Views
No views yet
pip install cellseg-models-pytorch
pip install albumentations1from cellseg_models_pytorch.models.cellpose import CellPose
2
3model = CellPose.from_pretrained("cin2_v1_efficientnet_b5")1from albumentations import Resize, Compose
2from cellseg_models_pytorch.utils import FileHandler
3from cellseg_models_pytorch.transforms.albu_transforms import MinMaxNormalization
4
5model.set_inference_mode()
6
7# Resize to multiple of 32 of your own choosing
8transform = Compose([Resize(1024, 1024), MinMaxNormalization()])
9
10im = FileHandler.read_img(IMG_PATH)
11im = transform(image=im)["image"]
12
13prob = model.predict(im)
14out = model.post_process(prob)
15# out = {"nuc": [(nuc instances (H, W), nuc types (H, W))], "cyto": None, "tissue": None}1import torch
2from cellseg_models_pytorch.utils import FileHandler
3
4model.set_inference_mode()
5
6# dont use random matrices IRL
7batch = torch.rand(8, 3, 1024, 1024)
8
9prob = model.predict(im)
10out = model.post_process(prob)
11# out = {
12# "nuc": [
13# (nuc instances (H, W), nuc types (H, W)),
14# (nuc instances (H, W), nuc types (H, W)),
15# .
16# .
17# .
18# (nuc instances (H, W), nuc types (H, W))
19# ],
20# "cyto": None,
21# "tissue": None
22#}1from matplotlib import pyplot as plt
2from skimage.color import label2rgb
3
4fig, ax = plt.subplots(1, 3, figsize=(18, 6))
5ax[0].imshow(im)
6ax[1].imshow(label2rgb(out["nuc"][0][0], bg_label=0)) # inst_map
7ax[2].imshow(label2rgb(out["nuc"][0][1], bg_label=0)) # type_map
nuc_classes = {
0: "background",
1: "neoplastic",
2: "inflammatory",
3: "connective",
4: "dead",
5: "glandular_epithelial",
6: "squamous_epithelial",
}@misc{https://doi.org/10.5281/zenodo.12666959,
doi = {10.5281/ZENODO.12666959},
url = {https://zenodo.org/doi/10.5281/zenodo.12666959},
author = {Okunator, },
title = {okunator/cellseg_models.pytorch: v0.2.0},
publisher = {Zenodo},
year = {2024},
copyright = {Creative Commons Attribution 4.0 International}
}@article{Stringer2020,
title = {Cellpose: a generalist algorithm for cellular segmentation},
volume = {18},
ISSN = {1548-7105},
url = {http://dx.doi.org/10.1038/s41592-020-01018-x},
DOI = {10.1038/s41592-020-01018-x},
number = {1},
journal = {Nature Methods},
publisher = {Springer Science and Business Media LLC},
author = {Stringer, Carsen and Wang, Tim and Michaelos, Michalis and Pachitariu, Marius},
year = {2020},
month = dec,
pages = {100–106}
}