#NoPayJan Offer - Access all CloudxLab Courses for free between 1st to 31st Jan

  Enroll Now >>

Predicting the Class using Pre-Trained model

Now that we have loaded the image and the pre-trained network, we shall preprocess the image, feed it to the neural network to predict the class of the image.


  • image.img_to_array : Converts a PIL Image instance to a Numpy array.

  • tensorflow.keras.applications.inception_v3.preprocess_input : The images are converted from RGB to BGR, then each color channel is zero-centered with respect to the ImageNet dataset, without scaling.

  • tensorflow.keras.applications.inception_v3.decode_predictions : Decodes the prediction into a list of tuples (class, description, probability)

  • Converts the PIL image img to np array x using image.img_to_array function.

    x = << your code comes here >>(img)
  • The model expects to be fed with an array of images. So write as follows:

    x= np.array([x])
  • Preprocess the x using preprocess_input.

    x =  << your code comes here >>(x)
  • Predict the class probabilities of the input image x using model.predict.

    preds = << your code comes here>>(x)
  • Decode the predictions and print the top 3 prediction probabilities as follow:

    print('Predicted:', decode_predictions(preds, top=3)[0])

No hints are availble for this assesment

Answer is not availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...