Machine learning: Cats and Dog

my code: https://colab.research.google.com/drive/1gBwfuR-i81Oa2DxKJtfwQTwUyPHCkqua?usp=sharing

link to challenge: https://colab.research.google.com/drive/1UCHiRuBLxo0S3aMuiDXlaP54LsxzrXHz

In this section of the cats and dog challenge,

//---------------------------------------------------------------------------------------
Now it is time to use your model to predict whether a brand new image is a cat or a dog.

In this final cell, get the probability that each test image (from test_data_gen) is a dog or a cat. probabilities should be a list of integers.

Call the plotImages function and pass in the test images and the probabilities corresponding to each test image.

After your run the cell, you should see all 50 test images with a label showing the percentage sure that the image is a cat or a dog. The accuracy will correspond to the accuracy shown in the graph above (after running the previous cell). More training images could lead to a higher accuracy.
//-----------------------------------------------------------------------------------------

I am not able to plot the test images using plotImages function. I have tried alot of combinations to try and get it to work but have not been successful.

plotImages(test_data_gen,probabilities=prediction) is what i expect to be written but gets the error:
TypeError: Invalid shape (1, 150, 150, 3) for image data

However if i run the test block i do pass.

I just realised that my previous comment had a mistake in it. Here is the corrected version.
Images have a shape of (x, y, 3) so that’s why you are getting the error.
Each image is given by test_data_gen[0][0][image_index]
image
To display the 50 images with their corresponding classifications, you should try use

plotImages(test_data_gen[0][0], probabilities)

Hope this helps.

1 Like

I got it to work using:

plotImages([test_data_gen[i][0] for i in range(50)], probabilities=probabilities)

Thanks for your help

2 Likes