All Projects → IBM → Matrix Capsules With Em Routing

IBM / Matrix Capsules With Em Routing

Licence: apache-2.0
A TensorFlow implementation of "Matrix Capsules with EM Routing" by Hinton et al. (2018).

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Matrix Capsules With Em Routing

Capsnet
A PyTorch implementation of CapsNet based on NIPS 2017 paper "Dynamic Routing Between Capsules"
Stars: ✭ 141 (+90.54%)
Mutual labels:  capsnet
tf CapsNet
A tensorflow implementation for CapsNet
Stars: ✭ 19 (-74.32%)
Mutual labels:  capsnet
Capsnet Visualization
🎆 A visualization of the CapsNet layers to better understand how it works
Stars: ✭ 371 (+401.35%)
Mutual labels:  capsnet
Capsnet Traffic Sign Classifier
A Tensorflow implementation of CapsNet(Capsules Net) apply on german traffic sign dataset
Stars: ✭ 166 (+124.32%)
Mutual labels:  capsnet
CapsNet
Empirical studies on Capsule Network representation and improvements implemented with PyTorch.
Stars: ✭ 39 (-47.3%)
Mutual labels:  capsnet
capsules-tensorflow
Another implementation of Hinton's capsule networks in tensorflow.
Stars: ✭ 18 (-75.68%)
Mutual labels:  capsnet
Capsnet guide pytorch
A tutorial-style implementation of CapsNet in PyTorch
Stars: ✭ 104 (+40.54%)
Mutual labels:  capsnet
Capsnet Pytorch
PyTorch implementation of NIPS 2017 paper Dynamic Routing Between Capsules
Stars: ✭ 440 (+494.59%)
Mutual labels:  capsnet
CapsNet-tensorflow-jupyter
A simple tensorflow implementation of CapsNet (by Dr. G. Hinton), based on my understanding. This repository is built with an aim to simplify the concept, implement and understand it.
Stars: ✭ 16 (-78.38%)
Mutual labels:  capsnet
Capslayer
CapsLayer: An advanced library for capsule theory
Stars: ✭ 351 (+374.32%)
Mutual labels:  capsnet
Dynamic routing between capsules
Implementation of Dynamic Routing Between Capsules, Sara Sabour, Nicholas Frosst, Geoffrey E Hinton, NIPS 2017
Stars: ✭ 202 (+172.97%)
Mutual labels:  capsnet
CapsNet-Fashion-MNIST
Capsule Network on Fashion MNIST dataset
Stars: ✭ 93 (+25.68%)
Mutual labels:  capsnet
CapsuleLayer
PyTorch Capsule Layer
Stars: ✭ 28 (-62.16%)
Mutual labels:  capsnet
Capsule Net Pytorch
[NO MAINTENANCE INTENDED] A PyTorch implementation of CapsNet architecture in the NIPS 2017 paper "Dynamic Routing Between Capsules".
Stars: ✭ 158 (+113.51%)
Mutual labels:  capsnet
Capsnet Tensorflow
A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules
Stars: ✭ 3,776 (+5002.7%)
Mutual labels:  capsnet
Capsule Gan
Code for my Master thesis on "Capsule Architecture as a Discriminator in Generative Adversarial Networks".
Stars: ✭ 120 (+62.16%)
Mutual labels:  capsnet
capsnet.mxnet
MXNet implementation of CapsNet
Stars: ✭ 30 (-59.46%)
Mutual labels:  capsnet
Capsnet Nlp
CapsNet for NLP
Stars: ✭ 66 (-10.81%)
Mutual labels:  capsnet
Capsnet
CapsNet (Capsules Net) in Geoffrey E Hinton paper "Dynamic Routing Between Capsules" - State Of the Art
Stars: ✭ 423 (+471.62%)
Mutual labels:  capsnet
CapsNet-keras-imdb
No description or website provided.
Stars: ✭ 15 (-79.73%)
Mutual labels:  capsnet

Implementation of "Matrix Capsules with EM Routing"

A TensorFlow implementation of Hinton's paper Matrix Capsules with EM Routing by Ashley Gritzman from IBM Research AI.

E-mail: [email protected]

This implementation fixes a number of common issues that were found in other open-source implementations, the main ones being:

  1. Parent capsules at different spatial positions compete for child capsules
  2. Numerical instability due to parent capsules with only one child
  3. Normalising the amount of data assigned to parent capsules

If you would like more information about these issues, please refer to the associated paper and blog.

Usage

Step 1. Download this repository with git or click the download ZIP button.

$ git clone https://github.com/IBM/matrix-capsules-with-em-routing.git
$ cd matrix-capsules-with-em-routing

Step 2. Download smallNORB dataset.

$ chmod +x data/download.sh
$ ./data/download.sh

The download is 251MB which will then be unzipped to about 856MB. The six .mat files are placed in the directory data/smallNORB/mat.

Step 3. Set up the environment with Anaconda. (See here for instructions on how to install Anaconda.)

With Anaconda (recommended):

$ conda env create -f capsenv.yml
$ conda activate capsenv

Without Anaconda:

$ pip install --requirement requirements.txt

Step 4. Generate TFRecord for train and test datasets from .mat files.

$ python ./data/convert_to_tfrecord.py

The resulting TFRecords are about 3.4GB each. The TensorFlow api employs multithreading, so this process should be fast (within a minute). If you are planning to commit to GitHub, make sure to ignore these files as they are too large to upload. The .tfrecord files for train and test datasets are placed in the data/smallNORB/tfrecord directory.

If you receive the errors:
Bus error (core dumped) python ./convert_to_tfrecord.py or
Killed python ./convert_to_tfrecord.py
these most likely indicate that you have insufficient memory (8GB should be enough), and you should try the sharded approach.

Step 5. Start the training and validation on smallNORB.

$ python train_val.py

If you need to monitor the training process, open tensorboard with this command.

$ tensorboard --logdir=./logs

To get the full list of command line flags, python train_val.py --helpfull

Step 6. Calculate test accuracy. Make sure to specify the actual path to your directory, the directory below "./logs/smallNORB/20190731_wip" is just an example.

$ python test.py --load_dir="./logs/smallNORB/20190731_wip"

Results

The graph below shows the test accuracy of our implementation after each training epoch for 1–3 iterations of EM routing. We achieve our best accuracy of 95.4% with 2 routing iterations, and with 3 iterations we get 93.7%. The table shows how our results stack up to other open source implementations available on GitHub: yl-1993, www0wwwjs1, Officium (as recorded on 28 May 2019). The accuracy of our implementation at 95.4% is a 3.8 percentage point improvement on the previous best open source implementation at 91.8%, however it is still a bit below the accuracy of Hinton et al. at 97.8%. To our knowledge, our implementation is currently the best open-source implementation available.

Implementation Framework Routing iterations Test accuracy
Hinton Not available 3 97.8%
yl-1993 PyTorch 1 74.8%
yl-1993 PyTorch 2 89.5%
yl-1993 PyTorch 3 82.5%
www0wwwjs1 Tensorflow 2 91.8%
Officium PyTorch 3 90.9%
Ours TensorFlow 1 86.2%
Ours TensorFlow 2 95.4%
Ours TensorFlow 3 93.7%

Implementation Details

If you would like more information on the implementation details, please refer to the associated paper and blog.

Acknowledgements

  1. Jonathan Hui's blog, "Understanding Matrix capsules with EM Routing (Based on Hinton's Capsule Networks)"
  2. Questions and answers on OpenReview, "Matrix capsules with EM routing"
  3. Suofei Zhang's implementation on GitHub, "Matrix-Capsules-EM-Tensorflow" 
  4. Guang Yang's implementation on GitHub, "CapsulesEM"

Contributions

Contributions are welcome, please submit a pull request.

How to Cite this Work

If you find this code useful in your academic work, please cite as follows:

A. Gritzman, "Avoiding Implementation Pitfalls of Matrix Capsules with EM Routing by Hinton et al.", in Joint Workshop on Human Brain and Artificial Intelligence (HBAI) at IJCAI'19, Macao, 2019.

Disclaimer: This is not an official IBM product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].