Resource retrieval
Get the pre-trained net:
Basic usage
Classify an image:
The prediction is an Entity object, which can be queried:
Get a list of available properties of the predicted Entity:
Obtain the probabilities of the 10 most likely entities predicted by the net:
An object outside the list of the ImageNet classes will be misidentified:
Obtain the list of names of all available classes:
Feature extraction
Remove the last layers of the trained net so that the net produces a vector representation of an image:
Get a set of images:
Visualize the features of a set of images:
Visualize convolutional weights
Extract the weights of the first convolutional layer in the trained net:
Show the dimensions of the weights:
Visualize the weights as a list of 24 images of size 3⨯3:
Transfer learning
Use the pre-trained model to build a classifier for telling apart images of sunflowers and roses. Create a test set and a training set:
Remove the last layers from the pre-trained net:
Create a new net composed of the pre-trained net followed by a linear layer and a softmax layer:
Train on the dataset, freezing all the weights except for those in the "linearNew" layer (use TargetDevice -> "GPU" for training on a GPU):
Accuracy obtained on the test set:
Net information
Inspect the number of parameters of all arrays in the net:
Obtain the total number of parameters:
Obtain the layer type counts:
Display the summary graphic:
Export to ONNX
Export the net to the ONNX format:
Get the size of the ONNX file:
The size is similar to the byte count of the resource object:
Check some metadata of the ONNX model:
Import the model back into the Wolfram Language. However, the NetEncoder and NetDecoder will be absent because they are not supported by ONNX: