All Projects → leftthomas → CapsuleLayer

leftthomas / CapsuleLayer

Licence: MIT license
PyTorch Capsule Layer

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to CapsuleLayer

Capsnet Tensorflow
A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules
Stars: ✭ 3,776 (+13385.71%)
Mutual labels:  routing-algorithm, capsule, 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 (-42.86%)
Mutual labels:  capsule, capsnet
Capsnet Keras
A Keras implementation of CapsNet in NIPS2017 paper "Dynamic Routing Between Capsules". Now test error = 0.34%.
Stars: ✭ 2,428 (+8571.43%)
Mutual labels:  capsule, capsnet
capsnet.mxnet
MXNet implementation of CapsNet
Stars: ✭ 30 (+7.14%)
Mutual labels:  capsule, capsnet
SegCaps
A Clone version from Original SegCaps source code with enhancements on MS COCO dataset.
Stars: ✭ 62 (+121.43%)
Mutual labels:  capsule
motis
Intermodal Mobility Information System
Stars: ✭ 45 (+60.71%)
Mutual labels:  routing-algorithm
Dynamic routing between capsules
Implementation of Dynamic Routing Between Capsules, Sara Sabour, Nicholas Frosst, Geoffrey E Hinton, NIPS 2017
Stars: ✭ 202 (+621.43%)
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 (+464.29%)
Mutual labels:  capsnet
capsules-tensorflow
Another implementation of Hinton's capsule networks in tensorflow.
Stars: ✭ 18 (-35.71%)
Mutual labels:  capsnet
tf CapsNet
A tensorflow implementation for CapsNet
Stars: ✭ 19 (-32.14%)
Mutual labels:  capsnet
CapsNet-Fashion-MNIST
Capsule Network on Fashion MNIST dataset
Stars: ✭ 93 (+232.14%)
Mutual labels:  capsnet
CapsuleGAN
An Experimental Implementation for CapsuleGAN.
Stars: ✭ 22 (-21.43%)
Mutual labels:  capsule
yates
YATES (Yet Another Traffic Engineering System)
Stars: ✭ 46 (+64.29%)
Mutual labels:  routing-algorithm
pinecone
Peer-to-peer overlay routing for the Matrix ecosystem
Stars: ✭ 361 (+1189.29%)
Mutual labels:  routing-algorithm
Spacex Api
🚀 Open Source REST API for SpaceX launch, rocket, core, capsule, starlink, launchpad, and landing pad data.
Stars: ✭ 8,973 (+31946.43%)
Mutual labels:  capsule
Capsnet Traffic Sign Classifier
A Tensorflow implementation of CapsNet(Capsules Net) apply on german traffic sign dataset
Stars: ✭ 166 (+492.86%)
Mutual labels:  capsnet
CapsNet
Empirical studies on Capsule Network representation and improvements implemented with PyTorch.
Stars: ✭ 39 (+39.29%)
Mutual labels:  capsnet
heinsen routing
Official implementation of "An Algorithm for Routing Capsules in All Domains" (Heinsen, 2019) in PyTorch.
Stars: ✭ 41 (+46.43%)
Mutual labels:  routing-algorithm
me recognition
CapsuleNet for Micro-expression Recognition (IEEE FG 2019)
Stars: ✭ 56 (+100%)
Mutual labels:  capsule
dynamic-routing-capsule-cifar
CapsNet reference from : https://github.com/XifengGuo/CapsNet-Keras
Stars: ✭ 34 (+21.43%)
Mutual labels:  capsule

Capsule Layer

PyTorch Capsule Layer, include conv2d and linear layers.

Requirements

conda install pytorch torchvision -c pytorch

Installation

pip install git+https://github.com/leftthomas/CapsuleLayer.git@master

To update:

pip install --upgrade git+https://github.com/leftthomas/CapsuleLayer.git@master

Examples

CapsuleConv2d

import torch
from capsule_layer import capsule_cov2d
x = torch.rand(4, 8, 28, 50)
w = torch.randn(2, 8, 4, 3, 5)
if torch.cuda.is_available():
    x, w = x.to('cuda'), w.to('cuda')
# routing_type options: ['dynamic', 'k_means']
y, prob = capsule_cov2d(x, w, stride=1, padding=1, routing_type='k_means')

or with modules interface:

import torch
from capsule_layer import CapsuleConv2d
x = torch.rand(4, 8, 28, 50)
module = CapsuleConv2d(in_channels=8, out_channels=16, kernel_size=(3, 5), in_length=4, out_length=8, stride=1, padding=1, routing_type='k_means')
if torch.cuda.is_available():
    x, module = x.to('cuda'), module.to('cuda')
y, prob = module(x)

CapsuleLinear

import torch
from capsule_layer import capsule_linear
x = torch.rand(64, 128, 8)
w = torch.randn(10, 16, 8)
if torch.cuda.is_available():
    x, w = x.to('cuda'), w.to('cuda')
# routing_type options: ['dynamic', 'k_means']
y, prob = capsule_linear(x, w, share_weight=True, routing_type='dynamic')

or with modules interface:

import torch
from capsule_layer import CapsuleLinear
x = torch.rand(64, 128, 8)
module = CapsuleLinear(out_capsules=10, in_length=8, out_length=16, in_capsules=None, routing_type='dynamic', num_iterations=3)
if torch.cuda.is_available():
    x, module = x.to('cuda'), module.to('cuda')
y, prob = module(x)

Routing Algorithm

  • dynamic routing
import torch
import capsule_layer.functional as F
x = torch.rand(64, 10, 128, 8)
if torch.cuda.is_available():
    x = x.to('cuda')
y, prob = F.dynamic_routing(x, num_iterations=10)
  • k-means routing
import torch
import capsule_layer.functional as F
x = torch.rand(64, 5, 64, 8)
if torch.cuda.is_available():
    x = x.to('cuda')
# similarity options: ['dot', 'cosine', 'tonimoto', 'pearson']
y, prob = F.k_means_routing(x, num_iterations=100, similarity='tonimoto')

Similarity Algorithm

  • tonimoto similarity
import torch
import capsule_layer.functional as F
x1 = torch.rand(64, 16)
x2 = torch.rand(1, 16)
if torch.cuda.is_available():
    x1, x2 = x1.to('cuda'), x2.to('cuda')
y = F.tonimoto_similarity(x1, x2, dim=-1)
  • pearson similarity
import torch
import capsule_layer.functional as F
x1 = torch.rand(32, 8, 16)
x2 = torch.rand(32, 8, 1)
if torch.cuda.is_available():
    x1, x2 = x1.to('cuda'), x2.to('cuda')
y = F.pearson_similarity(x1, x2, dim=1)

Dynamic Scheduler

  • routing iterations
from capsule_layer import CapsuleLinear
from capsule_layer.optim import MultiStepRI
model = CapsuleLinear(3, 4, 7, num_iterations=2)
scheduler = MultiStepRI(model, milestones=[5, 20], addition=3, verbose=True)
# scheduler = MultiStepRI(model, milestones=[5, 20], addition=[3, 3], verbose=True)
for epoch in range(30):
    model.train()
    ...
    model.eval()
    ...
    scheduler.step()

Contribution

Any contributions to Capsule Layer are welcome!

Copyright and License

Capsule Layer is provided under the MIT License.

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