

GitHub - IBM/matrix-capsules-with-em-routing: A TensorFlow implementation of &qu...
source link: https://github.com/IBM/matrix-capsules-with-em-routing
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:
- Parent capsules at different spatial positions compete for child capsules
- Numerical instability due to parent capsules with only one child
- 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
orKilled 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
- Jonathan Hui's blog, "Understanding Matrix capsules with EM Routing (Based on Hinton's Capsule Networks)"
- Questions and answers on OpenReview, "Matrix capsules with EM routing"
- Suofei Zhang's implementation on GitHub, "Matrix-Capsules-EM-Tensorflow"
- 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.
Recommend
-
142
CapsNet-Tensorflow A Tensorflow implementation of CapsNet based on Geoffrey Hinton's paper Dynamic Routing Between Capsules Notes:
-
88
CapsNet-Keras A Keras (branch tf2.2 supports TensorFlow 2) implementation of CapsNet in the paper:
-
156
pytorch-capsule A Pytorch implementation of Hinton's "Dynamic Routing Between Capsules". https://arxiv.org/pdf/1710.09829.pdf Thanks to @naturomics for his T...
-
138
Dynamic Routing Between Capsules A barebones CUDA-enabled PyTorch implementation of the CapsNet architecture in the paper "Dynamic Routing Between Capsules" by Kenta Iwasaki o...
-
61
Dynamic Routing Between Capsules - PyTorch implementation PyTorch implementation of NIPS 2017 paper Dynamic Routing Between Capsules from Sara Sabour, Nicholas Frosst...
-
36
GPT Neo 1T or bust my dudes An impleme...
-
6
Implementation of CIDR routing table in RustStep by step guide to implement CIDR routing in RustJanuary 29, 2022 · 11 min · RokaStep by step guide to implement CIDR routing in RustTable of Contents...
-
10
Why SpaceX Stopped Production Of The Crew Dragon Astronaut Capsules ...
-
14
This article covers the technical paper by Sara Sabour, Nicholas Frosst and Geoffrey Hinton on Dynamic Routing between Capsules. In this article, we will describe the basic Capsule...
-
10
“Understanding Matrix capsules with EM Routing (Based on Hinton's Capsule Networks)” Nov 14, 2017 This article covers the second Hinton’s capsule network paper
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK