Skip to main content

Training code and pre-trained models for Neural Cellular Automata on different datasets and tasks

Project description

NCALab

NCALab is a framework designed to facilitate the creation and analysis of Neural Cellular Automata (NCA) implementations. NCAs are a new type of Artificial Neural Network model that operates on a grid of cells in multiple iterations. With NCALab, users can effortlessly explore various applications of NCA, including image segmentation, classification, and synthesis. The models are documented, unit-tested and type-checked and can be modified in a streamlined fashion.

For more information on NCAs, check out our curated Awesome List and our NCA Tutorial.

docs python-package manuscript status coverage

Python 3.10 Python 3.11 Python 3.12 Python 3.13 Python 3.14

Examples Gallery

Animation of a growing lizard emoji Animation of gastro-intestinal polyp segmentation using NCA Animation of a prediction on CIFAR-10 in feature space Animation of a prediction on DermaMNIST in feature space Animation of a prediction on DermaMNIST in feature space Animation of a prediction on PathMNIST in feature space

Neural Cellular Automata

NCA are a new type of neural architecture, fusing Cellular Automata and Artificial Neural Networks to create memory-efficient, robust models. By replacing the transition function of a Cellular Automaton with a neural network model (a Multi-Layer Perceptron), they can learn from labelled input data to achieve tasks like image classification or segmentation.

Generalized NCA Architecture

Akin to a traditional cellular automaton, a neural cellular automaton operates in multiple time steps (typically up to 100 steps until a prediction is considered finished). In each time step, the cells of an image are stochastically updated by a multilayer perceptron. Instead of a manual neighborhood aggregation (e.g. Moore or von Neumann neighborhood), neighboring cell states are determined by applying 2D depth-wise convolutions to the input image.

For a better overview on the basic NCA architecture, we recommend you to read the original 2020 NCA Paper by Mordvintsev et al.

Features

Features of NCALab include:

  • Easy training and evaluation of NCA models
  • Cascaded multi-scale training
  • Tensorboard integration with default presets
  • Training with k-fold cross-validation
  • Convenience features: Fixing random seeds, selecting compute devices, data processing
  • Animation and visualization of NCA predictions

Roadmap

The following features are planned for future releases of NCALab:

  • Implementation of more approaches presented in research that extend or tweak NCA models
  • Simplifyed saving and loading of trained NCA models
  • Evaluation of federated and continual learning with NCAs
  • NCAs that operate on 3D voxel data

Getting started

This project makes use of uv for package and dependency management. Please read the installation instructions of uv before proceeding or simply install it to your Python workspace by running:

pip install -U uv

Perhaps the best way of getting started with NCALab is to take a look at the provided usage example tasks, starting with the Growing Emoji task.

You may want to download pre-trained weights for all examples by issuing the following script:

uv run scripts/download_example_weights.py

Usage Example Tasks

So far, the following example tasks are implemented in NCALab:

  • Image Generation:
    • Growing NCA for emoji generation
      • Training and evaluation
      • Fine-tuning of a pre-trained emoji generator
      • Hyperparameter search
  • Image Classification:
    • Self-classifying MNIST digits
    • MedMNIST image classification (PathMNIST, BloodMNIST, DermaMNIST)
  • Image Segmentation:
    • Endoscopic polyp binary segmentation (Kvasir-SEG, public)

You can find those example tasks inside the tasks/ directory and its subfolders.

Growing Lizard Example

A good starting point to get started with NCAs is the famous Growing Lizard emoji example.

uv run tasks/growing_emoji/train_growing_emoji.py

Run this script to generate a GIF of the trained model's prediction:

uv run tasks/growing_emoji/eval_growing_emoji.py

Installation

Run

pip install ncalab

to install the latest release through pip or

pip install git+https://github.com/MECLabTUDA/NCALab

for the most recent commit of NCALab. We recommend to install NCALab in a virtual environment.

Tensorboard integration

We recommend you to monitor your training progress in Tensorboard. To launch tensorboard, run

uv run tensorboard --logdir=runs

in a separate terminal. Once it is running, it should show you the URL the tensorboard server is running on, which is localhost:6006 by default. Alternatively, you may use the tensorboard integration of your IDE.

For Developers

The NCALab project comes with scripts and workflows to maintain software quality.

uv sync --group dev --group docs

Dry Training

To dry-train all example task models, run:

./scripts/dry_train_examples.sh

This script will run the training script of all models, but only for two epochs each. Checkpoints will not be saved.

Distribution

./scripts/train_examples.sh
uv run ./scripts/pack_example_weights.py
./scripts/save_animations.sh

Type Safety

To inspect the code base for type errors, run:

uv run mypy ncalab

Unit Tests and Code Analysis

Static code analysis:

uv run ruff check ncalab

Testing:

uv run pytest tests

View test coverage:

uv run coverage run --source ncalab -m pytest tests
uv run coverage report

Check for outdated dependencies:

uv tree --outdated

How to Cite

Coming soon.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ncalab-0.5.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ncalab-0.5.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file ncalab-0.5.1.tar.gz.

File metadata

  • Download URL: ncalab-0.5.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ncalab-0.5.1.tar.gz
Algorithm Hash digest
SHA256 174cbea4c73aff220c5656dad022375a2f3ff21e895197e738e2c40c57a86d8e
MD5 fe22d5a20466eb0fc5e6608dff438530
BLAKE2b-256 5de9ff3b37f8b9511cfde881c7c82feec6f7222810be6b467de2a06e9dbfed6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ncalab-0.5.1.tar.gz:

Publisher: python-publish.yml on MECLabTUDA/NCALab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ncalab-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: ncalab-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ncalab-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49f3d2e3e1362fb68d0f93f351bae0968029801663174a3be2db41d0ea659349
MD5 a3709a9fddf5028e627eef21c23b73c5
BLAKE2b-256 d9acb6cf6ebb96476b5ad593d65020f9a2b12291573c6b4a09c7922e34c47f0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ncalab-0.5.1-py3-none-any.whl:

Publisher: python-publish.yml on MECLabTUDA/NCALab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page