我正在按照Keras CIFAR10教程进行操作。
我所做的唯一更改是:
在教程文件末尾添加了[a]。
model.save_weights('./weights.h5', overwrite=True)
修改了~./keras/keras.json
{"floatx": "float32", "backend": "tensorflow", "epsilon": 1e-07}
我可以成功运行这个模型。
然后我想对训练好的模型测试一张单独的图片。我的代码:
[... similar to tutorial file with model being created and compiled...]
...
model = Sequential()
...
model.compile()
model.load_weights('./ddx_weights.h5')
img = cv2.imread('car.jpeg', -1) # this is is a 32x32 RGB image
img = np.array(img)
y_pred = model.predict_classes(img, 1)
print(y_pred)
我遇到了这个错误:
ValueError: Cannot feed value of shape (1, 32, 3) for Tensor 'convolution2d_input_1:0', which has shape '(?, 3, 32, 32)'
如何正确地调整输入数据的形状,以便测试单个图像?
我在./keras/keras.json
中未添加"image_dim_ordering": "tf"
。