Wolfram ImageIdentify Net V1

Identify the main object in an image

This model is also available through the built-in functions Classify and Predict

Released in 2017 by Wolfram Research, this net was trained on over 4,000 classes of objects. It is part of the back end for the ImageIdentify function in Wolfram Language 11.1. It was designed to achieve a good balance among classification accuracy, size and evaluation speed.

Number of layers: 232 | Parameter count: 14,713,147 | Trained size: 65 MB |

Training Set Information

Examples

Resource retrieval

Get the pre-trained net:

In[1]:=
NetModel["Wolfram ImageIdentify Net V1"]
Out[1]=

Basic usage

Classify an image:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/212ab05b-8f82-44bd-b276-143f90a58832"]
Out[2]=

The prediction is an Entity object, which can be queried:

In[3]:=
pred["Definition"]
Out[3]=

Get a list of available properties of the predicted Entity:

In[4]:=
pred["Properties"]
Out[4]=

Obtain the probabilities of the ten most likely entities predicted by the net:

In[5]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/186927b9-d01b-4b7a-b863-af903711c224"]
Out[5]=

An object outside the list of the ImageIdentify dataset will be misidentified:

In[6]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0b1f4657-acb0-40a0-a851-b35cd7a29b7b"]
Out[6]=

Obtain the list of names of all available classes:

In[7]:=
EntityValue[
 NetExtract[NetModel["Wolfram ImageIdentify Net V1"], "Output"][[
  "Labels"]], "Name"]
Out[7]=

Feature extraction

Remove the last two layers of the trained net so that the net produces a vector representation of an image:

In[8]:=
extractor = Take[NetModel["Wolfram ImageIdentify Net V1"], {1, -3}]
Out[8]=

Get a set of images:

In[9]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/620d57cb-98d5-4bac-a888-cc28a3381178"]

Visualize the features of a set of images:

In[10]:=
FeatureSpacePlot[imgs, FeatureExtractor -> extractor, LabelingSize -> 100, ImageSize -> 800]
Out[10]=

Visualize convolutional weights

Extract the weights of the first convolutional layer in the trained net:

In[11]:=
weights = NetExtract[
   NetModel["Wolfram ImageIdentify Net V1"], {"conv_1", "Weights"}];

Visualize the weights as a list of 64 images of size 7x7:

In[12]:=
ImageAdjust[Image[#, Interleaving -> False]] & /@ Normal[weights]
Out[12]=

Transfer learning

Use the pre-trained model to build a classifier for telling apart images of dogs and cats. Create a test set and a training set:

In[13]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/09b85c63-f5ba-4bb8-9894-f691d4d3682f"]
In[14]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/5fa6a079-daa0-49c4-a796-4ae221896e55"]

Remove the linear layer from the pre-trained net:

In[15]:=
tempNet = Take[NetModel["Wolfram ImageIdentify Net V1"], {1, -3}]
Out[15]=

Create a new net composed of the pre-trained net followed by a linear layer and a softmax layer:

In[16]:=
newNet = NetChain[<|"pretrainedNet" -> tempNet, "linearNew" -> LinearLayer[], "softmax" -> SoftmaxLayer[]|>, "Output" -> NetDecoder[{"Class", {"cat", "dog"}}]]
Out[16]=

Train on the dataset, freezing all the weights except for those in the "linearNew" layer (use TargetDevice -> "GPU" for training on a GPU):

In[17]:=
trainedNet = NetTrain[newNet, trainSet, LearningRateMultipliers -> {"linearNew" -> 1, _ -> 0}]
Out[17]=

Perfect accuracy is obtained on the test set:

In[18]:=
ClassifierMeasurements[trainedNet, testSet, "Accuracy"]
Out[18]=

Net information

Inspect the number of parameters of all arrays in the net:

In[19]:=
NetInformation[
 NetModel["Wolfram ImageIdentify Net V1"], "ArraysElementCounts"]
Out[19]=

Obtain the total number of parameters:

In[20]:=
NetInformation[
 NetModel["Wolfram ImageIdentify Net V1"], "ArraysTotalElementCount"]
Out[20]=

Obtain the layer type counts:

In[21]:=
NetInformation[
 NetModel["Wolfram ImageIdentify Net V1"], "LayerTypeCounts"]
Out[21]=

Display the summary graphic:

In[22]:=
NetInformation[
 NetModel["Wolfram ImageIdentify Net V1"], "SummaryGraphic"]
Out[22]=

Export to MXNet

Export the net into a format that can be opened in MXNet :

In[23]:=
jsonPath = Export[FileNameJoin[{$TemporaryDirectory, "net.json"}], NetModel["Wolfram ImageIdentify Net V1"], "MXNet"]
Out[23]=

Export also creates a net.params file containing parameters:

In[24]:=
paramPath = FileNameJoin[{DirectoryName[jsonPath], "net.params"}]
Out[24]=

Get the size of the parameter file:

In[25]:=
FileByteCount[paramPath]
Out[25]=

The size is similar to the byte count of the resource object:

In[26]:=
ResourceObject["Wolfram ImageIdentify Net V1"]["ByteCount"]
Out[26]=

Requirements

Wolfram Language 11.1 (March 2017) or above

Resource History

Reference