#
Wolfram Neural Net Repository

Immediate Computable Access to Neural Net Models

Identify the handwritten digit in an image

Released in 2017, this model makes use of capsules as the fundamental building blocks to replace neurons in artificial neural networks. As opposed to scalar neurons, whose activation reacts to the presence of a particular feature or object, a capsule is a group of neurons all reacting to the same entity, whose vectorial activation can also encode the properties of the detected instance. In addition, features are passed from one capsule layer to another using a novel dynamic routing technique.

Number of layers: 52 | Parameter count: 8,141,840 | Trained size: 33 MB

- MNIST Database of Handwritten Digits, consisting of 60,000 training and 10,000 test grayscale images of size 28x28.

- This model achieves 99.5% accuracy on the MNIST dataset.

Retrieve the resource object:

In[1]:= |

Out[1]= |

Retrieve the pre-trained net:

In[2]:= |

Out[2]= |

Apply the trained net to a set of inputs:

In[3]:= |

Out[3]= |

Give class probabilities for a single input:

In[4]:= |

Out[4]= |

Create a subset of the MNIST dataset:

In[5]:= |

Out[5]= |

Remove the last linear layer of the net, which will be used as a feature extractor:

In[6]:= |

Out[6]= |

Visualize the features of a subset of the MNIST dataset:

In[7]:= |

Out[7]= |

Extract the image reconstruction part:

In[8]:= |

Out[8]= |

Extract the DigitCaps feature vector for a given digit image:

In[9]:= |

Out[9]= |

Reconstruct the image from the feature vector:

In[10]:= |

Out[10]= |

Experiment with changing the feature vector. Add a shift along a single coordinate at a time:

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

Retrieve the uninitialized training architecture:

In[14]:= |

Out[14]= |

Retrieve the MNIST dataset:

In[15]:= |

Out[15]= |

Use the training dataset provided:

In[16]:= |

Out[16]= |

Use the test dataset provided:

In[17]:= |

Out[17]= |

Initialize the “W” matrices properly:

In[18]:= |

Out[18]= |

Train the net (if a GPU is available, setting TargetDevice -> "GPU" is recommended):

In[19]:= |

Out[20]= |

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

In[21]:= |

Out[21]= |

Obtain the total number of parameters:

In[22]:= |

Out[22]= |

Obtain the layer type counts:

In[23]:= |

Out[23]= |

Display the summary graphic:

In[24]:= |

Out[24]= |

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

In[25]:= |

Out[25]= |

Export also creates a net.params file containing parameters:

In[26]:= |

Out[26]= |

Get the size of the parameter file:

In[27]:= |

Out[27]= |

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

In[28]:= |

Out[28]= |

Represent the MXNet net as a graph:

In[29]:= |

Out[29]= |

Wolfram Language 11.3 (March 2018) or above

- S. Sabour, N. Frosst, G. E. Hinton, "Dynamic Routing between Capsules," arXiv:1710.09829 (2017)