Skip to main content

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

Project description

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
  • Flexibility to modify the components of the model architectures.
  • Sliding window inference for large images.

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.

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

cellseg_models_pytorch-0.1.30.tar.gz (3.9 MB view details)

Uploaded Source

Built Distribution

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

cellseg_models_pytorch-0.1.30-py3-none-any.whl (4.0 MB view details)

Uploaded Python 3

File details

Details for the file cellseg_models_pytorch-0.1.30.tar.gz.

File metadata

  • Download URL: cellseg_models_pytorch-0.1.30.tar.gz
  • Upload date:
  • Size: 3.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure

File hashes

Hashes for cellseg_models_pytorch-0.1.30.tar.gz
Algorithm Hash digest
SHA256 83384dedb2fe6be4aac629f36f51e5e4e4d1c70a9f82062013be3294dbf64bcc
MD5 62ac411f859ddca492154415dee43212
BLAKE2b-256 387d96a110bfaac5af5a0a3e6d39ad1dd95a4388143f601f866383caa13f619c

See more details on using hashes here.

File details

Details for the file cellseg_models_pytorch-0.1.30-py3-none-any.whl.

File metadata

File hashes

Hashes for cellseg_models_pytorch-0.1.30-py3-none-any.whl
Algorithm Hash digest
SHA256 e2e73d2b8248c45ea1309307bad0aba3e2bf29f9882bfe4465b9c7d3bcce25c0
MD5 de9f765182cc415c8c197532b652eb50
BLAKE2b-256 aa8a97a0b724be1c0614807f42b15b1373e7f175241d51bc6ef860a7e08097bf

See more details on using hashes here.

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