Introduction
cellseg-models.pytorch is a library built upon PyTorch that contains multi-task encoder-decoder architectures along with dedicated post-processing methods for segmenting cell/nuclei instances. As the name might suggest, this library is heavily inspired by segmentation_models.pytorch library for semantic segmentation.
For panoptic segmentation and downstream spatial analysis of whole-slide images, see Histolytics. Histolytics uses cellseg-models.pytorch for its segmentation models.
Features
- Six model families for cell and nuclei instance segmentation.
- Pretrained checkpoints available through CSMP Hub.
- Configurable encoders, decoders and prediction heads.
- Cell-type classification and optional tissue segmentation alongside instance masks.
- Inference on individual images, sliding windows and whole-slide images.
- Datasets, transforms, losses and metrics for training and evaluation.
- ONNX export for all six model families.
Installation
pip install cellseg-models-pytorch
For optional training, ONNX export and OpenSlide installs, see the installation guide.
Read the documentation for the quick start, user guides and API reference.
Quick Start
Initialize a pre-trained model and run inference
pip install cellseg-models-pytorch
pip install albumentations==2.0.8
This checkpoint expects RGB images with pixel values scaled globally to 0–1.
import numpy as np
from albumentations import Normalize, Resize
from cellseg_models_pytorch.models.cellpose import CellPose
from cellseg_models_pytorch.utils import FileHandler
# Initialize a nuclei segmentation model trained on HGSC data.
# see models in https://huggingface.co/csmp-hub
model = CellPose.from_pretrained(weights="hgsc_v1_efficientnet_b5")
model.set_inference_mode()
# Resize to multiple of 32 of your own choosing
resize = Resize(1024, 1024)
normalize = Normalize(normalization="min_max")
im = FileHandler.read_img(IMG_PATH)
# Match the checkpoint's float32 preprocessing before normalization.
im = resize(image=im)["image"].astype(np.float32, copy=False)
im = normalize(image=im)["image"]
prob = model.predict(im)
out = model.post_process(prob)
# out = {"nuc": [(nuc instances (H, W), nuc types (H, W))], "cyto": None, "tissue": None}
Models
Six model families are available. Find pretrained checkpoints on csmp-hub on Hugging Face.
| Model | Paper |
|---|---|
| [1] HoVer-Net | https://www.sciencedirect.com/science/article/pii/S1361841519301045?via%3Dihub |
| [2] Cellpose | https://www.nature.com/articles/s41592-020-01018-x |
| [3] Omnipose | https://www.biorxiv.org/content/10.1101/2021.11.03.467199v2 |
| [4] Stardist | https://arxiv.org/abs/1806.03535 |
| [5] CellVit-SAM | https://arxiv.org/abs/2306.15350 |
| [6] InstanSeg | https://arxiv.org/abs/2408.15954 |
Datasets
Download prepared datasets from CSMP Hub. Each linked dataset card describes its format, labels, splits and license.
| Dataset | Images | Splits | License |
|---|---|---|---|
| [7, 8] PanNuke | 7,901 | fold1, fold2, fold3 |
CC BY-NC-SA 4.0 (noncommercial) |
| [9] PanopTILs Refined | 1,349 | Patient-separated train, val, test |
CC0 1.0 |
| [10] PUMA | 206 | Public challenge train |
CC0 1.0 |
| [11] CytoNuke | 83 | New patient-separated train, val, test |
CC BY 4.0 (CPTAC images: CC BY 3.0) |
| [12] HeLaCytoNuc | 2,676 | Original train, val (automatic labels), test (manual labels) |
CC BY 4.0 |
| [13] AIR-LEISH | 180 | train only; no independent evaluation split |
CC BY 4.0 |
| [14, 15] Lizard-Mitosis | 4,981 | Original train, val, test; train/val overlap |
CC BY-NC-SA 4.0 (noncommercial) |
| [16] Human Lung | 68 | Original train (51), val (7), test (10); patient independence unverified |
CC BY-NC 4.0 (noncommercial) |
| [17, 18, 19] VitaminP ORION-CRC | 3,337 | Original case-separated train (2,946), val (272), test (119) |
CC BY 4.0 |
Load one PanopTILs Refined sample:
from io import BytesIO
import numpy as np
import pyarrow.parquet as pq
from huggingface_hub import hf_hub_download
from PIL import Image
def read_png(data: bytes) -> np.ndarray:
"""Decode RGB pixels or integer labels without reducing mask bit depth."""
with Image.open(BytesIO(data)) as image:
return np.array(image)
path = hf_hub_download(
repo_id="csmp-hub/panoptils_refined",
repo_type="dataset",
filename="train.parquet",
)
row = next(pq.ParquetFile(path).iter_batches(batch_size=1)).to_pylist()[0]
image = read_png(row["image"])
instances = read_png(row["inst"])
cell_types = read_png(row["type"])
tissue_types = read_png(row["sem"])
References
See REFERENCES.md for model papers and dataset sources.
Citation
Please cite the version you used. CITATION.cff provides citation metadata for the software as a whole. The example below cites version 0.1.30.
@misc{lehtonen_cellseg_models_2025,
doi = {10.5281/zenodo.17608242},
url = {https://doi.org/10.5281/zenodo.17608242},
author = {Lehtonen, Oskari},
title = {{cellseg_models.pytorch}},
version = {0.1.30},
publisher = {Zenodo},
year = {2025}
}
Licence
Original code in this project is licensed under MIT. Adapted third-party code retains its original terms. See third-party notices for sources and bundled license texts, including timm, Diffusers, Kornia, MetaFormer, HoVer-Net, Cellpose, StarDist, scikit-image and HistoPrep. Dataset and pretrained-weight licenses are documented separately in their cards.
Metadata
Release files for cellseg-models-pytorch 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cellseg_models_pytorch-0.2.0.tar.gz | 200.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cellseg_models_pytorch-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 531.2 kB
Release files / cellseg_models_pytorch-0.2.0.tar.gz
| Download URL | cellseg_models_pytorch-0.2.0.tar.gz |
|---|---|
| Size | 200.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b46cba183f6b3ec3bf77330a3b9bedc838d3803c2d6ae385c3684b4f35c5c26c
|
|
BLAKE2b-256 checksum How to use checksums |
e3c875ab6eb4048e3b4561d787cbedc8fadbd530d2a24ad40c79165a06a2c5b6
|
| 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 Oct 20, 2026.
Transparency logRelease files / cellseg_models_pytorch-0.2.0-py3-none-any.whl
| Download URL | cellseg_models_pytorch-0.2.0-py3-none-any.whl |
|---|---|
| Size | 331.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23293c5c8f6d5a9fd74aa5c61f1a46d0fafec606b8e50a8856d4f97e2d4e0ce9
|
|
BLAKE2b-256 checksum How to use checksums |
0111f0daffb8f00b582e62cef732dc42043d072f255c6cae163466bfe5b4bace
|
| 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 Oct 20, 2026.
Transparency logSecurity for cellseg-models-pytorch 0.2.0
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.
Attestation for cellseg_models_pytorch-0.2.0.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 Oct 20, 2026.
Transparency logA 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.