This implementation is fork of , applied to IMDB texts reviews dataset.


A Keras implementation of CapsNet in the paper: Sara Sabour, Nicholas Frosst, Geoffrey E Hinton. Dynamic Routing Between Capsules. NIPS 2017




Step 1. Install Keras:

$ pip install keras

Step 2. Clone this repository with git.

$ git clone
$ cd CapsNet-Keras

Step 3. Training:

$ python

Training with one routing iteration (default 3).

$ python --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


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 --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

Capsnet Keras Imdb

Capsnet Keras Imdb Info

⭐ Stars 15
🔗 Source Code
🕒 Last Update 2 years ago
🕒 Created 5 years ago
🐞 Open Issues 4
➗ Star-Issue Ratio 4
😎 Author streamride