简体   繁体   中英

Error while predicting classes of an trained DNN model

I used the following program to predict classes for my image.

 from tensorflow.keras.preprocessing.image import load_img, img_to_array x = load_img("8-SignLanguageMNIST/test1.jpg", target_size = (28, 28)) x = img_to_array(x) x = np.expand_dims(x, axis = 0) x = np.vstack([x]) classes = model.predict(x) print(classes[0])

The Images I used for training are of shape (28, 28, 1).

Here I am uploading an RGB image which is of shape (28, 28, 3), I tried converting that image to grayscale and then predicting but kept getting the following error.

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 1 but received input with shape [None, 28, 28, 3]

Can anyone tell me what I am doing wrong, and help me out with that.

you need to apply a conversion to grayscale like below:

load_img(path, color_mode='grayscale')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM