All Projects → ethanleet → CapsNet

ethanleet / CapsNet

Licence: MIT license
Empirical studies on Capsule Network representation and improvements implemented with PyTorch.

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to CapsNet

capsules-tensorflow
Another implementation of Hinton's capsule networks in tensorflow.
Stars: ✭ 18 (-53.85%)
Mutual labels:  hinton, capsnet, capsule-network
capsnet.mxnet
MXNet implementation of CapsNet
Stars: ✭ 30 (-23.08%)
Mutual labels:  hinton, capsnet, dynamic-routing-between-capsules
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 (-58.97%)
Mutual labels:  hinton, capsnet, capsule-network
Capsnet Tensorflow
A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules
Stars: ✭ 3,776 (+9582.05%)
Mutual labels:  capsnet, capsule-network
Capsnet Traffic Sign Classifier
A Tensorflow implementation of CapsNet(Capsules Net) apply on german traffic sign dataset
Stars: ✭ 166 (+325.64%)
Mutual labels:  capsnet, capsule-network
Capsnet Visualization
🎆 A visualization of the CapsNet layers to better understand how it works
Stars: ✭ 371 (+851.28%)
Mutual labels:  capsnet, capsule-network
Variational Capsule Routing
Official Pytorch code for (AAAI 2020) paper "Capsule Routing via Variational Bayes", https://arxiv.org/pdf/1905.11455.pdf
Stars: ✭ 84 (+115.38%)
Mutual labels:  capsnet, capsule-network
Capslayer
CapsLayer: An advanced library for capsule theory
Stars: ✭ 351 (+800%)
Mutual labels:  capsnet, capsule-network
tf CapsNet
A tensorflow implementation for CapsNet
Stars: ✭ 19 (-51.28%)
Mutual labels:  capsnet, dynamic-routing-between-capsules
Capsule Gan
Code for my Master thesis on "Capsule Architecture as a Discriminator in Generative Adversarial Networks".
Stars: ✭ 120 (+207.69%)
Mutual labels:  capsnet, capsule-network
Capsule Net Pytorch
[NO MAINTENANCE INTENDED] A PyTorch implementation of CapsNet architecture in the NIPS 2017 paper "Dynamic Routing Between Capsules".
Stars: ✭ 158 (+305.13%)
Mutual labels:  capsnet, capsule-network
Capsnet Keras
A Keras implementation of CapsNet in NIPS2017 paper "Dynamic Routing Between Capsules". Now test error = 0.34%.
Stars: ✭ 2,428 (+6125.64%)
Mutual labels:  capsnet, capsule-network
Capsnet Nlp
CapsNet for NLP
Stars: ✭ 66 (+69.23%)
Mutual labels:  capsnet
Dynamic routing between capsules
Implementation of Dynamic Routing Between Capsules, Sara Sabour, Nicholas Frosst, Geoffrey E Hinton, NIPS 2017
Stars: ✭ 202 (+417.95%)
Mutual labels:  capsnet
Capsnet Pytorch
PyTorch implementation of NIPS 2017 paper Dynamic Routing Between Capsules
Stars: ✭ 440 (+1028.21%)
Mutual labels:  capsnet
Capsnet
CapsNet (Capsules Net) in Geoffrey E Hinton paper "Dynamic Routing Between Capsules" - State Of the Art
Stars: ✭ 423 (+984.62%)
Mutual labels:  capsnet
Subject-and-Sentiment-Analysis
汽车行业用户观点主题及情感识别
Stars: ✭ 24 (-38.46%)
Mutual labels:  capsule-network
Capsnet
A PyTorch implementation of CapsNet based on NIPS 2017 paper "Dynamic Routing Between Capsules"
Stars: ✭ 141 (+261.54%)
Mutual labels:  capsnet
Capsnet guide pytorch
A tutorial-style implementation of CapsNet in PyTorch
Stars: ✭ 104 (+166.67%)
Mutual labels:  capsnet
CapsNet-Fashion-MNIST
Capsule Network on Fashion MNIST dataset
Stars: ✭ 93 (+138.46%)
Mutual labels:  capsnet

CapsNet

Capsule networks is a novel approach showing promising results on SmallNorb and MNIST. Here we reproduce and build upon the impressive results shown by Sara Sabour et al. We experiment on the Capsule Network architecture by visualizing exactly what the capsules on different layers represents, what information they store about 3D objects in an image, and try to improve its classification results on CIFAR10 and SmallNorb with various methods including some tricks with reconstruction loss. Further, We present a deconvolution-based reconstruction module that reduces the number of learnable parameters by 80% from the fully-connected module presented by Sara Sabour et al.

Benchmarks

Our baseline model is the same as the original paper, but is only trained for 113 epochs on MNIST, and we did not use a 7-model ensemble for CIFAR10 as did in the paper.

Model MNIST SmallNORB CIFAR10
Sabour et al. 99.75% 97.3% 89.40%
Baseline 99.73% 91.5% 72.59%

Experiments

We introduced a deconvolution-based reconstructions module, and experimented with Batch normalization and different network topologies.

Deconvolution-based Reconstruction

The baseline model has 1.4M parameters in the fully connected decoder, while our deconvolution-based reconstruction module recudes the number of learnable parameters by 80% down to 0.25M.

Here is an comparison between the two reconstruction modules after training for 25 epochs on MNIST, where RLoss is the SSE reconstruction loss, and MLoss is the margin loss.

Model RLoss MLoss Accuracy
FC 21.62 0.0058 99.51%
FC w/ BN 13.12 0.0054 99.54%
DeConv 10.87 0.0050 99.54%
DeConv w/ BN 9.52 0.0044 99.55%

Visualization

Reconstructions

Here are the reconstruction results for SmallNORB and CIFAR10, after training for 186 epochs and 86 epochs respectively.

Robustness to Affine Transformations

We visualized how the network recognizes a rotated MNIST image when only trained on unmodified MNIST data. We present an image of number 2 as an example. The network is confident about the result when the image is just slightly rotated, but as the image is further rotated, it starts to confuse the image with other numbers. For example, it is very confident about the image being number 7 at a certain angle, and reconstructs a number 7 that aligns pretty well with the input. Due to its special topological features, the input number 2 is still recognized by the network when rotated by 180°.

Primary Capsules Reconstructions

We used a pre-trained network to train a reconstruction module for Primary Capsules. By scaling these capsules by its routing coefficients to the classified object, we were able to visualize reconstructions from Primary Capsules. Each row is reconstructed from a single capsule, and the routing coefficient is increased from left to right.

Usage

Step 1. Install requirements

  • Python 3
  • PyTorch 1.0.1
  • Torchvision 0.2.1
  • TQDM

Step 2. Adjust hyperparameters

In constants.py:

DEFAULT_LEARNING_RATE = 0.001
DEFAULT_ALPHA = 0.0005 # Scaling factor for reconstruction loss
DEFAULT_DATASET = "small_norb" # 'mnist', 'small_norb'
DEFAULT_DECODER = "FC" # 'FC' or 'Conv'
DEFAULT_BATCH_SIZE = 128
DEFAULT_EPOCHS = 300
DEFAULT_USE_GPU = True
DEFAULT_ROUTING_ITERATIONS = 3

Step 3. Start training

Training with default settings:

$ python train.py

Training flags example:

$ python train.py --decoder=Conv  --file=model32.pt --dataset=mnist

Further help with training flags:

$ python train.py -h

Step 4. Get your results

Trained models are saved in saved_models directory. Tensorboard logs are saved to logs/. You can launch tensorboard with

tensorboard --logdir logs

Future work

  • Fully develop notebooks for visualization and plotting.
  • Implement EM routing.
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].