Run this model with HF Jobs
Run 1aurent/samvit_base_patch16_1024.pathosam on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/1aurent/samvit_base_patch16_1024.pathosam. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/1aurent/samvit_base_patch16_1024.pathosam on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use 1aurent/samvit_base_patch16_1024.pathosam with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use 1aurent/samvit_base_patch16_1024.pathosam with timm:
import timm model = timm.create_model("hf-hub:1aurent/samvit_base_patch16_1024.pathosam", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Add samvit_base_patch16_1024.pathosam (timm re-upload of official PathoSAM SAM encoder; bit-identical, parity PASS)
Browse filesFiles changed (3)
- README.mdAdded+81
- config.jsonAdded+48
- model.safetensorsAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081---tags:- feature-extraction- timm- histology- pathology- segment-anything- sam- pathosamlibrary_name: timmlicense: mitpipeline_tag: feature-extractioninference: false---
# Model card for samvit_base_patch16_1024.pathosam
A Segment Anything Model (SAM) ViT-B/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_base_patch16)- **Developed by**: Computational Cell Analytics (Research Group of Prof. Dr. Constantin Pape), University of Göttingen- **Model Stats:** - Params: 89670912 (89.7M, image encoder only) - Image size: 1024 x 1024 x 3 - Patch size: 16 x 16 x 3 - Embedding dim: 768, depth: 12, heads: 12, window size: 14, global attention blocks: [2, 5, 8, 11] - Output features: 256 channels x 64 x 64 (neck output, num_features = 256)- **Training:** - Base: SAM ViT-B/16 (SA-1B) image encoder (micro-sam checkpoint vit_b_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```pythonfrom urllib.request import urlopenfrom PIL import Imageimport timm
# get example histology imageimg = Image.open( urlopen( "https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif" )).convert("RGB")
# load model from the hubmodel = timm.create_model( model_name="hf-hub:1aurent/samvit_base_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 tensoroutput = 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}, }```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748{ "architecture": "samvit_base_patch16", "num_classes": 0, "num_features": 256, "global_pool": "avg", "model_args": { "img_size": 1024, "patch_size": 16, "window_size": 14, "global_attn_indexes": [ 2, 5, 8, 11 ], "use_rel_pos": true, "num_classes": 0 }, "pretrained_cfg": { "tag": "pathosam", "custom_load": false, "input_size": [ 3, 1024, 1024 ], "fixed_input_size": true, "interpolation": "bilinear", "crop_pct": 1.0, "crop_mode": "center", "mean": [ 0.485, 0.456, 0.406 ], "std": [ 0.229, 0.224, 0.225 ], "num_classes": 0, "pool_size": null, "first_conv": "patch_embed.proj", "classifier": "head", "license": "mit", "hf_hub_id": "1aurent/samvit_base_patch16_1024.pathosam" }}123version https://git-lfs.github.com/spec/v1oid sha256:dc7f336015986321b591b0fbc0a557dfaebbf00bd5052d0ec8addb878f8dea5bsize 358700144README.mdAdded+81
config.jsonAdded+48
model.safetensorsAdded+3