Skip to main content

BacLCT: Bacteria Life Cycle Tracking

Code for the paper Bacteria Tracking and Life Cycle State Classification using Graph Neural Networks and Pretrained Vision Transformers (Medical Image Analysis, 2026).

BacLCT is a unified GNN-based method for simultaneous tracking, division detection, and life cycle state classification of bacteria in time-lapse microscopy. Segmented cells are represented as nodes of a graph and their interactions over time as multi-frame edges. A message-passing GNN classifies the graph edges as correspondence, division, or no correspondence, and the graph nodes as life cycle states. From these predictions, trajectories are reconstructed. The division and multi-frame predictions are used for segmentation error correction, such as for missed detections, early divisions, and incorrect merges. The node features combine learned features from a DINO-pretrained Vision Transformer with handcrafted single-object features, so no task-specific encoder has to be trained.

BacLCT includes pre-trained models for tracking bacteria in bright field and phase contrast images, and for simultaneous tracking and life cycle state classification of B. subtilis spore germination and outgrowth in bright field images. It is also available as a napari plugin.

Documentation: https://baclct.readthedocs.io — getting started, user guide, and API reference.

Installation

It is recommended to install on a machine with a GPU. System requirements depend on the size of the image data and the number of objects in it. The smaller 2D sequences used in the paper (190 frames, ~500x500 px, ~10K objects) stayed below 8 GB of GPU and system RAM, while the larger ones (800 frames, ~1000x1000 px, >100K objects) required 16 GB of GPU and 32 GB of system RAM. Inference also works without a GPU, but will be much slower.

For inference and the napari plugin, install from PyPI into an environment (e.g., using Conda). If the environment should use a GPU, install PyTorch first.

pip install baclct              # inference
pip install "baclct[napari]"    # + the napari plugin

For training, it is recommended to clone the repository and install locally.

git clone https://github.com/bmcv/baclct
cd baclct
pip install -e ".[train]"       # training

Or let uv or Pixi set up and run everything in one command:

pixi run baclct-track --help   # check the install
uv run baclct-track --help

The Pixi environments are configured for Linux only and the full development environment is pinned in pixi.lock. Setup using uv also works on macOS and Windows. The documentation lists the commands for the napari plugin and for training.

Usage

import tifffile
from baclct import BacLCT

images = tifffile.imread("images.tif")  # (T, H, W)
masks = tifffile.imread("masks.tif")    # instance segmentation

pipeline = BacLCT()
tracked_masks, tracks = pipeline.track(images, masks, model="baclct_track")

masks must be an instance segmentation, one label per object; relabel a binary mask with skimage.measure.label first. Both images and masks may be numpy or dask arrays. tracked_masks are the input masks relabelled along their trajectories, and tracks has one row per cell and frame (label, t, the center coordinate, parent, and the single-cell features). If the model classifies life cycle states, tracks also has a state column. Pass output_dir to additionally export in CTC format or as flat CSV/TIF.

The baclct-track CLI mirrors this API. It takes the two paths directly, or a dataset directory in one of three layouts, and then tracks every sequence in it. See --help.

baclct-track images.tif masks.tif -o outputs/   # one sequence
baclct-track --data-dir data/ -o outputs/       # every sequence in a dataset

The same runs interactively in napari. baclct-napari opens a sequence with the plugin docked and the layers preselected, reading the frames on demand so a long movie opens at once:

baclct-napari images.tif masks.tif

It takes the same tracking flags as baclct-track, and the plugin is also reachable the usual way, under Plugins → BacLCT.

Pre-trained Models

Three pre-trained models for bacteria tracking are available by name, optionally with life cycle state classification. They were trained on two datasets, each model on the subset listed in the table below: bright-field sequences of germinating and outgrowing B. subtilis spores with annotated trajectories and life cycle states (https://doi.org/10.5281/zenodo.21805068) and phase-contrast sequences of growing C. glutamicum microcolonies with annotated trajectories (TOIAM, Seiffarth et al. 2025).

Model Use case Trained on
baclct_track Bacteria tracking and division detection. Bright-field and phase-contrast. Default. Spores + TOIAM
baclct_spore_classification_bf Bacteria tracking and division detection. Life cycle state classification for B. subtilis spore germination and outgrowth. Bright-field. Used in paper. Spores
baclct_toiam_pc Bacteria tracking and division detection. Phase-contrast. Used in paper. TOIAM

The models are downloaded automatically from the GitHub release on first use. A model is an experiment directory containing the config it was trained with and a checkpoint.

Training

baclct-train dataset=spores task=tracking_with_states fold=0
baclct-train dataset=toiam task=tracking fold=0

A run requires a configured dataset and task (see the directories in src/baclct/config/). The dataset defines the data and its graph parameters, and the task selects whether life cycle states and divisions are predicted. fold selects the cross-validation split and defaults to 0.

Datasets are read from paths.data_dir in CTC format. Next to the sequences, a splits.yaml maps each fold to train, val, and test sequence IDs, and an optional states.txt holds per-cell life cycle states. The splits used in the paper are in examples/splits/. Caching is mandatory for training: node features, DINO embeddings, and candidate edges are always written under paths.feature_dir and stay below 1 GB for a typical sequence, growing to a few GB for long or very dense ones.

To train on your own data, copy the annotated examples/configs/dataset/example.yaml, adjust the graph parameters to your images, and pass it with --config-dir:

baclct-train --config-dir examples/configs dataset=example task=tracking fold=0

BacLCT is configured with Hydra, so any key can be overridden on the command line or swept with --multirun. See the documentation for the config groups and for reproducing the paper's folds and ablations.

Citation

Kunzmann, M., Elizondo-Cantú, M. C., Bischofs, I. B., Rohr, K. Bacteria tracking and life cycle state classification using graph neural networks and pretrained vision transformers. Medical Image Analysis, 104275 (2026). doi:10.1016/j.media.2026.104275

When using the models with DINO-pretrained ViT features, please also cite Caron et al., ICCV 2021.

Declaration of generative AI use

Parts of the codebase were developed with AI assistance (Claude Code). This was used primarily for refactoring, organizing code and tests (e.g., converting existing notebooks into integration tests), packaging and parts of the documentation (e.g., Sphinx), debugging, as well as runtime and memory optimization (e.g., replacing existing code with faster libraries). Some components, notably several tests and the napari plugin, started as generated drafts that were subsequently corrected, partly reimplemented, or heavily refactored manually. Core functionality was ported from the author's previous implementation of this work. Where new functionality was generated, it was validated against the previous implementation, existing benchmarks, or hand-written tests. All generated code was reviewed and validated by the author.

Metadata

Release files for baclct 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for baclct 0.4.1
File Size Uploaded Provenance Actions
baclct-0.4.1.tar.gz 1.5 MB With provenance Details for baclct-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for baclct 0.4.1
File Interpreter ABI Platform Actions
baclct-0.4.1-py3-none-any.whl Python 3 none any Details for baclct-0.4.1-py3-none-any.whl

Total release size: 1.7 MB

Release files / baclct-0.4.1.tar.gz

Download URL baclct-0.4.1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
fad2e875174c626790e628dbadb2f8474c94a4490a92fccdcf115bae3347069b
BLAKE2b-256 checksum
How to use checksums
e02689ef87d658a17e731691fcdbca0a869149abc01951ba7d88cb1423bb52e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / baclct-0.4.1-py3-none-any.whl

Download URL baclct-0.4.1-py3-none-any.whl
Size 260.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d50188b50266196c67cce7f57cf197dc4690c491a98c1a58c3e032296089f44
BLAKE2b-256 checksum
How to use checksums
2baba6ba1d4df74e0ae4afedec2dc46742c3883ce933f5ac7550cb917593a618
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Security for baclct 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for baclct-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page