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
Add samvit_large_patch16_1024.pathosam (timm re-upload of official PathoSAM SAM encoder; bit-identical, parity PASS)
Browse files- README.md +81 -0
- config.json +48 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- feature-extraction
|
| 4 |
+
- timm
|
| 5 |
+
- histology
|
| 6 |
+
- pathology
|
| 7 |
+
- segment-anything
|
| 8 |
+
- sam
|
| 9 |
+
- pathosam
|
| 10 |
+
library_name: timm
|
| 11 |
+
license: mit
|
| 12 |
+
pipeline_tag: feature-extraction
|
| 13 |
+
inference: false
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Model card for samvit_large_patch16_1024.pathosam
|
| 17 |
+
|
| 18 |
+
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).
|
| 19 |
+
|
| 20 |
+
## Model Details
|
| 21 |
+
|
| 22 |
+
- **Model Type:** Feature backbone (SAM image encoder, timm samvit_large_patch16)
|
| 23 |
+
- **Developed by**: Computational Cell Analytics (Research Group of Prof. Dr. Constantin Pape), University of Göttingen
|
| 24 |
+
- **Model Stats:**
|
| 25 |
+
- Params: 308278272 (308.3M, image encoder only)
|
| 26 |
+
- Image size: 1024 x 1024 x 3
|
| 27 |
+
- Patch size: 16 x 16 x 3
|
| 28 |
+
- Embedding dim: 1024, depth: 24, heads: 16, window size: 14, global attention blocks: [5, 11, 17, 23]
|
| 29 |
+
- Output features: 256 channels x 64 x 64 (neck output, num_features = 256)
|
| 30 |
+
- **Training:**
|
| 31 |
+
- Base: SAM ViT-L/16 (SA-1B) image encoder (micro-sam checkpoint vit_l_histopathology), fine-tuned on histopathology nucleus segmentation data (PathoSAM)
|
| 32 |
+
- Framework: PyTorch / micro-sam
|
| 33 |
+
- **Papers:**
|
| 34 |
+
- [Segment Anything for Histopathology](https://arxiv.org/abs/2502.00408) (MIDL 2025)
|
| 35 |
+
- **Original:** https://github.com/computational-cell-analytics/patho-sam
|
| 36 |
+
- **License:** [MIT](https://github.com/computational-cell-analytics/patho-sam/blob/main/LICENSE)
|
| 37 |
+
|
| 38 |
+
## Model Usage
|
| 39 |
+
|
| 40 |
+
### Image Embeddings
|
| 41 |
+
```python
|
| 42 |
+
from urllib.request import urlopen
|
| 43 |
+
from PIL import Image
|
| 44 |
+
import timm
|
| 45 |
+
|
| 46 |
+
# get example histology image
|
| 47 |
+
img = Image.open(
|
| 48 |
+
urlopen(
|
| 49 |
+
"https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
|
| 50 |
+
)
|
| 51 |
+
).convert("RGB")
|
| 52 |
+
|
| 53 |
+
# load model from the hub
|
| 54 |
+
model = timm.create_model(
|
| 55 |
+
model_name="hf-hub:1aurent/samvit_large_patch16_1024.pathosam",
|
| 56 |
+
pretrained=True,
|
| 57 |
+
).eval()
|
| 58 |
+
|
| 59 |
+
# get model specific transforms (normalization, resize)
|
| 60 |
+
data_config = timm.data.resolve_model_data_config(model)
|
| 61 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
| 62 |
+
|
| 63 |
+
data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
|
| 64 |
+
output = model(data) # output is a (batch_size, num_features) shaped tensor (avg-pooled neck features)
|
| 65 |
+
features = model.forward_features(data) # SAM image embeddings, shape (batch_size, 256, 64, 64)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
**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.
|
| 69 |
+
|
| 70 |
+
## Citation
|
| 71 |
+
```bibtex
|
| 72 |
+
@misc{griebel2025segmenthistopathology,
|
| 73 |
+
title={Segment Anything for Histopathology},
|
| 74 |
+
author={Titus Griebel and Anwai Archit and Constantin Pape},
|
| 75 |
+
year={2025},
|
| 76 |
+
eprint={2502.00408},
|
| 77 |
+
archivePrefix={arXiv},
|
| 78 |
+
primaryClass={eess.IV},
|
| 79 |
+
url={https://arxiv.org/abs/2502.00408},
|
| 80 |
+
}
|
| 81 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": "samvit_large_patch16",
|
| 3 |
+
"num_classes": 0,
|
| 4 |
+
"num_features": 256,
|
| 5 |
+
"global_pool": "avg",
|
| 6 |
+
"model_args": {
|
| 7 |
+
"img_size": 1024,
|
| 8 |
+
"patch_size": 16,
|
| 9 |
+
"window_size": 14,
|
| 10 |
+
"global_attn_indexes": [
|
| 11 |
+
5,
|
| 12 |
+
11,
|
| 13 |
+
17,
|
| 14 |
+
23
|
| 15 |
+
],
|
| 16 |
+
"use_rel_pos": true,
|
| 17 |
+
"num_classes": 0
|
| 18 |
+
},
|
| 19 |
+
"pretrained_cfg": {
|
| 20 |
+
"tag": "pathosam",
|
| 21 |
+
"custom_load": false,
|
| 22 |
+
"input_size": [
|
| 23 |
+
3,
|
| 24 |
+
1024,
|
| 25 |
+
1024
|
| 26 |
+
],
|
| 27 |
+
"fixed_input_size": true,
|
| 28 |
+
"interpolation": "bilinear",
|
| 29 |
+
"crop_pct": 1.0,
|
| 30 |
+
"crop_mode": "center",
|
| 31 |
+
"mean": [
|
| 32 |
+
0.485,
|
| 33 |
+
0.456,
|
| 34 |
+
0.406
|
| 35 |
+
],
|
| 36 |
+
"std": [
|
| 37 |
+
0.229,
|
| 38 |
+
0.224,
|
| 39 |
+
0.225
|
| 40 |
+
],
|
| 41 |
+
"num_classes": 0,
|
| 42 |
+
"pool_size": null,
|
| 43 |
+
"first_conv": "patch_embed.proj",
|
| 44 |
+
"classifier": "head",
|
| 45 |
+
"license": "mit",
|
| 46 |
+
"hf_hub_id": "1aurent/samvit_large_patch16_1024.pathosam"
|
| 47 |
+
}
|
| 48 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a3f875535ff40b104a0a2dca85d6e3e7f1cf16156e847a835c999f5c3c3d8b0
|
| 3 |
+
size 1233145976
|