All Projects → laubonghaudoi → Capsnet_guide_pytorch

laubonghaudoi / Capsnet_guide_pytorch

Licence: apache-2.0
A tutorial-style implementation of CapsNet in PyTorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Capsnet guide pytorch

Capsnet Traffic Sign Classifier
A Tensorflow implementation of CapsNet(Capsules Net) apply on german traffic sign dataset
Stars: ✭ 166 (+59.62%)
Mutual labels:  capsnet
capsules-tensorflow
Another implementation of Hinton's capsule networks in tensorflow.
Stars: ✭ 18 (-82.69%)
Mutual labels:  capsnet
Capsnet
CapsNet (Capsules Net) in Geoffrey E Hinton paper "Dynamic Routing Between Capsules" - State Of the Art
Stars: ✭ 423 (+306.73%)
Mutual labels:  capsnet
Capsnet Keras
A Keras implementation of CapsNet in NIPS2017 paper "Dynamic Routing Between Capsules". Now test error = 0.34%.
Stars: ✭ 2,428 (+2234.62%)
Mutual labels:  capsnet
tf CapsNet
A tensorflow implementation for CapsNet
Stars: ✭ 19 (-81.73%)
Mutual labels:  capsnet
CapsNet-keras-imdb
No description or website provided.
Stars: ✭ 15 (-85.58%)
Mutual labels:  capsnet
Capsnet
A PyTorch implementation of CapsNet based on NIPS 2017 paper "Dynamic Routing Between Capsules"
Stars: ✭ 141 (+35.58%)
Mutual labels:  capsnet
Matrix Capsules With Em Routing
A TensorFlow implementation of "Matrix Capsules with EM Routing" by Hinton et al. (2018).
Stars: ✭ 74 (-28.85%)
Mutual labels:  capsnet
capsnet.mxnet
MXNet implementation of CapsNet
Stars: ✭ 30 (-71.15%)
Mutual labels:  capsnet
Capsnet Tensorflow
A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules
Stars: ✭ 3,776 (+3530.77%)
Mutual labels:  capsnet
CapsNet-Fashion-MNIST
Capsule Network on Fashion MNIST dataset
Stars: ✭ 93 (-10.58%)
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 (-84.62%)
Mutual labels:  capsnet
Capslayer
CapsLayer: An advanced library for capsule theory
Stars: ✭ 351 (+237.5%)
Mutual labels:  capsnet
Dynamic routing between capsules
Implementation of Dynamic Routing Between Capsules, Sara Sabour, Nicholas Frosst, Geoffrey E Hinton, NIPS 2017
Stars: ✭ 202 (+94.23%)
Mutual labels:  capsnet
Capsnet Pytorch
PyTorch implementation of NIPS 2017 paper Dynamic Routing Between Capsules
Stars: ✭ 440 (+323.08%)
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 (+51.92%)
Mutual labels:  capsnet
CapsuleLayer
PyTorch Capsule Layer
Stars: ✭ 28 (-73.08%)
Mutual labels:  capsnet
Variational Capsule Routing
Official Pytorch code for (AAAI 2020) paper "Capsule Routing via Variational Bayes", https://arxiv.org/pdf/1905.11455.pdf
Stars: ✭ 84 (-19.23%)
Mutual labels:  capsnet
Capsnet Nlp
CapsNet for NLP
Stars: ✭ 66 (-36.54%)
Mutual labels:  capsnet
Capsnet Visualization
🎆 A visualization of the CapsNet layers to better understand how it works
Stars: ✭ 371 (+256.73%)
Mutual labels:  capsnet

CapsNet Guide in PyTorch

Contributions welcome License

This is my PyTorch implementation of CapsNet in Hinton's paper Dynamic Routing Between Capsules. I try to implement in a style that helps newcomers understand the architecture of CapsNet and the idea of Capsules. Therefore I am not going to wrap the codes into capsule layer APIs, and I more oftenly declare constants rather than passing parameters to functions, neither are the codes optimized for speed. The classes and functions are supplemented with detailed comments. To read and understand the codes, simply start from the comments in main.py and follow the order list at the head of the file.

The figure below clearly illustrates the core idea of capsules:

capsuleVSneuron

As I am busy these days, I might not have time to checkout and fix every issue. But contributions are highly welcomed. If you find any bugs or errors in the codes, please do not hesitate to open an issue or a pull request.

Requirements

  • pytorch 0.4.1
  • torchvision
  • pytorch-extras (For one-hot vector conversion)
  • tensorboard-pytorch
  • tqdm

All codes are tested under Python 3.6.

Get Started

After cloning the repository, simply run the command:

python main.py

The codes will automatically download the MNIST dataset (if not exist) into ./data and start traing and testing. Tensorboard logs are automatically saved in ./runs, and model checkpoints are saved in ./ckpt by default.

Default parameters are defined in get_opts() in utils.py, which are listed below and can be changed by passing arguments. (e.g. python main.py -batch_size 128 -epochs 30)

-batch_size     64      # Data batch size for training and testing
-lr             1e-3    # Learning rate
-epochs         10      # Train epochs
-r              3       # Number of iterations of for Dynamic Routing
-use_cuda       True    # Use GPU
-print_every    10      # Interval of batches to print out losses

Based on my own experiments, one train epoch takes about 6 minutes on a GTX 1080Ti with default settings. (I set 10 epochs as default just for showcasing, you should try 30 or more.)

Results

I have not fine tuned the parameters, results below are obtained with the default configurations in the codes. You can find this Tensorboard log in ./runs/sample/. Please do make a pull request if you find out the best parameters :)

Train

train

Test

test

Reconstructed images

e1_l28.29 e2_l30.37 e3_l27.20 e4_l28.29 e5_l26.02 e6_l25.26 e7_l25.02 e8_l24.86 e9_l24.83 e10_l24.78

Reference

[1] Sabour, Sara, Nicholas Frosst, and Geoffrey E. Hinton. "Dynamic Routing Between Capsules." arXiv preprint arXiv:1710.09829 (2017).

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