[英]different output of model.fit (after loading model no training) and model.predict in keras
[英]Keras Model: Same array that is used for model.fit is not being processed in model.predict
我有一个模型:
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'])
在Model.evaluvate期间,它可以与'X'的输入配合使用:
history = model.fit(X, Y, validation_split=0.2, epochs=10, callbacks= [PrintDot()], batch_size=10, verbose=0)
但是在我使用X [1]进行预测的过程中,会引发错误:
ValueError: Error when checking input: expected dense_8_input to have shape (500,) but got array with shape (1,)
但是X [1] .Shape是(500,):
X[1].shape
--> (500,)
如果有任何帮助,我该如何纠正此错误
model.predict
希望接收(amount_of_items, features)
输入。
因此,即使尝试预测单个样本,也必须将其重塑为(1, features)
,对于您的情况,则重塑为(1, features)
(1, 500)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.