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
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 (MIDL 2025)
- Original: https://github.com/computational-cell-analytics/patho-sam
- License: MIT
Model Usage
Image Embeddings
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
@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},
}
- Downloads last month
- -