Instructions to use 1aurent/samvit_large_patch16_1024.pathosam with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use 1aurent/samvit_large_patch16_1024.pathosam with timm:
import timm model = timm.create_model("hf-hub:1aurent/samvit_large_patch16_1024.pathosam", pretrained=True) - Notebooks
- Google Colab
- Kaggle
File size: 3,288 Bytes
1945c9f | 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 | ---
tags:
- feature-extraction
- timm
- histology
- pathology
- segment-anything
- sam
- pathosam
library_name: timm
license: mit
pipeline_tag: feature-extraction
inference: false
---
# Model card for samvit_large_patch16_1024.pathosam
A Segment Anything Model (SAM) ViT-L/16 image encoder, fine-tuned as part of PathoSAM on a diverse histopathology dataset for nucleus segmentation. This repo contains the image encoder only (no prompt encoder or mask decoder); call forward_features to obtain the SAM image embeddings of shape (batch_size, 256, 64, 64).
## Model Details
- **Model Type:** Feature backbone (SAM image encoder, timm samvit_large_patch16)
- **Developed by**: Computational Cell Analytics (Research Group of Prof. Dr. Constantin Pape), University of Göttingen
- **Model Stats:**
- Params: 308278272 (308.3M, image encoder only)
- Image size: 1024 x 1024 x 3
- Patch size: 16 x 16 x 3
- Embedding dim: 1024, depth: 24, heads: 16, window size: 14, global attention blocks: [5, 11, 17, 23]
- Output features: 256 channels x 64 x 64 (neck output, num_features = 256)
- **Training:**
- Base: SAM ViT-L/16 (SA-1B) image encoder (micro-sam checkpoint vit_l_histopathology), fine-tuned on histopathology nucleus segmentation data (PathoSAM)
- Framework: PyTorch / micro-sam
- **Papers:**
- [Segment Anything for Histopathology](https://arxiv.org/abs/2502.00408) (MIDL 2025)
- **Original:** https://github.com/computational-cell-analytics/patho-sam
- **License:** [MIT](https://github.com/computational-cell-analytics/patho-sam/blob/main/LICENSE)
## Model Usage
### Image Embeddings
```python
from urllib.request import urlopen
from PIL import Image
import timm
# get example histology image
img = Image.open(
urlopen(
"https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
)
).convert("RGB")
# load model from the hub
model = timm.create_model(
model_name="hf-hub:1aurent/samvit_large_patch16_1024.pathosam",
pretrained=True,
).eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
output = model(data) # output is a (batch_size, num_features) shaped tensor (avg-pooled neck features)
features = model.forward_features(data) # SAM image embeddings, shape (batch_size, 256, 64, 64)
```
**Preprocessing note:** PathoSAM / SAM consume 1024 x 1024 inputs normalized with the ImageNet mean/std. The exact SAM preprocessing resizes the longest side to 1024 (bilinear) and zero-pads to 1024 x 1024 (segment_anything.utils.transforms.ResizeLongestSide(1024) + zero-pad, see Sam.preprocess). The timm transform above resizes directly to 1024 x 1024; apply the resize-longest-side + zero-pad preprocessing manually for bit-exact SAM behavior.
## Citation
```bibtex
@misc{griebel2025segmenthistopathology,
title={Segment Anything for Histopathology},
author={Titus Griebel and Anwai Archit and Constantin Pape},
year={2025},
eprint={2502.00408},
archivePrefix={arXiv},
primaryClass={eess.IV},
url={https://arxiv.org/abs/2502.00408},
}
```
|