Keras错误:预计将看到1个数组 [英] Keras error : Expected to see 1 array
问题描述
当我尝试在keras中训练MLP模型时出现以下错误(我正在使用keras版本1.2.2
)
I got the following error when I tried to train an MLP model in keras(I am using keras version 1.2.2
)
检查模型输入时出错:您所输入的Numpy数组的列表 传递给您的模型的尺寸不是模型期望的尺寸.预期的 查看1个数组,但得到以下12859个数组的列表:
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 1 arrays but instead got the following list of 12859 arrays:
这是模型的摘要
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
dense_1 (Dense) (None, 20) 4020 dense_input_1[0][0]
____________________________________________________________________________________________________
dense_2 (Dense) (None, 2) 42 dense_1[0][0]
====================================================================================================
Total params: 4,062
Trainable params: 4,062
Non-trainable params: 0
____________________________________________________________________________________________________
None
这是模型的第一行
model.add(Dense(20, input_shape=(200,), init='lecun_uniform', activation='tanh'))
培训:
model.fit(X,Y,nb_epoch=100,verbose=1)
其中X是元素列表,每个元素又是200个值的列表.
where X is a list of elements and each element in turn is a list of 200 values.
我也尝试过
model.add(Dense(20, input_shape=(12859,200), init='lecun_uniform', activation='tanh'))
但是我遇到了同样的错误
but I am getting the same error
推荐答案
您的错误来自以下事实:您的X
由于某种原因未转换为numpy.array
.在这种情况下,您的X
被视为行列表,这是您的错误消息背后的原因(它期望一个输入而不是具有多个行元素的list).转变:
Your error comes from the fact that your X
for some reason wasn't transformed to a numpy.array
. In this your X
is treated as a list of rows and this is a reason behind your error message (that it expected one input instead of list which has a number of rows elements). Transformation:
X = numpy.array(X)
Y = numpy.array(Y)
我会检查数据加载过程,因为那里可能出了些问题.
I would check a data loading process because something might go wrong there.
更新:
正如评论中提到的-input_shape
需要更改为input_dim
.
As it was mentioned in a comment - input_shape
need to be changed to input_dim
.
更新2:
为了保留input_shape
,应将其更改为input_shape=(200,)
.
In order to keep input_shape
one should change to it to input_shape=(200,)
.
这篇关于Keras错误:预计将看到1个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!