NOTE
This implementation is fork of https://github.com/XifengGuo/CapsNet-Keras , applied to IMDB texts reviews dataset.
CapsNet-Keras
A Keras implementation of CapsNet in the paper: Sara Sabour, Nicholas Frosst, Geoffrey E Hinton. Dynamic Routing Between Capsules. NIPS 2017
Requirements
- Keras
- matplotlib
Usage
Training
Step 1. Install Keras:
$ pip install keras
Step 2. Clone this repository with git
.
$ git clone https://github.com/streamride/CapsNet-keras-imdb.git
$ cd CapsNet-Keras
Step 3. Training:
$ python capsulenet.py
Training with one routing iteration (default 3).
$ python capsulenet.py --num_routing 1
Other parameters include batch_size, epochs, lam_recon, shift_fraction, save_dir
can passed to the function in the same way. Please refer to capsulenet.py
Testing
Suppose you have trained a model using the above command, then the trained model will be saved to result/trained_model.h5
. Now just launch the following command to get test results.
$ python capsulenet.py --is_training 0 --weights result/trained_model.h5
It will output the testing accuracy and show the reconstructed images. The testing data is same as the validation data. It will be easy to test on new data, just change the code as you want (Of course you can do it!!!)
Other Implementations
-
Kaggle (this version as self-contained notebook):
- MNIST Dataset running on the standard MNIST and predicting for test data
- MNIST Fashion running on the more challenging Fashion images.
-
TensorFlow:
- naturomics/CapsNet-Tensorflow
Very good implementation. I referred to this repository in my code. - InnerPeace-Wu/CapsNet-tensorflow
I referred to the use of tf.scan when optimizing my CapsuleLayer. - LaoDar/tf_CapsNet_simple
- naturomics/CapsNet-Tensorflow
-
PyTorch:
-
MXNet:
-
Lasagne (Theano):
-
Chainer: