[英]Keras Model: Same array that is used for model.fit is not being processed in model.predict
I have a model: 我有一个模型:
model.add(Dense(16, input_dim = X.shape[1], activation = 'tanh'))
model.add(Dropout(0.2))
model.add(Dense(8, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(4, activation = 'tanh'))
model.add(Dropout(0.2))
model.add(Dense(2, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mae'])
And during Model.evaluvate it works just fine with 'X' s input: 在Model.evaluvate期间,它可以与'X'的输入配合使用:
history = model.fit(X, Y, validation_split=0.2, epochs=10, callbacks= [PrintDot()], batch_size=10, verbose=0)
But during prediction as I use X[1] it throws an error: 但是在我使用X [1]进行预测的过程中,会引发错误:
ValueError: Error when checking input: expected dense_8_input to have shape (500,) but got array with shape (1,)
But X[1].Shape is (500,): 但是X [1] .Shape是(500,):
X[1].shape
--> (500,)
How can I mend this error, any help appreciated 如果有任何帮助,我该如何纠正此错误
Keras model.predict
expects to receive input of (amount_of_items, features)
. model.predict
希望接收(amount_of_items, features)
输入。
So even when attempting to predict a single sample, you must reshape it to (1, features)
, and in your case, (1, 500)
. 因此,即使尝试预测单个样本,也必须将其重塑为
(1, features)
,对于您的情况,则重塑为(1, features)
(1, 500)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.