python - Keras/Tensorflow predict: error in array shape -


i'm following keras cifar10 tutorial here. changes made were:

[a] added end of tutorial file

model.save_weights('./weights.h5', overwrite=true) 

[b] changed ~./keras/keras.json to

{"floatx": "float32", "backend": "tensorflow", "epsilon": 1e-07} 

i can run model successfully.

then want test single image against trained model. code:

[... similar tutorial file model being created , compiled...] ... model = sequential() ... model.compile()  model.load_weights('./ddx_weights.h5')  img = cv2.imread('car.jpeg', -1) # is 32x32 rgb image img = np.array(img) y_pred = model.predict_classes(img, 1) print(y_pred) 

i error:

valueerror: cannot feed value of shape (1, 32, 3) tensor 'convolution2d_input_1:0', has shape '(?, 3, 32, 32)' 

what correct way of reshaping input data single image tested?

i have not added "image_dim_ordering": "tf" in ./keras/keras.json.

you have reshape input image have shape of [?, 3, 32, 32] ? batch size. in case, since have 1 image batch size 1, can do:

img = np.array(img) img = img.reshape((1, 3, 32, 32))