简体   繁体   English

无法将 NumPy 数组转换为张量(不支持的 object 类型 numpy.ndarray)错误

[英]Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) error

I try to train a tensorflow model.我尝试训练 tensorflow model。 But I got error.但我得到了错误。

Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).

Here my fit codes:这是我的适合代码:

model.fit(self.datas.trainImages, self.datas.trainLabels,self.datas.batch_size, epochs =self.datas.epochs)

My self.datas.trainImages is numpy.array() its shape is (16,) it has 16 sample and their sizes is 28x28, it is mnist dataset.我的 self.datas.trainImages 是 numpy.array() 它的形状是 (16,) 它有 16 个样本,它们的大小是 28x28,它是 mnist 数据集。

self.train_dataset = [[cv2.imread(image0),0],[cv2.imread(image1),1],[cv2.imread(image2),2],[...],[...]]
self.trainDataset = numpy.array(self.train_dataset)
        
self.trainImages, self.trainLabels = numpy.asarray(self.trainDataset[:,0])/255,self.trainDataset[:,1] #.astype(numpy.float32)/



self.val_dataset = [[cv2.imread(image0),0],[cv2.imread(image1),1],[cv2.imread(image2),2],[...],[...]]

self.valDataset = numpy.array(self.val_dataset)#.astype(numpy.float32)
self.valImages, self.valLabels = numpy.asarray(self.valDataset[:,0])/255,self.valDataset[:,1] #.astype(numpy.float32)/255
        

I tried to use astype or numpy.ndarray but I got another errors.我尝试使用 astype 或 numpy.ndarray 但我遇到了另一个错误。 I am sure of that all datas in the self.datas.trainImages is float numbers and has same shape.我确信 self.datas.trainImages 中的所有数据都是浮点数并且具有相同的形状。

Would it be possible to print out some type of error output?是否可以打印出某种类型的错误 output?

Personally, I was having a similar issue and by coating my input with "np.stack()" it added an extra dimension, changed the shape of the array and allowed it to work.就我个人而言,我遇到了类似的问题,通过用“np.stack()”覆盖我的输入,它添加了一个额外的维度,改变了数组的形状并允许它工作。

ie IE

images = np.stack(self.data.trainImages)

Furthermore, I'm not sure if you're using a custom Model.fit() method, but I believe for multiple inputs it's best to use square brackets, ie此外,我不确定您是否使用自定义 Model.fit() 方法,但我相信对于多个输入,最好使用方括号,即

model.fit(x = [input1, input2], y = output1, batch_size = batch_sizing, epochs = epoch_quantity)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不断收到此错误:无法将 NumPy 数组转换为张量(不支持的 object 类型 numpy.ndarray) - I keep getting this error: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) 错误:无法将 NumPy 数组转换为张量(不支持 object 类型 numpy.ndarray) - Error: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) ValueError:无法将 NumPy 数组转换为数组大小超过 4000 的张量(不支持的对象类型 numpy.ndarray) - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) with array size exceeding 4000 ValueError:无法将 NumPy 数组转换为 CNN 分类上的张量(不支持的 object 类型 numpy.ndarray) - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) on CNN classifiction ValueError:无法使用 tensorflow CNN 将 NumPy 数组转换为张量(不支持 object 类型 numpy.ndarray) - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) with tensorflow CNN ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) in Tensorflow - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) in Tensorflow "ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray). In TensorFlow CNN for image classification - "ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray). In TensorFlow CNN for image classification ValueError:无法将 NumPy 数组转换为张量(不支持的 object 类型 numpy.ndarray)。在 jupyternotebook - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).in jupyternotebook ValueError:无法将 NumPy 数组转换为张量(不支持的 object 类型 numpy.ndarray)。 试图预测特斯拉股票 - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray). in trying to predict tesla stock 尝试执行 model.fit() 时出现 ValueError -:无法将 NumPy 数组转换为张量(不支持的对象类型 numpy.ndarray) - ValueError when trying to execute model.fit() -: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM