OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Models

Capsnet Pytorch

Capsnet Pytorch is a Python implementation of dynamic routing between capsules in PyTorch. It trains a capsule network on MNIST, supports optional reconstruction layers, and includes a Jupyter notebook for visualizing reconstructed digits and capsule dimensions.

Independent OpenViST project profile, based on linked sources.

Capsnet Pytorch — A compact example for learning about capsule networks in PyTorch
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use it for a code-based MNIST experiment when you want to study dynamic routing or inspect reconstruction behavior, rather than as a general-purpose image-classification service.

Who it is for

  • Developers and researchers studying capsule networks and dynamic routing.
  • Learners who want to train an MNIST model and explore its digit reconstructions.

Documented uses

  • Train a capsule-network baseline for MNIST classification.
  • Compare classification experiments using different routing-iteration counts.
  • Generate input-digit reconstructions with optional reconstruction layers.
  • Visualize how changes to individual digit-capsule dimensions affect reconstructions.
Before you choose

Requirements & limits

The repository is public and identifies a BSD-3-Clause license.

  • The training example is specific to MNIST handwritten digits.
  • Core requirements are PyTorch and torchvision; notebook visualizations also require Jupyter and matplotlib.
  • The README documents older tested PyTorch versions, 0.2.0 and 0.3.0.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Train the capsule network on MNIST

Run the documented training script with optional settings for routing and reconstruction.

Before you start

  • Python environment with PyTorch and torchvision.
  • Access to download the MNIST dataset; the script downloads it automatically.

Steps

  1. Run the command below from the project directory.

    Documented command
    python net.py
  2. Optionally set documented arguments such as --epochs, --lr, --routing_iterations, or --with_reconstruction.

Expected outcome

The script trains and tests the capsule network on MNIST, with configurable routing iterations and optional reconstruction layers.

Guide limitations

  • The README's reported 99.65% test accuracy is for reconstruction enabled with three routing iterations and is not a result guaranteed for other settings.
  • The README notes that test loss was still decreasing for that reported run.
Source-based practical guide

Explore digit reconstructions in the notebook

Use the provided notebook to inspect reconstructions and how digit-capsule dimensions affect them.

Before you start

  • Jupyter and matplotlib, in addition to the project’s PyTorch and torchvision requirements.

Steps

  1. Open reconstruction_visualization.ipynb in Jupyter.

  2. Use the notebook examples to view digit reconstructions and perturb digit-capsule dimensions.

Expected outcome

The examples show reconstructed digits and dimension perturbations, including changes associated with stroke thickness, digit width, and vertical position.

Guide limitations

  • The documented examples concern MNIST digit reconstructions and the model's 16 digit-capsule dimensions.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
12 November 2026
Original website title
adambielski/CapsNet-pytorch · Official homepage title · retained in its source language