I am using image data generator for binary classification. I have built my model and now I want to display images incorrectly classified by my mode.
My code is as follows. I am trying to build an images and labels which are incorrectly classified and then display the images out of 100 from my test generator.
images = []
labels = []
for i in range(100):
img, label = next(val_generator)
img = img_to_array(img[i])
img = np.expand_dims(img, axis=0)
result = model.predict_classes(img)
if result != label[i]:
images.append(img)
labels.append(label)
I want to display images[]. The code:
images[0]
images[0].reshape(-1)
img0 = array_to_img(images[0])
plt.plot(images[0])
I get the error:
Traceback (most recent call last):
File "<ipython-input-723-c79b5280f8fc>", line 1, in <module>
img0 = array_to_img(images[0])
File "/home/idu/.local/lib/python3.6/site-packages/keras/preprocessing/image.py", line 184, in array_to_img
return image.array_to_img(x, data_format=data_format, scale=scale, **kwargs)
I think it is about reshaping my images from arrays. How can I display the images wrongly classified? Thank you!
File "/home/idu/.local/lib/python3.6/site-packages/keras_preprocessing/image/utils.py", line 257, in array_to_img
'Got array with shape: %s' % (x.shape,))
ValueError: Expected image array to have rank 3 (single image). Got array with shape: (1, 512, 512, 1)