File size: 6,783 Bytes
3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc 3e8e849 ceb92bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 136 137 138 139 |
---
license: other
language:
- en
tags:
- histology
- pathology
- vision
- pytorch
- self-supervised
- vit
metrics:
- accuracy
- roc_auc
- f1
pipeline_tag: image-feature-extraction
library_name: transformers
---
# Model Card for Phikon-v2
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.
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).
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.
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.
## Model Description
- **Developed by:** Owkin, Inc
- **Model type:** Pretrained vision backbone (ViT-L/16 via DINOv2)
- **Pretraining dataset:** PANCAN-XL, sourced from public histology collections (TCGA, CPTAC, GTEx, TCIA and others).
- **Paper:** to be released
- **License:** [Owkin non-commercical licence](https://github.com/owkin/HistoSSLscaling/blob/main/README.md)
### How To Use (Feature Extraction)
The following code snippet allows you to extract features from histology images using Phikon-v2 (CLS token).
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.
```python
from PIL import Image
import torch
from transformers import AutoImageProcessor, AutoModel
# Load an image
image = Image.open(
requests.get(
"https://github.com/owkin/HistoSSLscaling/blob/main/assets/example.tif?raw=true",
stream=True
).raw
)
# Load phikon-v2
processor = AutoImageProcessor.from_pretrained("owkin/phikon-v2")
model = AutoModel.from_pretrained("owkin/phikon-v2")
model.eval()
# Process the image
inputs = processor(image, return_tensors="pt")
# Get the features
with torch.inference_mode():
outputs = model(**inputs)
features = outputs.last_hidden_state[:, 0, :] # (1, 1024) shape
assert features.shape == (1, 1024)
```
### Direct Use (with Pre-Extracted and Frozen Features)
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).
[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.
### Downstream Use (Finetuning)
You can fine-tune the model
## Training Details
- **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).
- **Training regime:** fp16 using PyTorch-FSDP mixed-precision.
- **Training objective:** DINOv2 SSL recipe with the following losses:
- DINO self-distillation loss with multi-crop
- iBOT masked-image modeling loss
- KoLeo regularization on [CLS] tokens
- **Training length:** 125,000 iterations with a batch size of 3072
- **Model architecture:** ViT-Large (0.3B params): Patch size 16, embedding dimension 1024, 16 heads, MLP FFN
- **Hardware used:** 4x8 Nvidia A100 80GB
- **Hours trained:** Approx 1024 GPU hours (32 hours total)
- **Cloud provider:** MGB ERIS Research Computing Core
## Software Dependencies
**Python Packages**
- torch>=2.0: https://pytorch.org
- xformers>=0.0.18: https://github.com/facebookresearch/xformers
- timm>=0.9.8: https://github.com/huggingface/pytorch-image-models
**Repositories**
- DINOv2 (self-supervised learning): https://github.com/facebookresearch/dinov2
- CLAM (slide classification): https://github.com/mahmoodlab/CLAM
- Mask2Former (cell and tissue segmentation): https://github.com/facebookresearch/Mask2Former
- ViT-Adapter (cell and tissue segmentation): https://github.com/czczup/ViT-Adapter
- LGSSL (Linear Probe & Few-Shot Eval): https://github.com/mbanani/lgssl
## License and Terms of Use
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.
## Contact
For any additional questions or comments, contact Faisal Mahmood (`[email protected]`),
Richard J. Chen (`[email protected]`),
Tong Ding (`[email protected]`),
or Ming Y. Lu (`[email protected]`).
## Acknowledgements
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.
## BibTeX
If you found our work useful in your research, please consider citing our work at:
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
```
@article{chen2024uni,
title={Towards a General-Purpose Foundation Model for Computational Pathology},
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},
journal={Nature Medicine},
publisher={Nature Publishing Group},
year={2024}
}
```
Works that use UNI should also attribute ViT and DINOv2. |