Model card for H0-mini
H0-mini is a lightweight foundation model for histology developed by Owkin and Bioptimus.
The model is a Vision Transformer Base/14 distilled from H-optimus-0 [1] (ViT-g/14) with DINOv2 [2] self-supervised distillation method on PanCancer40M, a set of 43 million histology tiles extracted from 6,093 histology slides of TCGA.
H0-mini achieves comparable performance to current histology foundation models at a significantly reduced inference cost. It also demonstrates strong robustness to variations in staining and scanning protocols. Please refer to the ArXiv preprint for additional details.
Figure: Assessment of model robustness to staining and scanning conditions in PLISM dataset [3] - Median top-10 accuracy vs. mean cosine similarity was computed for each extractor over 4,095 slide pairs. For both axes, higher values indicate more robust models.
How to use it to extract features.
H0-mini can be used with or without fine-tuning on different downstream applications, such as slide-level classification using multiple-instance learning algorithms (e.g. using ABMIL [4]).
The following code snippet allows you to extract features from histology images using H0-Mini.
We recommend to use the CLS token (cls_features) as input features for downstream tasks.
The concatenation of the CLS token features with the average of patch token features may bring some improvements on some tasks (concatenated_features).
from huggingface_hub import login
import torch
import timm
from timm.data import resolve_data_config
from timm.data.transforms_factory import create_transform
from torchvision import transforms
# Login to the Hugging Face hub, using your user access token that can be found here:
# https://huggingface.co/settings/tokens.
login()
model = timm.create_model(
"hf-hub:bioptimus/H0-mini",
pretrained=True,
mlp_layer=timm.layers.SwiGLUPacked,
act_layer=torch.nn.SiLU,
)
model.to("cuda")
model.eval()
transform = create_transform(**resolve_data_config(model.pretrained_cfg, model=model))
input = torch.rand(3, 224, 224)
input = transforms.ToPILImage()(input)
# We recommend using mixed precision for faster inference.
with torch.autocast(device_type="cuda", dtype=torch.float16):
with torch.inference_mode():
output = model(transform(input).unsqueeze(0).to("cuda")) # (1, 261, 768)
# CLS token features (1, 768):
cls_features = output[:, 0]
# Patch token features (1, 256, 768):
patch_token_features = output[:, model.num_prefix_tokens :]
# Concatenate the CLS token features with the mean of the patch token
# features (1, 1536):
concatenated_features = torch.cat(
[cls_features, patch_token_features.mean(1)], dim=-1
)
assert cls_features.shape == (1, 768)
assert patch_token_features.shape == (1, 256, 768)
assert concatenated_features.shape == (1, 1536)
These features can then be used for downstream applications such as ROI classification (via linear or k-NN probing), slide classification (via multiple instance learning), segmentation (via ViT-Adapter for instance), etc.
Pre-training dataset tiles coordinates.
Tiles coordinates of the pre-training dataset are available here as one .txt file per indication. For a given .txt file, the structure is the following:
cohort_1/slide_id_1.svs:
tile_z_x1_y1_slide_id_1.svs.png
tile_z_x2_y2_slide_id_1.svs.png
…
cohort_N/slide_id_S.svs:
tile_z_x1_y1_slide_id_2.svs.png
tile_z_x2_y2_slide_id_2.svs.png
Where z, x, y represent the deepzoom level, x coordinate at z-level and y coordinate at z-level of the tile, respectively.
For example:
TCGA_COAD/TCGA-3L-AA1B-01Z-00-DX1.8923A151-A690-40B7-9E5A-FCBEDFC2394F.svs:
tile_16_100_105_TCGA-3L-AA1B-01Z-00-DX1.8923A151-A690-40B7-9E5A-FCBEDFC2394F.svs.png
tile_16_100_106_TCGA-3L-AA1B-01Z-00-DX1.8923A151-A690-40B7-9E5A-FCBEDFC2394F.svs.png
…
Software Dependencies.
- torch>==2.0.0: https://pytorch.org
- torchvision>=0.15.0: https://pytorch.org/vision/stable/index.html
- xformers>=0.0.18: https://github.com/facebookresearch/xformers
Citation.
If you are using this model, please cite our work:
@misc{filiot2025distillingfoundationmodelsrobust,
title={Distilling foundation models for robust and efficient models in digital pathology},
author={Alexandre Filiot and Nicolas Dop and Oussama Tchita and Auriane Riou and Thomas Peeters and Daria Valter and Marin Scalbert and Charlie Saillard and Geneviève Robin and Antoine Olivier},
year={2025},
eprint={2501.16239},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2501.16239},
}
Acknowledgements.
Computing resources.
This work was granted access to the High-Performance Computing (HPC) resources of IDRIS under the allocations 2023-A0141012519, 2024-A0161012519 and 2024-GC011015442 made by GENCI.
Code.
H0-mini was built upon DINOv2 repository (Apache License 2.0).
Datasets.
The results published here are partly based upon data generated by the TCGA Research Network: https://www.cancer.gov/tcga.
References
- Saillard, C., Jenatton, R., Llinares-López, F., Mariet, Z., Cahané, D., Durand, E., Vert, J.-P., 2024. H-optimus-0.
- Oquab, M., Darcet, T., Moutakanni, T., Vo, H., Szafraniec, M., Khalidov, V., ... & Bojanowski, P. (2023). Dinov2: Learning robust visual features without supervision. arXiv preprint arXiv:2304.07193.
- Ochi, M., Komura, D., Onoyama, T., Shinbo, K., Endo, H., Odaka, H., ... & Ishikawa, S. (2024). Registered multi-device/staining histology image dataset for domain-agnostic machine learning models. Scientific Data, 11(1), 330.
- Ilse, M., Tomczak, J., & Welling, M. (2018, July). Attention-based deep multiple instance learning. In International conference on machine learning (pp. 2127-2136). PMLR.