Model card for samvit_huge_patch16_1024.pathosam

A Segment Anything Model (SAM) ViT-H/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_huge_patch16)
  • Developed by: Computational Cell Analytics (Research Group of Prof. Dr. Constantin Pape), University of Göttingen
  • Model Stats:
    • Params: 637026048 (637.0M, image encoder only)
    • Image size: 1024 x 1024 x 3
    • Patch size: 16 x 16 x 3
    • Embedding dim: 1280, depth: 32, heads: 16, window size: 14, global attention blocks: [7, 15, 23, 31]
    • Output features: 256 channels x 64 x 64 (neck output, num_features = 256)
  • Training:
    • Base: SAM ViT-H/16 (SA-1B) image encoder (micro-sam checkpoint vit_h_histopathology), fine-tuned on histopathology nucleus segmentation data (PathoSAM)
    • Framework: PyTorch / micro-sam
  • Papers:
  • 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_huge_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
-
Safetensors
Model size
0.6B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including 1aurent/samvit_huge_patch16_1024.pathosam

Paper for 1aurent/samvit_huge_patch16_1024.pathosam