I am doing image classification and I trained a model and saved a model. When I try to predict the model, it shows input error. I am building a classifier using ResNet Architecture and initially declared input_size as 224 x 224. Now I need to predict the class of the test image.
I converted the image into 224x224 numpy array. when I try the below code
#plot the figure
fig = plt.figure()
for num,data in enumerate(test_data):
img_num = data[1]
img_data = data[0]
y = fig.add_subplot(9,3,num+1)
orig = img_data
data = img_data.reshape(1,IMG_SIZ,IMG_SIZ,3)
#predict the model
model_out = model.predict_classes([orig])[0]
if np.argmax(model_out) == 1: str_label='Dog'
else: str_label='Cat'
y.imshow(orig,cmap = 'gray')
plt.title(str_label)
y.axes.get_xaxis().set_visible(False)
y.axes.get_yaxis().set_visible(False)
plt.show()
plt.savefig('test_labeled.jpg')
It shows me the following error
ValueError: cannot reshape array of size 50176 into shape (1,224,224,3)
in what size I have to reshape the correct dimension?
Thanks!
data[0]? Are you trying to resize an image by using.reshape()? - eugenhu[224, 224, 1]instead of[224, 224, 3], so reshape accordingly. - vijay m