#
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 pre-trained net:

In[1]:= |

Out[1]= |

Apply the trained net to a set of inputs:

In[2]:= |

Out[2]= |

Give class probabilities for a single input:

In[3]:= |

Out[3]= |

Create a subset of the MNIST dataset:

In[4]:= |

Out[4]= |

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

In[5]:= |

Out[5]= |

Visualize the features of a subset of the MNIST dataset:

In[6]:= |

Out[6]= |

Extract the image reconstruction part:

In[7]:= |

Out[7]= |

Extract the DigitCaps feature vector for a given digit image:

In[8]:= |

Out[8]= |

Reconstruct the image from the feature vector:

In[9]:= |

Out[9]= |

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

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

Retrieve the uninitialized training architecture:

In[13]:= |

Out[13]= |

Retrieve the MNIST dataset:

In[14]:= |

Out[14]= |

Use the training dataset provided:

In[15]:= |

Out[15]= |

Use the test dataset provided:

In[16]:= |

Out[16]= |

Initialize the “W” matrices properly:

In[17]:= |

Out[17]= |

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

In[18]:= |

Out[18]= |

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

In[19]:= |

Out[19]= |

Obtain the total number of parameters:

In[20]:= |

Out[20]= |

Obtain the layer type counts:

In[21]:= |

Out[21]= |

Display the summary graphic:

In[22]:= |

Out[22]= |

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

In[23]:= |

Out[23]= |

Export also creates a net.params file containing parameters:

In[24]:= |

Out[24]= |

Get the size of the parameter file:

In[25]:= |

Out[25]= |

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

In[26]:= |

Out[26]= |

Represent the MXNet net as a graph:

In[27]:= |

Out[27]= |

Wolfram Language 11.3 (March 2018) or above

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