Numpy Keras阵列输入错误
我得到以下错误:Numpy Keras阵列输入错误,numpy,machine-learning,tensorflow,deep-learning,keras,Numpy,Machine Learning,Tensorflow,Deep Learning,Keras,我得到以下错误: ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 6 arrays but instead got the following list of 3 arrays: [array([[ 0, 0, 0, ..., 1
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 6 arrays but instead got the following list of 3 arrays: [array([[ 0, 0, 0, ..., 18, 12, 1],
[ 0, 0, 0, ..., 18, 11, 1],
[ 0, 0, 0, ..., 18, 9, 1],
...,
[ 0, 0, 0, ..., 18, 15, 1],
[ 0, 0, 0, ..., 18, 9, ...
在我的keras模型中
我认为模型有误
当我将输入输入输入到模型时,就会发生这种情况。同样的输入在另一个程序中工作得非常好。如果没有更多信息,就不可能诊断出您的确切问题 我通常根据我的训练数据
X
指定第一层的input\u shape
参数
e、 g
我想你会希望X
看起来像这样:
[
[[ 0, 0, 0, ..., 18, 11, 1]],
[[ 0, 0, 0, ..., 18, 9, 1]],
....
]
因此,您可以尝试使用以下行重塑它:
X = np.array([[sample] for sample in X])
问题实际上来自于向网络提供错误的输入 在我的例子中,问题是我的自定义图像生成器将整个数据集作为输入传递,而不是某对图像标签。这是因为我认为Keras的generator.flow(x,y,批次大小)内部已经有一个产量结构,但是正确的generator结构应该如下所示(具有单独的产量):
我意识到这个问题很老,但可能会为查找问题节省一些时间。再次,获取相同的错误值错误:检查模型输入时出错:传递给模型的Numpy数组列表的大小不是模型预期的大小。期望看到6个数组,但得到了以下3个数组的列表:[array([[[0,0,0,…,18,12,1]],[[0,0,0,…,18,11,1]],[[0,0,0,0,…,18,18,9,1]],…,[[0,0,…,18,15,1]][[0,0,0,…。从错误代码中可以看出,您试图输入一个包含三个数组的列表。您需要确保您的训练数据与上面显示的X类似。我的训练方式与keras的官方示例代码相同。我的输入数据的形状为(10000,68)。我看不出需要6个数组的位置和方式。没有任何层具有将6个数组作为输入的形状。你是如何提出建议的?我不会调试你链接到的300行代码。如果你想要更多的反馈,你必须找到相关的代码以包含在你的问题中。不,我不是要求调试。我只是问你是如何猜到的初始修复?需要6个阵列,3个阵列…在每个示例的修复中都有一个新阵列…我想理解它将有助于我进行调试。谢谢。
X = np.array([[sample] for sample in X])
def generator(batch_size):
(images, labels) = utils.get_data(1000) # gets 1000 samples from dataset
labels = to_categorical(labels, 2)
generator = ImageDataGenerator(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90.,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
generator.fit(images)
gen = generator.flow(images, labels, batch_size=32)
while 1:
x_batch, y_batch = gen.next()
yield ([x_batch, y_batch])