{"id":15647291,"url":"https://github.com/dragen1860/capsnet-pytorch","last_synced_at":"2025-04-30T12:41:43.415Z","repository":{"id":95699418,"uuid":"109246029","full_name":"dragen1860/CapsNet-Pytorch","owner":"dragen1860","description":"Pytorch version of Hinton's Capsule Theory paper: Dynamic Routing Between Capsules","archived":false,"fork":false,"pushed_at":"2018-01-19T02:16:47.000Z","size":69039,"stargazers_count":45,"open_issues_count":4,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T16:12:06.587Z","etag":null,"topics":["capsnet-pytorch","deep-learning","machine-learning","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dragen1860.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-02T09:48:15.000Z","updated_at":"2025-01-21T04:06:04.000Z","dependencies_parsed_at":"2023-05-21T15:30:45.908Z","dependency_job_id":null,"html_url":"https://github.com/dragen1860/CapsNet-Pytorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragen1860%2FCapsNet-Pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragen1860%2FCapsNet-Pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragen1860%2FCapsNet-Pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragen1860%2FCapsNet-Pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dragen1860","download_url":"https://codeload.github.com/dragen1860/CapsNet-Pytorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251702048,"owners_count":21629940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capsnet-pytorch","deep-learning","machine-learning","pytorch"],"created_at":"2024-10-03T12:18:13.949Z","updated_at":"2025-04-30T12:41:43.390Z","avatar_url":"https://github.com/dragen1860.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/dragen1860/CapsNet-Pytorch.git)\n\n# CapsNet-Pytorch\nPytorch version of Hinton's paper: [Dynamic Routing Between Capsules](https://arxiv.org/abs/1710.09829)\n\u003e Some implementations of CapsNet online have potential problems and it's uneasy to realize the bugs since MNIST is too simple to achieve satisfying accuracy.\n\n# Network\n![](res/model.png)\n\u003e Corresponding pipeline: Input \u003e Conv1 \u003e Caps(cnn inside) \u003e Route \u003e Loss  \n\n# Screenshots\n- running\n![](res/capsnet-cmd.png)\n- training loss\n![](res/accuracy-loss.png)\n\n# Highlights\n- Highly abstraction of `Caps` layer, by re-writing the function `create_cell_fn` you can implement your own sub-network inside `Caps` Layer\n```python\n    def create_cell_fn(self):  \n            \"\"\"  \n            create sub-network inside a capsule.  \n            :return:  \n            \"\"\"  \n            conv1 = nn.Conv2d(self.conv1_kernel_num, self.caps1_conv_kernel_num, kernel_size = self.caps1_conv_kernel_size, stride = self.caps1_conv1_stride)  \n            #relu = nn.ReLU(inplace = True)  \n            #net = nn.Sequential(conv1, relu)  \n            return conv1  \n```\n- Highly abstraction of routing layer by class `Route`, you can take use of `Caps` Layer and `Route` Layer to construct any type of network\n- No DigitsCaps Layer, and we just just the output of `Route` layer.\n\n## Status\n\n- Currently we train our model for 30 epochs, which means it is potentially promising if more epochs are used to train\n- We don not use reconstruction loss now, and will add it later\n- The critical part of code is well commented with each dimension changes, which means you can follow the comments to understand the routing mechnism\n\n## TODO\n- add reconstruction loss\n- test on more convincing dataset, such as ImagetNet\n\n## About me\n\u003e I'm a Research Assistant @ National University of Singapre, before joinging NUS, I was a first-year PhD candidate in Zhejiang University and then quitted.\nContact me with email: dcslong@nus.edu.sg or wechat: dragen1860\n\n# Usage\n\n## Step 1. Install Conda, CUDA, cudnn and Pytorch\n\u003econda install pytorch torchvision cuda80 -c soumith\n\n## Step 2. Clone the repository to local\n\u003egit clone https://github.com/dragen1860/CapsNet-Pytorch.git  \n\u003ecd CapsNet-Pytorch\n\n## Step 3. Train CapsNet on MNIST\n\n1. please modify the variable `glo_batch_size = 125` to appropriate size according to your GPU memory size.\n2. run\n\u003e$ python main.py\n3. turn on tensorboard\n\u003e$ tensorboard --logdir runs \n\n## Step 4. Validate CapsNet on MNIST\nOR you can comment the part of train code and test its performance with pretrained model `mdl` file.\n\n# Results\n\n| Model    | Routing | Reconstruction | MNIST |   |\n|----------|---------|----------------|-------|---|\n| Baseline | -       | -              | 0.39  |   |\n| Paper    | 3       | no             | 0.35  |   |\n| Ours     | 3       | no             | **0.34**|   |\n\nIt takes about 150s per epoch for single GTX 970 4GB Card.\n\n## Other Implementations\n- Keras:\n  - [XifengGuo/Capsnet-Keras](https://github.com/XifengGuo/CapsNet-Keras) Well written.\n\n- TensorFlow:\n  - [naturomics/CapsNet-Tensorflow](https://github.com/naturomics/CapsNet-Tensorflow.git)  The first implementation online. \n  - [InnerPeace-Wu/CapsNet-tensorflow](https://github.com/InnerPeace-Wu/CapsNet-tensorflow)  \n  - [LaoDar/tf_CapsNet_simple](https://github.com/LaoDar/tf_CapsNet_simple)\n  \n- MXNet:\n  - [AaronLeong/CapsNet_Mxnet](https://github.com/AaronLeong/CapsNet_Mxnet)\n  \n- Lasagne (Theano):\n  - [DeniskaMazur/CapsNet-Lasagne](https://github.com/DeniskaMazur/CapsNet-Lasagne)\n\n- Chainer:\n  - [soskek/dynamic_routing_between_capsules](https://github.com/soskek/dynamic_routing_between_capsules)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragen1860%2Fcapsnet-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdragen1860%2Fcapsnet-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragen1860%2Fcapsnet-pytorch/lists"}