Skip to main content

Vision encoder for chest X-rays.

Project description


license: other license_name: mit license_link: https://huggingface.co/microsoft/rad-dino/blob/main/LICENSE library_name: transformers pipeline_tag: image-feature-extraction

Model card for RAD-DINO

Model description

RAD-DINO is a vision transformer model trained to encode chest X-rays using the self-supervised learning method DINOv2.

RAD-DINO is described in detail in Exploring Scalable Medical Image Encoders Beyond Text Supervision (F. Pérez-García, H. Sharma, S. Bond-Taylor, et al., 2024).

  • Developed by: Microsoft Health Futures
  • Model type: Vision transformer
  • License: MIT
  • Finetuned from model: dinov2-base

Uses

RAD-DINO is shared for research purposes only. It is not meant to be used for clinical practice.

The model is a vision backbone that can be plugged to other models for downstream tasks. Some potential uses are:

  • Image classification, with a classifier trained on top of the CLS token
  • Image segmentation, with a decoder trained using the patch tokens
  • Clustering, using the image embeddings directly
  • Image retrieval, using nearest neighbors of the CLS token
  • Report generation, with a language model to decode text

Fine-tuning RAD-DINO is typically not necessary to obtain good performance in downstream tasks.

Biases, risks, and limitations

RAD-DINO was trained with data from three countries, therefore it might be biased towards population in the training data. Underlying biases of the training datasets may not be well characterized.

Installation

pip install rad-dino

Usage

Encode an image

>>> from rad_dino import RadDino
>>> from rad_dino.utils import download_sample_image
>>> encoder = RadDino()
>>> image = download_sample_image()
>>> image
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2765x2505 at 0x7CCD5C014050>
>>> cls_token, patch_tokens = encoder.extract_features(image)
>>> cls_embeddings.shape, patch_embeddings.shape
(torch.Size([1, 768]), torch.Size([1, 768, 37, 37]))

Weights for fine-tuning

We have released a checkpoint compatible with the original DINOv2 code to help researchers fine-tune our model.

We can use the hub model and load the RAD-DINO weights. Let's clone the DINOv2 repository so we can import the code for the head.

git clone https://github.com/facebookresearch/dinov2.git
>>> import torch
>>> from rad_dino.utils import safetensors_to_state_dict
>>> rad_dino_gh = torch.hub.load("./dinov2", "dinov2_vitb14")
>>> backbone_state_dict = safetensors_to_state_dict("backbone_compatible.safetensors")
>>> rad_dino_gh.load_state_dict(backbone_state_dict, strict=True)
<All keys matched successfully>

The weights of the head are also released:

>>> from dinov2.layers import DINOHead
>>> rad_dino_head_gh = DINOHead(
...    in_dim=768,
...    out_dim=65536,
...    hidden_dim=2048,
...    bottleneck_dim=256,
...    nlayers=3,
... )
>>> head_state_dict = safetensors_to_state_dict("dino_head.safetensors")
>>> rad_dino_head_gh.load_state_dict(head_state_dict, strict=True)
<All keys matched successfully>

Configs and augmentation

The configuration files ssl_default_config.yaml and vitb14_cxr.yaml, and the augmentations module are also available in the repository to help researchers reproduce the training procedure with our hyperparameters.

Training details

Training data

We used images from five public, deidentified chest X-ray datasets to train this checkpoint of RAD-DINO.

Dataset Num. images
MIMIC-CXR 368 960
CheXpert 223 648
NIH-CXR 112 120
PadChest 136 787
BRAX 41 260
TOTAL 882 775

Images in the validation and test sets used to train MAIRA were excluded from the training set of RAD-DINO. The list of image files used for training is available at ./training_images.csv.

Note this checkpoint is different from the one in the paper, where some private data was used (and fewer GPUs). The checkpoint shared here is trained for 35 000 iterations (the total number of iterations in the run was 100 000, but we selected this checkpoint using linear probing on the validation sets of the evaluation datasets described in the paper). We used 16 nodes with 4 A100 GPUs each, and a batch size of 40 images per GPU.

Training procedure

We refer to the manuscript for a detailed description of the training procedure.

Preprocessing

All DICOM files were resized using B-spline interpolation so that their shorter size was 518, min-max scaled to [0, 255], and stored as PNG files.

Training hyperparameters

  • Training regime: fp16 using PyTorch-FSDP mixed-precision.

Evaluation

Our evaluation is best described in the manuscript.

Environmental impact

  • Hardware type: NVIDIA A100 GPUs
  • Hours used: 40 hours/GPU × 16 nodes × 4 GPUs/node = 2560 GPU-hours
  • Cloud provider: Azure
  • Compute region: West US 2
  • Carbon emitted: 222 kg CO₂ eq.

Compute infrastructure

RAD-DINO was trained on Azure Machine Learning.

Hardware

We used 16 Standard_NC96ads_A100_v4 nodes with four NVIDIA A100 (80 GB) GPUs each.

Software

We leveraged the code in DINOv2 for training. We used SimpleITK and Pydicom for processing of DICOM files.

Citation

BibTeX:

@article{perez-garcia_exploring_2025,
 title = {Exploring scalable medical image encoders beyond text supervision},
 issn = {2522-5839},
 url = {https://doi.org/10.1038/s42256-024-00965-w},
 doi = {10.1038/s42256-024-00965-w},
 journal = {Nature Machine Intelligence},
 author = {P{\'e}rez-Garc{\'i}a, Fernando and Sharma, Harshita and Bond-Taylor, Sam and Bouzid, Kenza and Salvatelli, Valentina and Ilse, Maximilian and Bannur, Shruthi and Castro, Daniel C. and Schwaighofer, Anton and Lungren, Matthew P. and Wetscherek, Maria Teodora and Codella, Noel and Hyland, Stephanie L. and Alvarez-Valle, Javier and Oktay, Ozan},
 month = jan,
 year = {2025},
}

APA:

Pérez-García, F., Sharma, H., Bond-Taylor, S., Bouzid, K., Salvatelli, V., Ilse, M., Bannur, S., Castro, D. C., Schwaighofer, A., Lungren, M. P., Wetscherek, M. T., Codella, N., Hyland, S. L., Alvarez-Valle, J., & Oktay, O. (2025). Exploring scalable medical image encoders beyond text supervision. In Nature Machine Intelligence. Springer Science and Business Media LLC. https://doi.org/10.1038/s42256-024-00965-w

Model card contact

Fernando Pérez-García (fperezgarcia@microsoft.com).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rad_dino-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rad_dino-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file rad_dino-0.1.0.tar.gz.

File metadata

  • Download URL: rad_dino-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for rad_dino-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7c582cff2ea98c6bc681f2c8aeb6f08c5d5b76ac025288d5f64a6cb0afaa492
MD5 ee54a26a4f94631544e2e6813bfd21be
BLAKE2b-256 ef6f33efdfad03172d876d4b0f898c8b735406ff25b050b443fb6fb6d8ee2ba2

See more details on using hashes here.

File details

Details for the file rad_dino-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rad_dino-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for rad_dino-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da9fc02211b5e1c6165b90e10c484d878533036b8136be8de1c0aa6ca37c59a4
MD5 6934a6c5db067543eed946160a9953b6
BLAKE2b-256 2236a81e14093ae7b5b94b176d914205c5f07644b0d9ba00fef3290a05fe881f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page