简体   繁体   English

ValueError:检查输入时出错:预期dense_1_input具有形状(180,)但得到形状为(1,)的数组

[英]ValueError: Error when checking input: expected dense_1_input to have shape (180,) but got array with shape (1,)

My learning model is as follows (using Keras).我的学习模型如下(使用 Keras)。

model = Sequential()
model.add(Dense(100, activation='relu', input_shape = (X_train.shape[0],)))
model.add(Dense(500, activation='relu'))
model.add(Dense(2, activation='softmax'))

My input data X_train is an array of shape (180,) and the corresponding y_train containing labels is also an array of shape (180,).我的输入数据 X_train 是一个形状数组 (180,),相应的包含标签的 y_train 也是一个形状数组 (180,)。 I tried to compile and fit the model as follows.我尝试编译和拟合模型如下。

model.compile(loss="sparse_categorical_crossentropy",
             optimizer="adam",
             metrics=['accuracy'])

model.fit(X_train, y_train, epochs = 200)

When I run the model.fit(), I encountered the following error:当我运行model.fit()时,我遇到了以下错误:

ValueError: Error when checking input: expected dense_1_input to have
shape (180,) but got array with shape (1,)

I'm not sure what I'm doing wrong since I'm pretty new to deep learning.我不确定自己做错了什么,因为我对深度学习还很陌生。 Any help is appreciated.任何帮助表示赞赏。 Thanks.谢谢。

In your case, the input_shape defined in the first layer, should be (1,) :在您的情况下,第一层中定义的 input_shape 应该是(1,)

X_train.shape[0] is the number of samples, each sample has for shape (1,) . X_train.shape[0]是样本数,每个样本具有形状(1,)

Moreover, your call to the fit function won't work as your output has for shape (2,) ( Dense(2) ) whereas the shape of each target sample is (1,) (you have 180 of those).此外,您对 fit 函数的调用将不起作用,因为您的输出具有形状(2,) ( Dense(2) ) 而每个目标样本的形状是(1,) (您有 180 个)。

As @Thomas Schillaci wrote, the problem is that if you write X_train.shape[0] you are taking into account the number of samples of your dataset.正如@Thomas Schillaci 所写,问题在于,如果您编写X_train.shape[0]您将考虑数据集的样本数量。 But in that line the code want to know how many features you have, so you have to change in X_train.shape[1] in order to have the n° of input.但是在那一行代码想知道你有多少特征,所以你必须改变X_train.shape[1]以获得输入的 n°。 How many labels do you have?你有多少标签?

暂无
暂无

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

相关问题 ValueError:检查输入时出错:预期density_1_input的形状为(24,),但数组的形状为(1,) - ValueError: Error when checking input: expected dense_1_input to have shape (24,) but got array with shape (1,) ValueError:检查输入时出错:预期dense_1_input 具有形状(9,) 但得到形状为(1,) 的数组 - ValueError: Error when checking input: expected dense_1_input to have shape (9,) but got array with shape (1,) ValueError:检查输入时出错:预期dense_1_input 具有形状(8,) 但得到形状为(1,) 的数组 - ValueError: Error when checking input: expected dense_1_input to have shape (8,) but got array with shape (1,) ValueError:检查输入时出错:预期dense_1_input的形状为(1,)但得到的数组形状为(5000,) - ValueError: Error when checking input: expected dense_1_input to have shape (1,) but got array with shape (5000,) ValueError:检查时出错:预期dense_1_input具有形状(3,)但得到形状为(1,)的数组 - ValueError: Error when checking : expected dense_1_input to have shape (3,) but got array with shape (1,) ValueError:检查时出错:预期density_1_input具有2维,但数组的形状为(1,16,16,512) - ValueError: Error when checking : expected dense_1_input to have 2 dimensions, but got array with shape (1, 16, 16, 512) 如何修复'ValueError:检查输入时出错:期望dense_1_input有形状(4,)但是在Python中有错误的形状(1,)数组? - How to fix ‘ValueError: Error when checking input: expected dense_1_input to have shape (4,) but got array with shape (1,)’ error in Python? ValueError:检查输入时出错:预期density_1_input具有形状(1,224,224),但数组形状为(224,224,1) - ValueError: Error when checking input: expected dense_1_input to have shape (1, 224, 224) but got array with shape (224, 224, 1) 检查输入时出错:预期density_1_input具有形状(3773),但数组的形状为(111,) - Error when checking input: expected dense_1_input to have shape (3773,) but got array with shape (111,) 检查输入时出错:预期dense_1_input 具有形状(784,) 但得到形状为(10,) 的数组 - Error when checking input: expected dense_1_input to have shape (784,) but got array with shape (10,)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM