Top five categories

Now, we can use the pretrained model to make predictions by providing preprocessed image data as input. The code to achieve this is as follows:

# Predictions for top 5 categories
preds <- pretrained %>% predict(x)
imagenet_decode_predictions(preds, top = 5)[[1]]
Output
class_name class_description score
1 n02094258 Norwich_terrier 0.769952953
2 n02094114 Norfolk_terrier 0.126662806
3 n02096294 Australian_terrier 0.046003290
4 n02096177 cairn 0.040896162
5 n02093991 Irish_terrier 0.005021056

In the preceding code, we can observe the following:

  • The predictions are made using the predict function and contain probabilities for 1,000 different categories, out of which the top five categories with the highest probabilities are obtained using the imagenet_decode_predictions() function.
  • The highest score of about 0.7699 correctly identifies that the picture is of a Norwich terrier dog.
  • The second highest score is for the Norfolk terrier dog, which looks very similar to the Norwich terrier dog.
  • The predictions also suggest that the picture could be of another type of terrier dog; however, those probabilities are relatively small or negligible.

In the next section, we will look at a larger image dataset instead of a single image and use a pretrained network to develop an image classification model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset