Exercise

Preparing your input image

The original ResNet50 model was trained with images of size 224 x 224 pixels and a number of preprocessing operations; like the subtraction of the mean pixel value in the training set for all training images. You need to pre-process the images you want to predict on in the same way.

When predicting on a single image you need it to fit the model's input shape, which in this case looks like this: (batch-size, width, height, channels),np.expand_dims with parameter axis = 0 adds the batch-size dimension, representing that a single image will be passed to predict. This batch-size dimension value is 1, since we are only predicting on one image.

You will go over these preprocessing steps as you prepare this dog's (named Ivy) image into one that can be classified by ResNet50.

Instructions

100 XP
  • Import image from tensorflow.keras.preprocessing and preprocess_input from tensorflow.keras.applications.resnet50.
  • Load the image with the right target_size for your model.
  • Turn it into an array with image.img_to_array().
  • Pre-process img_expanded the same way the original ResNet50 training images were processed with preprocess_input().