Views
No views yet
pip install histolytics
pip install albumentations1from histolytics.models.cellvit_panoptic import CellVitPanoptic
2
3model = CellVitPanoptic.from_pretrained("hgsc_v1_efficientnet_b5")1from albumentations import Resize, Compose
2from histolytics.utils import FileHandler
3from histolytics.transforms import MinMaxNormalization
4
5model.set_inference_mode(mixed_precision=False)
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))], "tissue": [tissues (H, W)], "cyto": None}1import torch
2from histolytics.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# "tissue": [
21# (nuc instances (H, W), nuc types (H, W)),
22# (nuc instances (H, W), nuc types (H, W)),
23# .
24# .
25# .
26# (nuc instances (H, W), nuc types (H, W))
27# ],
28# "cyto": None,
29}1from matplotlib import pyplot as plt
2from skimage.color import label2rgb
3
4fig, ax = plt.subplots(1, 4, figsize=(24, 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
8ax[3].imshow(label2rgb(out["tissue"][0], bg_label=0)) # tissue_map
nuc_classes = {
0: "background",
1: "neoplastic",
2: "inflammatory",
3: "connective",
4: "dead",
5: "macrophage_cell",
6: "macrophage_nuc",
}
tissue_classes = {
0: "background",
1: "stroma",
2: "omental_fat",
3: "tumor",
4: "hemorrage",
5: "necrosis",
6: "serum",
}@article{
}@article{CellViT,
title = {CellViT: Vision Transformers for precise cell segmentation and classification},
journal = {Medical Image Analysis},
volume = {94},
pages = {103143},
year = {2024},
issn = {1361-8415},
doi = {https://doi.org/10.1016/j.media.2024.103143},
url = {https://www.sciencedirect.com/science/article/pii/S1361841524000689},
author = {Fabian Hörst and Moritz Rempe and Lukas Heine and Constantin Seibold and Julius Keyl and Giulia Baldini and Selma Ugurel and Jens Siveke and Barbara Grünwald and Jan Egger and Jens Kleesiek},
}