简体   繁体   English

Keras模型:用于model.fit的同一数组未在model.predict中处理

[英]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.

相关问题 不同的model.fit输出(加载模型无训练后)和keras中的model.predict - different output of model.fit (after loading model no training) and model.predict in keras model.predict 会导致 oom 问题,但 model.fit 不会: - model.predict leads to oom issues, but model.fit does not: model.predict()和model.fit()做什么? - What do model.predict() and model.fit() do? model.fit vs model.predict-sklearn中的差异和用法 - model.fit vs model.predict - differences & usage in sklearn 为什么 model.predict() 的精度比具有相同 x_train 的 model.fit() 更差? - Why model.predict() is getting worse accuracy than model.fit() with the same x_train? Keras-与model.predict()不匹配的数组形状 - Keras - mismatched array shape with model.predict() keras model.predict() 很慢 - keras model.predict() is slow model.predict 的 Tensorflow 精度与 model.fit 的最终时期 val_accuracy 不匹配 - Tensorflow accuracy from model.predict does not match final epoch val_accuracy of model.fit 成功训练 Model.fit 但在 collab 上运行 model.predict 时提示资源错误 - Successfully trained Model.fit but prompted resource error when running model.predict on collab 带有 Model.Fit() 的 Keras InvalidArgumentError - Keras InvalidArgumentError With Model.Fit()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM