cellseg_models_pytorch


Namecellseg_models_pytorch JSON
Version 0.1.27 PyPI version JSON
download
home_pagehttps://github.com/okunator/cellseg_models.pytorch
SummaryPython library for 2D cell/nuclei instance segmentation models written with PyTorch.
upload_time2025-07-25 14:41:36
maintainerNone
docs_urlNone
authorOkunator
requires_python<4.0,>=3.10
licenseMIT
keywords cell segmentation nuclei segmentation pytorch pytorch-lightning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

![Logo](./images/logo.png)

**Python library for 2D cell/nuclei instance segmentation models written with [PyTorch](https://pytorch.org/).**

[![Generic badge](https://img.shields.io/badge/License-MIT-<COLOR>.svg?style=for-the-badge)](https://github.com/okunator/cellseg_models.pytorch/blob/master/LICENSE)
[![PyTorch - Version](https://img.shields.io/badge/PYTORCH-2+-red?style=for-the-badge&logo=pytorch)](https://pytorch.org/)
[![Python - Version](https://img.shields.io/badge/PYTHON-3.10+-red?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)
<br>
[![Github Test](https://img.shields.io/github/actions/workflow/status/okunator/cellseg_models.pytorch/tests.yml?label=Tests&logo=github&&style=for-the-badge)](https://github.com/okunator/cellseg_models.pytorch/actions/workflows/tests.yml)
[![Pypi](https://img.shields.io/pypi/v/cellseg-models-pytorch?color=blue&logo=pypi&style=for-the-badge)](https://pypi.org/project/cellseg-models-pytorch/)
[![Codecov](https://img.shields.io/codecov/c/github/okunator/cellseg_models.pytorch?logo=codecov&style=for-the-badge&token=oGSj7FZ1lm)](https://codecov.io/gh/okunator/cellseg_models.pytorch)
<br>
[![DOI](https://zenodo.org/badge/450787123.svg)](https://zenodo.org/badge/latestdoi/450787123)

</div>

<div align="center">

</div>

## Introduction

**cellseg-models.pytorch** is a library built upon [PyTorch](https://pytorch.org/) 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](https://github.com/qubvel/segmentation_models.pytorch) library for semantic segmentation. 

## What's new? 📢
- Simplified model usage
- First pre-trained models in [csmp-hub](https://huggingface.co/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](https://arxiv.org/abs/2206.15274), [Spectral decoupling](https://arxiv.org/abs/2011.09468), [Label smoothing](https://arxiv.org/abs/1512.00567).


## Installation 🛠️

```shell
pip install cellseg-models-pytorch
```

## Models 🤖

| Model                      | Paper                                                                          |
| -------------------------- | ------------------------------------------------------------------------------ |
| [[1](#Citation)] HoVer-Net | https://www.sciencedirect.com/science/article/pii/S1361841519301045?via%3Dihub |
| [[2](#Citation)] Cellpose  | https://www.nature.com/articles/s41592-020-01018-x                             |
| [[3](#Citation)] Omnipose  | https://www.biorxiv.org/content/10.1101/2021.11.03.467199v2                    |
| [[4](#Citation)] Stardist  | https://arxiv.org/abs/1806.03535                                               |
| [[5](#Citation)] CellVit-SAM  | https://arxiv.org/abs/2306.15350                                               |
| [[6](#Citation)] CPP-Net  | https://arxiv.org/abs/2102.06867                                               |

## Datasets

| Dataset                       | Paper                                                                                            |
| ----------------------------- | ------------------------------------------------------------------------------------------------ |
| [[7, 8](#References)] 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
```

```python
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

```bibtex
@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](https://github.com/okunator/cellseg_models.pytorch/blob/main/LICENSE)

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

- [timm](https://github.com/rwightman/pytorch-image-models) (Apache-2)
- [HoVer-Net](https://github.com/vqdang/hover_net) (MIT)
- [Cellpose](https://github.com/MouseLand/cellpose) (BSD-3)
- [Stardist](https://github.com/stardist/stardist) (BSD-3)

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/okunator/cellseg_models.pytorch",
    "name": "cellseg_models_pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "cell segmentation, nuclei segmentation, pytorch, pytorch-lightning",
    "author": "Okunator",
    "author_email": "oskari.lehtonen@helsinki.fi",
    "download_url": "https://files.pythonhosted.org/packages/dd/5c/c19a5b8bc269005c3305fd08ae65b9bba1734cb78d7c7a501aeaa894b019/cellseg_models_pytorch-0.1.27.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n![Logo](./images/logo.png)\n\n**Python library for 2D cell/nuclei instance segmentation models written with [PyTorch](https://pytorch.org/).**\n\n[![Generic badge](https://img.shields.io/badge/License-MIT-<COLOR>.svg?style=for-the-badge)](https://github.com/okunator/cellseg_models.pytorch/blob/master/LICENSE)\n[![PyTorch - Version](https://img.shields.io/badge/PYTORCH-2+-red?style=for-the-badge&logo=pytorch)](https://pytorch.org/)\n[![Python - Version](https://img.shields.io/badge/PYTHON-3.10+-red?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)\n<br>\n[![Github Test](https://img.shields.io/github/actions/workflow/status/okunator/cellseg_models.pytorch/tests.yml?label=Tests&logo=github&&style=for-the-badge)](https://github.com/okunator/cellseg_models.pytorch/actions/workflows/tests.yml)\n[![Pypi](https://img.shields.io/pypi/v/cellseg-models-pytorch?color=blue&logo=pypi&style=for-the-badge)](https://pypi.org/project/cellseg-models-pytorch/)\n[![Codecov](https://img.shields.io/codecov/c/github/okunator/cellseg_models.pytorch?logo=codecov&style=for-the-badge&token=oGSj7FZ1lm)](https://codecov.io/gh/okunator/cellseg_models.pytorch)\n<br>\n[![DOI](https://zenodo.org/badge/450787123.svg)](https://zenodo.org/badge/latestdoi/450787123)\n\n</div>\n\n<div align=\"center\">\n\n</div>\n\n## Introduction\n\n**cellseg-models.pytorch** is a library built upon [PyTorch](https://pytorch.org/) 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](https://github.com/qubvel/segmentation_models.pytorch) library for semantic segmentation. \n\n## What's new? \ud83d\udce2\n- Simplified model usage\n- First pre-trained models in [csmp-hub](https://huggingface.co/csmp-hub). More to come soon!\n\n## Features \ud83c\udf1f\n\n- High level API to define cell/nuclei instance segmentation models.\n- 6 cell/nuclei instance segmentation model architectures\n- Open source datasets for training and benchmarking.\n- Flexibility to modify the components of the model architectures.\n- Sliding window inference for large images.\n- Popular training losses and benchmarking metrics.\n- Benchmarking utilities\n- Regularization techniques to tackle batch effects/domain shifts such as [Strong Augment](https://arxiv.org/abs/2206.15274), [Spectral decoupling](https://arxiv.org/abs/2011.09468), [Label smoothing](https://arxiv.org/abs/1512.00567).\n\n\n## Installation \ud83d\udee0\ufe0f\n\n```shell\npip install cellseg-models-pytorch\n```\n\n## Models \ud83e\udd16\n\n| Model                      | Paper                                                                          |\n| -------------------------- | ------------------------------------------------------------------------------ |\n| [[1](#Citation)] HoVer-Net | https://www.sciencedirect.com/science/article/pii/S1361841519301045?via%3Dihub |\n| [[2](#Citation)] Cellpose  | https://www.nature.com/articles/s41592-020-01018-x                             |\n| [[3](#Citation)] Omnipose  | https://www.biorxiv.org/content/10.1101/2021.11.03.467199v2                    |\n| [[4](#Citation)] Stardist  | https://arxiv.org/abs/1806.03535                                               |\n| [[5](#Citation)] CellVit-SAM  | https://arxiv.org/abs/2306.15350                                               |\n| [[6](#Citation)] CPP-Net  | https://arxiv.org/abs/2102.06867                                               |\n\n## Datasets\n\n| Dataset                       | Paper                                                                                            |\n| ----------------------------- | ------------------------------------------------------------------------------------------------ |\n| [[7, 8](#References)] Pannuke | https://arxiv.org/abs/2003.10778 , https://link.springer.com/chapter/10.1007/978-3-030-23937-4_2 |\n\n\n## Quick Start \ud83d\udcbb\n\n**Initialize a pre-trained model and run inference**\n```\npip install cellseg-models-pytorch\npip install albumentations\n```\n\n```python\nfrom albumentations import Resize, Compose\nfrom cellseg_models_pytorch.models.cellpose import CellPose\nfrom cellseg_models_pytorch.utils import FileHandler\nfrom cellseg_models_pytorch.transforms.albu_transforms import MinMaxNormalization\n\n# intialize nuclei segmentation model trained on HGSC data\n# see models in https://huggingface.co/csmp-hub\nmodel = CellPose.from_pretrained(weights=\"hgsc_v1_efficientnet_b5\")\n\nmodel.set_inference_mode()\n\n# Resize to multiple of 32 of your own choosing\ntransform = Compose([Resize(1024, 1024), MinMaxNormalization()])\n\nim = FileHandler.read_img(IMG_PATH)\nim = transform(image=im)[\"image\"]\n\nprob = model.predict(im)\nout = model.post_process(prob)\n# out = {\"nuc\": [(nuc instances (H, W), nuc types (H, W))], \"cyto\": None, \"tissue\": None}\n```\n\n\n## References\n\n- [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.\n- [2] Stringer, C.; Wang, T.; Michaelos, M. & Pachitariu, M. Cellpose: a generalist algorithm for cellular segmentation Nature Methods, 2021, 18, 100-106\n- [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\n- [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\u2013273).\n- [5] H\u00f6rst, F., Rempe, M., Heine, L., Seibold, C., Keyl, J., Baldini, G., Ugurel, S., Siveke, J., Gr\u00fcnwald, 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.\n- [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\u2013994). Institute of Electrical and Electronics Engineers (IEEE). https://doi.org/10.1109/tip.2023.3237013\n- [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).\n- [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.\n- [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).\n\n## Citation\n\n```bibtex\n@misc{https://doi.org/10.5281/zenodo.15357070,\n  doi = {10.5281/ZENODO.15357070},\n  url = {https://zenodo.org/doi/10.5281/zenodo.15357070},\n  author = {Okunator,  },\n  title = {okunator/cellseg_models.pytorch: v0.1.26},\n  publisher = {Zenodo},\n  year = {2025},\n  copyright = {MIT License}\n}\n```\n\n## Licence\n\nThis project is distributed under [MIT License](https://github.com/okunator/cellseg_models.pytorch/blob/main/LICENSE)\n\nThe project contains code from the original cell segmentation and 3rd-party libraries that have permissive licenses:\n\n- [timm](https://github.com/rwightman/pytorch-image-models) (Apache-2)\n- [HoVer-Net](https://github.com/vqdang/hover_net) (MIT)\n- [Cellpose](https://github.com/MouseLand/cellpose) (BSD-3)\n- [Stardist](https://github.com/stardist/stardist) (BSD-3)\n\nIf 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.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library for 2D cell/nuclei instance segmentation models written with PyTorch.",
    "version": "0.1.27",
    "project_urls": {
        "Homepage": "https://github.com/okunator/cellseg_models.pytorch",
        "Repository": "https://github.com/okunator/cellseg_models.pytorch"
    },
    "split_keywords": [
        "cell segmentation",
        " nuclei segmentation",
        " pytorch",
        " pytorch-lightning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9562dde70cf6f37036b1c85413885d9c85aaa795f7314fa3277a5dbfcd5a059c",
                "md5": "2f57b051f29a14d3e16259c92d9f5b52",
                "sha256": "eaaf747aee35e71380ec6c180efb2fc55d1bc79d5b5c32231c6bbc25f73dd4fc"
            },
            "downloads": -1,
            "filename": "cellseg_models_pytorch-0.1.27-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2f57b051f29a14d3e16259c92d9f5b52",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 4004502,
            "upload_time": "2025-07-25T14:41:35",
            "upload_time_iso_8601": "2025-07-25T14:41:35.042963Z",
            "url": "https://files.pythonhosted.org/packages/95/62/dde70cf6f37036b1c85413885d9c85aaa795f7314fa3277a5dbfcd5a059c/cellseg_models_pytorch-0.1.27-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd5cc19a5b8bc269005c3305fd08ae65b9bba1734cb78d7c7a501aeaa894b019",
                "md5": "3b02d56033e45bb8be51bddc897e4c7e",
                "sha256": "a282229d0dbf63b48e04144e026b0aed91a57900bd6f526f7b5c2ced6f878ee7"
            },
            "downloads": -1,
            "filename": "cellseg_models_pytorch-0.1.27.tar.gz",
            "has_sig": false,
            "md5_digest": "3b02d56033e45bb8be51bddc897e4c7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3889740,
            "upload_time": "2025-07-25T14:41:36",
            "upload_time_iso_8601": "2025-07-25T14:41:36.457199Z",
            "url": "https://files.pythonhosted.org/packages/dd/5c/c19a5b8bc269005c3305fd08ae65b9bba1734cb78d7c7a501aeaa894b019/cellseg_models_pytorch-0.1.27.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-25 14:41:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "okunator",
    "github_project": "cellseg_models.pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cellseg_models_pytorch"
}
        
Elapsed time: 2.36630s