O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. First, load the libraries and download the pretrained Inception model, then extract it:
> library(mxnet) 
> library(EBImage) 
> library(jpeg) 
> library(png) 
 
> if (!file.exists("synset.txt")) {download.file("http://data.dmlc.ml/mxnet/models/imagenet/inception-bn.tar.gz", destfile = "inception-bn.tar.gz") 
  untar("inception-bn.tar.gz") 
} 
  1. Use the model loading function to load the unzipped pretrained model into R:
> model <<- mx.model.load("./Inception-BN", iteration = 126) 
> synsets <<- readLines("synset.txt") 
  1. Load the image of an elephant using the readImage function of the EBImage package (you can use another image if you want):
> image <- readImage("elephant.jpg") 
  1. Preprocess the image (resizing and subtracting the mean) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required