我正在训练模型,将模型保存在磁盘上,使用模型时出错。
Error when checking input: expected conv2d_input to have 4 dimensions, but got array with shape (150, 150, 3)
火车模型:
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3))
使用模型:
model = load_model(os.path.join('models', 'myModel.h5'))
model.predict(img) # img - OpenCV image
答案 0 :(得分:0)
使用此:
import numpy as np
model.predict(img[np.newaxis, :, :, :])