Skip to main content

Logo

Python library for 2D cell/nuclei instance segmentation models written with PyTorch.

Generic badge PyTorch - Version Python - Version Model Checkpoints
Github Test Pypi Codecov DOI

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.

What's new? 📢

  • Simplified model usage
  • First pre-trained models in csmp-hub. More to come soon!

Features 🌟

  • High level API to define cell/nuclei instance segmentation models.
  • 6 cell/nuclei instance segmentation model architectures
  • Open source datasets for training and benchmarking.
  • Flexibility to modify the components of the model architectures.
  • Sliding window inference for large images.
  • Popular training losses and benchmarking metrics.
  • Benchmarking utilities
  • Regularization techniques to tackle batch effects/domain shifts such as Strong Augment, Spectral decoupling, Label smoothing.

Installation 🛠️

pip install cellseg-models-pytorch

Models 🤖

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] CPP-Net https://arxiv.org/abs/2102.06867

Datasets

Dataset Paper
[7, 8] Pannuke https://arxiv.org/abs/2003.10778 , https://link.springer.com/chapter/10.1007/978-3-030-23937-4_2

Quick Start 💻

Initialize a pre-trained model and run inference

pip install cellseg-models-pytorch
pip install albumentations
from albumentations import Resize, Compose
from cellseg_models_pytorch.models.cellpose import CellPose
from cellseg_models_pytorch.utils import FileHandler
from cellseg_models_pytorch.transforms.albu_transforms import MinMaxNormalization

# intialize 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
transform = Compose([Resize(1024, 1024), MinMaxNormalization()])

im = FileHandler.read_img(IMG_PATH)
im = transform(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}

References

  • [1] S. Graham, Q. D. Vu, S. E. A. Raza, A. Azam, Y-W. Tsang, J. T. Kwak and N. Rajpoot. "HoVer-Net: Simultaneous Segmentation and Classification of Nuclei in Multi-Tissue Histology Images." Medical Image Analysis, Sept. 2019.
  • [2] Stringer, C.; Wang, T.; Michaelos, M. & Pachitariu, M. Cellpose: a generalist algorithm for cellular segmentation Nature Methods, 2021, 18, 100-106
  • [3] Cutler, K. J., Stringer, C., Wiggins, P. A., & Mougous, J. D. (2022). Omnipose: a high-precision morphology-independent solution for bacterial cell segmentation. bioRxiv. doi:10.1101/2021.11.03.467199
  • [4] Uwe Schmidt, Martin Weigert, Coleman Broaddus, & Gene Myers (2018). Cell Detection with Star-Convex Polygons. In Medical Image Computing and Computer Assisted Intervention - MICCAI 2018 - 21st International Conference, Granada, Spain, September 16-20, 2018, Proceedings, Part II (pp. 265–273).
  • [5] Hörst, F., Rempe, M., Heine, L., Seibold, C., Keyl, J., Baldini, G., Ugurel, S., Siveke, J., Grünwald, B., Egger, J., & Kleesiek, J. (2023). CellViT: Vision Transformers for Precise Cell Segmentation and Classification (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2306.15350.
  • [6] Chen, S., Ding, C., Liu, M., Cheng, J., & Tao, D. (2023). CPP-Net: Context-Aware Polygon Proposal Network for Nucleus Segmentation. In IEEE Transactions on Image Processing (Vol. 32, pp. 980–994). Institute of Electrical and Electronics Engineers (IEEE). https://doi.org/10.1109/tip.2023.3237013
  • [7] Gamper, J., Koohbanani, N., Benet, K., Khuram, A., & Rajpoot, N. (2019) PanNuke: an open pan-cancer histology dataset for nuclei instance segmentation and classification. In European Congress on Digital Pathology (pp. 11-19).
  • [8] Gamper, J., Koohbanani, N., Graham, S., Jahanifar, M., Khurram, S., Azam, A.,Hewitt, K., & Rajpoot, N. (2020). PanNuke Dataset Extension, Insights and Baselines. arXiv preprint arXiv:2003.10778.
  • [9] Graham, S., Jahanifar, M., Azam, A., Nimir, M., Tsang, Y.W., Dodd, K., Hero, E., Sahota, H., Tank, A., Benes, K., & others (2021). Lizard: A Large-Scale Dataset for Colonic Nuclear Instance Segmentation and Classification. In Proceedings of the IEEE/CVF International Conference on Computer Vision (pp. 684-693).

Citation

@misc{https://doi.org/10.5281/zenodo.15357070,
  doi = {10.5281/ZENODO.15357070},
  url = {https://zenodo.org/doi/10.5281/zenodo.15357070},
  author = {Okunator,  },
  title = {okunator/cellseg_models.pytorch: v0.1.26},
  publisher = {Zenodo},
  year = {2025},
  copyright = {MIT License}
}

Licence

This project is distributed under MIT License

The project contains code from the original cell segmentation and 3rd-party libraries that have permissive licenses:

If you find this library useful in your project, it is your responsibility to ensure you comply with the conditions of any dependent licenses. Please create an issue if you think something is missing regarding the licenses.

Metadata

Release files for cellseg-models-pytorch 0.1.28

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

Source distribution (sdist)

Source distribution for cellseg-models-pytorch 0.1.28
File Size Uploaded Provenance
cellseg_models_pytorch-0.1.28.tar.gz 3.9 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cellseg-models-pytorch 0.1.28
File Interpreter ABI Platform
cellseg_models_pytorch-0.1.28-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 MB

Release files / cellseg_models_pytorch-0.1.28.tar.gz

Download URL cellseg_models_pytorch-0.1.28.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
85738f78783ced3793359d1d66e802b413a07fa60cb112e818902db9ed323231
BLAKE2b-256 checksum
How to use checksums
106a2e76baef96528474efe94ed00640672d45d2a6fc9f5a94811c16e037f62e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.10.18 Linux/6.11.0-1018-azure

Release files / cellseg_models_pytorch-0.1.28-py3-none-any.whl

Download URL cellseg_models_pytorch-0.1.28-py3-none-any.whl
Size 4.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5f138603cdb3b22b69b419eaf964cfc03d65acbaabe985f39b4f25096ba1fb2e
BLAKE2b-256 checksum
How to use checksums
67aee8d4101474f71603307608b43dc30c888007f7105437b2e0764a2ee32215
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.10.18 Linux/6.11.0-1018-azure

Security for cellseg-models-pytorch 0.1.28

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.1.28 This release

2 release files No 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