Using a pretrained model to identify an image

Before we proceed, let's load three packages that we'll need in this section:

# Libraries used
library(keras)
library(EBImage)
library(tensorflow)

The Keras and TensorFlow libraries will be used for developing the pretrained image classification model, while the EBImage library will be used for processing and visualizing image data.

In Keras, the following pretrained image classification models are available:

  • Xception    
  • VGG16    
  • VGG19    
  • ResNet50    
  • InceptionV3    
  • InceptionResNetV2    
  • MobileNet    
  • MobileNetV2    
  • DenseNet    
  • NASNet

These pretrained models are trained on images from ImageNet (http://www.image-net.org/). ImageNet is a huge image database that contains several million images.

We will start by using a pretrained model known as resnet50 to identify an image. The following is the code we can use to utilize this pretrained model:

# Pretrained model
pretrained <- application_resnet50(weights = "imagenet")
summary(pretrained)

Here, we have specified weights as "imagenet". This allows us to reuse the pretrained weights of the RESNET50 network. RESNET50 is a deep residual network that has a depth of 50 layers and includes convolutional neural network layers. Note that in case we only want to use the model architecture without the pretrained weights and we would like to train from scratch, then we can specify weights as null. By using summary, we can obtain the architecture of the RESNET50 network. However, to conserve space, we do not provide any output from the summary. The total number of parameters in this network is 25,636,712. The RESNET50 network is trained in using over a million images from ImageNet and has the capability to classify images into 1,000 different categories.

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

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