Resource retrieval
Get the pre-trained net:
Out[1]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-1-o.en.gif) |
NetModel parameters
This model consists of a family of individual nets, each identified by a specific parameter combination. Inspect the available parameters:
Out[2]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-2-o.en.gif) |
Pick a non-default net by specifying the parameters:
Out[3]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-3-o.en.gif) |
Pick a non-default uninitialized net:
Out[4]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-4-o.en.gif) |
Basic usage
Classify an image:
Out[5]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-5-o.en.gif) |
The prediction is an Entity object, which can be queried:
Out[6]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-6-o.en.gif) |
Get a list of available properties of the predicted Entity:
Out[7]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-7-o.en.gif) |
Obtain the probabilities of the ten most likely entities predicted by the net:
Out[8]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-8-o.en.gif) |
An object outside the list of the ImageNet classes will be misidentified:
Out[9]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-9-o.en.gif) |
Obtain the list of names of all available classes:
Out[10]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-10-o.en.gif) |
Feature extraction
Remove the last two layers of the trained net so that the net produces a vector representation of an image:
Out[11]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-11-o.en.gif) |
Get a set of images:
Visualize the features of a set of images:
Out[13]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-13-o.en.gif) |
Visualize convolutional weights
Extract the weights of the first convolutional layer in the trained net:
Show the dimensions of the weights:
Out[15]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-15-o.en.gif) |
Visualize the weights as a list of 64 images of size 3x3:
Out[16]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-16-o.en.gif) |
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:
Remove the linear layer from the pre-trained net:
Out[19]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-19-o.en.gif) |
Create a new net composed of the pre-trained net followed by a linear layer and a softmax layer:
Out[20]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-20-o.en.gif) |
Train on the dataset, freezing all the weights except for those in the "linearNew" layer (use TargetDevice -> "GPU" for training on a GPU):
Out[21]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-21-o.en.gif) |
Perfect accuracy is obtained on the test set:
Out[22]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-22-o.en.gif) |
Net information
Inspect the number of parameters of all arrays in the net:
Out[23]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-23-o.en.gif) |
Obtain the total number of parameters:
Out[24]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-24-o.en.gif) |
Obtain the layer type counts:
Out[25]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-25-o.en.gif) |
Export to MXNet
Export the net into a format that can be opened in MXNet:
Out[26]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-26-o.en.gif) |
Export also creates a net.params file containing parameters:
Out[27]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-27-o.en.gif) |
Get the size of the parameter file:
Out[28]= | ![](images/57a/57aad159-9319-4ff9-afab-95a2acb272bf-io-28-o.en.gif) |