okunator commited on
Commit
24505ed
·
verified ·
1 Parent(s): 8246428

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +183 -3
README.md CHANGED
@@ -1,3 +1,183 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: image-segmentation
4
+ tags:
5
+ - medical
6
+ - biology
7
+ ---
8
+
9
+ # CPP-Net Model for High-Grade Serous Ovarian Cancer Panoptic Segmentation
10
+
11
+ # Model
12
+ - **histolytics** implementation of panoptic **CPP-Net**: [https://arxiv.org/abs/2102.06867](https://arxiv.org/abs/2102.06867)
13
+ - Backbone encoder: pre-trained **efficientnet_b5** from pytorch-image-models [https://github.com/huggingface/pytorch-image-models](https://github.com/huggingface/pytorch-image-models)
14
+
15
+
16
+ # USAGE
17
+
18
+ ## 1. Install histolytics and albumentations
19
+ ```
20
+ pip install histolytics
21
+ pip install albumentations
22
+ ```
23
+
24
+ ## 2. Load trained model
25
+ ```python
26
+ from histolytics.models.cppnet_panoptic import CPPNetPanoptic
27
+
28
+ model = CPPNetPanoptic.from_pretrained("hgsc_v1_efficientnet_b5")
29
+ ```
30
+
31
+ ## 3. Run inference for one image
32
+ ```python
33
+ from albumentations import Resize, Compose
34
+ from histolytics.utils import FileHandler
35
+ from histolytics.transforms.albu_transforms import MinMaxNormalization
36
+
37
+ model.set_inference_mode()
38
+
39
+ # Resize to multiple of 32 of your own choosing
40
+ transform = Compose([Resize(1024, 1024), MinMaxNormalization()])
41
+
42
+ im = FileHandler.read_img(IMG_PATH)
43
+ im = transform(image=im)["image"]
44
+
45
+ prob = model.predict(im)
46
+ out = model.post_process(prob)
47
+ # out = {"nuc": [(nuc instances (H, W), nuc types (H, W))], "tissue": [tissues (H, W)], "cyto": None}
48
+ ```
49
+
50
+ ## 3.1 Run inference for image batch
51
+ ```python
52
+ import torch
53
+ from histolytics.utils import FileHandler
54
+
55
+ model.set_inference_mode()
56
+
57
+ # dont use random matrices IRL
58
+ batch = torch.rand(8, 3, 1024, 1024)
59
+
60
+ prob = model.predict(im)
61
+ out = model.post_process(prob)
62
+ # out = {
63
+ # "nuc": [
64
+ # (nuc instances (H, W), nuc types (H, W)),
65
+ # (nuc instances (H, W), nuc types (H, W)),
66
+ # .
67
+ # .
68
+ # .
69
+ # (nuc instances (H, W), nuc types (H, W))
70
+ # ],
71
+ # "tissue": [
72
+ # (nuc instances (H, W), nuc types (H, W)),
73
+ # (nuc instances (H, W), nuc types (H, W)),
74
+ # .
75
+ # .
76
+ # .
77
+ # (nuc instances (H, W), nuc types (H, W))
78
+ # ],
79
+ # "cyto": None,
80
+ #}
81
+ ```
82
+
83
+ ## 4. Visualize output
84
+ ```python
85
+ from matplotlib import pyplot as plt
86
+ from skimage.color import label2rgb
87
+
88
+ fig, ax = plt.subplots(1, 4, figsize=(24, 6))
89
+ ax[0].imshow(im)
90
+ ax[1].imshow(label2rgb(out["nuc"][0][0], bg_label=0)) # inst_map
91
+ ax[2].imshow(label2rgb(out["nuc"][0][1], bg_label=0)) # type_map
92
+ ax[3].imshow(label2rgb(out["tissue"][0], bg_label=0)) # tissue_map
93
+ ```
94
+ <!-- ![out](cppnet_out.png) -->
95
+
96
+ ## Dataset Details
97
+ Semi-manually annotated HGSC Primary Omental samples from the (private) DECIDER cohort. Data acquired in the DECIDER project,
98
+ funded by the European Union’s Horizon 2020 research and innovation programme under grant agreement No 965193.
99
+
100
+ **Contains:**
101
+ - 198 varying sized image crops at 20x magnification.
102
+ - 98 468 annotated nuclei
103
+ - 699 744 885 pixels of annotated tissue region
104
+
105
+ ## Dataset classes
106
+
107
+ ```
108
+ nuc_classes = {
109
+ 0: "background",
110
+ 1: "neoplastic",
111
+ 2: "inflammatory",
112
+ 3: "connective",
113
+ 4: "dead",
114
+ 5: "macrophage_cell",
115
+ 6: "macrophage_nuc",
116
+ }
117
+
118
+ area_classes = {
119
+ 0: "background",
120
+ 1: "stroma",
121
+ 2: "omental_fat",
122
+ 3: "tumor",
123
+ 4: "hemorrage",
124
+ 5: "necrosis",
125
+ 6: "serum",
126
+ }
127
+ ```
128
+
129
+ ## Dataset Class Distribution
130
+ **Nuclei**:
131
+ - connective nuclei: 46 100 (~47%)
132
+ - neoplastic nuclei: 22 761 (~23%)
133
+ - inflammatory nuclei 19 185 (~19%)
134
+ - dead nuclei 1859 (~2%)
135
+ - macrophage nuclei and cytoplasms: 4550 (~5%)
136
+
137
+ **Tissues**:
138
+ - stromal tissue: 28%
139
+ - tumor tissue:29%
140
+ - omental fat: 20%
141
+ - hemorrhage 5%
142
+ - necrosis 13%
143
+ - serum 5%
144
+
145
+ # Model Training Details:
146
+ First, the image crops in the training data were tiled into 224x224px patches with a sliding window (stride=32px).
147
+
148
+ Rest of the training procedures follow this notebook: [link]
149
+
150
+ # Citation
151
+
152
+ histolytics:
153
+ ```
154
+ @article{
155
+
156
+ }
157
+ ```
158
+
159
+ CPP-Net original paper:
160
+ ```
161
+ @article{https://doi.org/10.48550/arxiv.2102.06867,
162
+ doi = {10.48550/ARXIV.2102.06867},
163
+ url = {https://arxiv.org/abs/2102.06867},
164
+ author = {Chen, Shengcong and Ding, Changxing and Liu, Minfeng and Cheng, Jun and Tao, Dacheng},
165
+ keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
166
+ title = {CPP-Net: Context-aware Polygon Proposal Network for Nucleus Segmentation},
167
+ publisher = {arXiv},
168
+ year = {2021},
169
+ copyright = {arXiv.org perpetual, non-exclusive license}
170
+ }
171
+ ```
172
+
173
+ ## Licence
174
+ These model weights are released under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at:
175
+
176
+ http://www.apache.org/licenses/LICENSE-2.0
177
+
178
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
179
+
180
+ ## Additional Terms
181
+
182
+ While the Apache 2.0 License grants broad permissions, we kindly request that users adhere to the following guidelines:
183
+ Medical or Clinical Use: This model is not intended for use in medical diagnosis, treatment, or prevention of disease of real patients. It should not be used as a substitute for professional medical advice.