Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,139 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
library_name: transformers
|
3 |
-
tags: []
|
4 |
---
|
5 |
|
6 |
-
# Model Card for Model ID
|
7 |
|
8 |
-
|
9 |
|
|
|
|
|
10 |
|
|
|
|
|
11 |
|
12 |
-
## Model
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
### Model Sources [optional]
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
|
|
|
37 |
|
38 |
-
|
|
|
|
|
|
|
39 |
|
40 |
-
|
|
|
41 |
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
|
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
-
|
70 |
-
## How to Get Started with the Model
|
71 |
-
|
72 |
-
Use the code below to get started with the model.
|
73 |
-
|
74 |
-
[More Information Needed]
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
+
license: other
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
tags:
|
6 |
+
- histology
|
7 |
+
- pathology
|
8 |
+
- vision
|
9 |
+
- pytorch
|
10 |
+
- self-supervised
|
11 |
+
- vit
|
12 |
+
metrics:
|
13 |
+
- accuracy
|
14 |
+
- roc_auc
|
15 |
+
- f1
|
16 |
+
pipeline_tag: image-feature-extraction
|
17 |
library_name: transformers
|
|
|
18 |
---
|
19 |
|
|
|
20 |
|
21 |
+
# Model Card for Phikon-v2
|
22 |
|
23 |
+
Phikon-v2 is a Vision Transformer Large pre-trained with Dinov2 self-supervised method on PANCAN-XL, a dataset of 450M 20x magnification histology images sampled from 60K whole slide images.
|
24 |
+
PANCAN-XL only incorporates publicly available datasets: CPTAC (6,193 WSI) and TCGA (29,502 WSI) for malignant tissue, and gTEX for normal tissue (13,302 WSI).
|
25 |
|
26 |
+
Phikon-v2 improves upon [Phikon](https://huggingface.co/owkin/phikon), our previous fondation model pre-trained with iBOT on 40M histology images from TCGA (6k WSI), on a large variety of weakly-supervised tasks tailored for biomarker discovery.
|
27 |
+
Phikon-v2 is evaluated on external cohorts to avoid any data contamination with PANCAN-XL pre-training dataset, and benchmarked against an exhaustive panel of representation learning and foundation models.
|
28 |
|
29 |
+
## Model Description
|
30 |
|
31 |
+
- **Developed by:** Owkin, Inc
|
32 |
+
- **Model type:** Pretrained vision backbone (ViT-L/16 via DINOv2)
|
33 |
+
- **Pretraining dataset:** PANCAN-XL, sourced from public histology collections (TCGA, CPTAC, GTEx, TCIA and others).
|
34 |
+
- **Paper:** to be released
|
35 |
+
- **License:** [Owkin non-commercical licence](https://github.com/owkin/HistoSSLscaling/blob/main/README.md)
|
36 |
|
37 |
+
### How To Use (Feature Extraction)
|
38 |
|
39 |
+
The following code snippet allows you to extract features from histology images using Phikon-v2 (CLS token).
|
40 |
+
These features can then be used for downstream applications such as ROI classification (via linear or knn probing), slide classification (via multiple instance learning), segmentation (via ViT-Adapter for instance), etc.
|
41 |
|
42 |
+
```python
|
43 |
+
from PIL import Image
|
44 |
+
import torch
|
45 |
+
from transformers import AutoImageProcessor, AutoModel
|
|
|
|
|
|
|
46 |
|
|
|
47 |
|
48 |
+
# Load an image
|
49 |
+
image = Image.open(
|
50 |
+
requests.get(
|
51 |
+
"https://github.com/owkin/HistoSSLscaling/blob/main/assets/example.tif?raw=true",
|
52 |
+
stream=True
|
53 |
+
).raw
|
54 |
+
)
|
55 |
|
56 |
+
# Load phikon-v2
|
57 |
+
processor = AutoImageProcessor.from_pretrained("owkin/phikon-v2")
|
58 |
+
model = AutoModel.from_pretrained("owkin/phikon-v2")
|
59 |
+
model.eval()
|
60 |
|
61 |
+
# Process the image
|
62 |
+
inputs = processor(image, return_tensors="pt")
|
63 |
|
64 |
+
# Get the features
|
65 |
+
with torch.inference_mode():
|
66 |
+
outputs = model(**inputs)
|
67 |
+
features = outputs.last_hidden_state[:, 0, :] # (1, 1024) shape
|
68 |
|
69 |
+
assert features.shape == (1, 1024)
|
70 |
+
```
|
71 |
|
|
|
72 |
|
73 |
+
### Direct Use (with Pre-Extracted and Frozen Features)
|
74 |
|
75 |
+
Phikon-v2 can be used with or without fine-tuning on different downstream applications, on top of which slide-classification using multiple instance learning algorithms (such as ABMIL).
|
76 |
+
[This Colab notebook](https://colab.research.google.com/drive/1zjxscEBgpizHBCwMy-aNz2916AVdB642) allows you to fine-tune Phikon and Phikon-v2 using LoRa through the huggingface API.
|
77 |
|
78 |
+
### Downstream Use (Finetuning)
|
79 |
|
80 |
+
You can fine-tune the model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
## Training Details
|
83 |
|
84 |
+
- **Training data:** Mass-100K, a pretraining dataset (sourced from MGH, BWH, and GTEx) composed of 75,832,905 [256×256] and 24,297,995 [512×512] histology images at 20× resolution, sampled from 100,402 H&E WSIs (100,130,900 images in total).
|
85 |
+
- **Training regime:** fp16 using PyTorch-FSDP mixed-precision.
|
86 |
+
- **Training objective:** DINOv2 SSL recipe with the following losses:
|
87 |
+
- DINO self-distillation loss with multi-crop
|
88 |
+
- iBOT masked-image modeling loss
|
89 |
+
- KoLeo regularization on [CLS] tokens
|
90 |
+
- **Training length:** 125,000 iterations with a batch size of 3072
|
91 |
+
- **Model architecture:** ViT-Large (0.3B params): Patch size 16, embedding dimension 1024, 16 heads, MLP FFN
|
92 |
+
- **Hardware used:** 4x8 Nvidia A100 80GB
|
93 |
+
- **Hours trained:** Approx 1024 GPU hours (32 hours total)
|
94 |
+
- **Cloud provider:** MGB ERIS Research Computing Core
|
95 |
+
|
96 |
+
## Software Dependencies
|
97 |
+
|
98 |
+
**Python Packages**
|
99 |
+
- torch>=2.0: https://pytorch.org
|
100 |
+
- xformers>=0.0.18: https://github.com/facebookresearch/xformers
|
101 |
+
- timm>=0.9.8: https://github.com/huggingface/pytorch-image-models
|
102 |
+
|
103 |
+
**Repositories**
|
104 |
+
- DINOv2 (self-supervised learning): https://github.com/facebookresearch/dinov2
|
105 |
+
- CLAM (slide classification): https://github.com/mahmoodlab/CLAM
|
106 |
+
- Mask2Former (cell and tissue segmentation): https://github.com/facebookresearch/Mask2Former
|
107 |
+
- ViT-Adapter (cell and tissue segmentation): https://github.com/czczup/ViT-Adapter
|
108 |
+
- LGSSL (Linear Probe & Few-Shot Eval): https://github.com/mbanani/lgssl
|
109 |
+
|
110 |
+
## License and Terms of Use
|
111 |
+
This model and associated code are released under the CC-BY-NC-ND 4.0 license and may only be used for non-commercial, academic research purposes with proper attribution. Any commercial use, sale, or other monetization of the UNI model and its derivatives, which include models trained on outputs from the UNI model or datasets created from the UNI model, is prohibited and requires prior approval. Downloading the model requires prior registration on Hugging Face and agreeing to the terms of use. By downloading this model, you agree not to distribute, publish or reproduce a copy of the model. If another user within your organization wishes to use the UNI model, they must register as an individual user and agree to comply with the terms of use. Users may not attempt to re-identify the deidentified data used to develop the underlying model. If you are a commercial entity, please contact the corresponding author.
|
112 |
+
|
113 |
+
|
114 |
+
## Contact
|
115 |
+
For any additional questions or comments, contact Faisal Mahmood (`faisalmahmood@bwh.harvard.edu`),
|
116 |
+
Richard J. Chen (`richardchen@g.harvard.edu`),
|
117 |
+
Tong Ding (`tong_ding@g.harvard.edu`),
|
118 |
+
or Ming Y. Lu (`mlu16@bwh.harvard.edu`).
|
119 |
+
|
120 |
+
|
121 |
+
## Acknowledgements
|
122 |
+
The project was built on top of amazing repositories such as [ViT](https://github.com/google-research/big_vision), [DINOv2](https://github.com/facebookresearch/dinov2), [LGSSL](https://github.com/mbanani/lgssl), and [Timm](https://github.com/huggingface/pytorch-image-models/) (ViT model implementation). We thank the authors and developers for their contribution.
|
123 |
+
|
124 |
+
|
125 |
+
## BibTeX
|
126 |
+
If you found our work useful in your research, please consider citing our work at:
|
127 |
+
|
128 |
+
Chen, R.J., Ding, T., Lu, M.Y., Williamson, D.F.K., et al. Towards a general-purpose foundation model for computational pathology. Nat Med (2024). https://doi.org/10.1038/s41591-024-02857-3
|
129 |
+
|
130 |
+
```
|
131 |
+
@article{chen2024uni,
|
132 |
+
title={Towards a General-Purpose Foundation Model for Computational Pathology},
|
133 |
+
author={Chen, Richard J and Ding, Tong and Lu, Ming Y and Williamson, Drew FK and Jaume, Guillaume and Chen, Bowen and Zhang, Andrew and Shao, Daniel and Song, Andrew H and Shaban, Muhammad and others},
|
134 |
+
journal={Nature Medicine},
|
135 |
+
publisher={Nature Publishing Group},
|
136 |
+
year={2024}
|
137 |
+
}
|
138 |
+
```
|
139 |
+
Works that use UNI should also attribute ViT and DINOv2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|