#
Wolfram Neural Net Repository

Immediate Computable Access to Neural Net Models

Identify the main object in an image

This model introduces the Dense Convolutional Network (DenseNet) paradigm, connecting each layer to every other layer in a feed-forward fashion. For each layer, the feature maps of all preceding layers are used as inputs and its own feature maps are used as inputs into all subsequent layers. Rather then using explicit dense connections, this implementation achieves the same result by ordinary skip connections and concatenations.

Number of layers: 427 | Parameter count: 8,062,504 | Trained size: 34 MB |

- ImageNet Large Scale Visual Recognition Challenge 2012 classification dataset, consisting of 1.2 million training images, with 1,000 classes of objects.

This model achieves a top-1 accuracy of 75% on the original ImageNet validation set.

Get the pre-trained net:

In[1]:= |

Out[1]= |

Classify an image:

In[2]:= |

Out[2]= |

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

In[3]:= |

Out[3]= |

Get a list of available properties of the predicted Entity:

In[4]:= |

Out[4]= |

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

In[5]:= |

Out[5]= |

An object outside the list of the ImageNet classes will be misidentified:

In[6]:= |

Out[6]= |

Obtain the list of names of all available classes:

In[7]:= |

Out[7]= |

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

In[8]:= |

Out[8]= |

Get a set of images:

In[9]:= |

Visualize the features of a set of images:

In[10]:= |

Out[10]= |

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

In[11]:= |

Show the dimensions of the weights:

In[12]:= |

Out[12]= |

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

In[13]:= |

Out[13]= |

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:

In[14]:= |

In[15]:= |

Remove the last two layers from the pre-trained net:

In[16]:= |

Out[16]= |

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

In[17]:= |

Out[17]= |

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

In[18]:= |

Out[18]= |

Accuracy obtained on the test set:

In[19]:= |

Out[19]= |

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

In[20]:= |

Out[20]= |

Obtain the total number of parameters:

In[21]:= |

Out[21]= |

Obtain the layer type counts:

In[22]:= |

Out[22]= |

Display the summary graphic:

In[23]:= |

Out[23]= |

Export the net to the ONNX format:

In[24]:= |

Out[24]= |

Get the size of the ONNX file:

In[25]:= |

Out[25]= |

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

In[26]:= |

Out[26]= |

Check some metadata of the ONNX model:

In[27]:= |

Out[27]= |

Import the model back into the Wolfram Language. However, the NetEncoder and NetDecoder will be absent because they are not supported by ONNX:

In[28]:= |

Out[28]= |

- G. Huang, Z. Liu, L. Van der Maaten, K. Q. Weinberger, "Densely Connected Convolutional Networks," arXiv:1608.06993v5 (2018)
- (available from https://github.com/onnx/models/tree/master/vision/classification/densenet-121)
- Rights: MIT License