CXformer is a vision transformer tailored for chest X-ray analysis, adapted from DINOv2 with clinically motivated training modifications. This repository provides code for pretraining CXformer using our optimized pipeline, as well as scripts for finetuning on downstream tasks like classification, segmentation, and report generation.
For more details on pre-training, please checkout
our paper accepted at MIDL 2025.
CXformer was pretrained on publicly available datasets, focusing on frontal views of chest X-rays (PA/AP):
The official training splits were used for CheXpert, MIMIC and NIH, and all available samples in BRAX and PadChest were used in pretraining.
1from transformers import AutoModel, AutoImageProcessor
2from PIL import Image
3
4model_name = "m42-health/CXformer-base"
5
6image_processor = AutoImageProcessor.from_pretrained(model_name,trust_remote_code=True)
7model = AutoModel.from_pretrained(model_name)
8
9model.eval()
10
11image = Image.open('sample_cxr.png')
12
13image = image_processor(image, return_tensors='pt')
14print(image['pixel_values'].shape) # [1,3,518,518]
15
16print("Doing forwardpass...")
17output = model(**image).last_hidden_state # [1, 1374, 768]
18
1@inproceedings{al2025empirical,
2 title={Empirical Analysis of Scaling Vision Foundation Models for Chest X-rays},
3 author={Al Mahrooqi, Ahmed and Munjal, Prateek and Rajan, Ronnie and Pimentel, Marco AF and Kanithi, Praveenkumar},
4 booktitle={Medical Imaging with Deep Learning},
5 year={2025}
6}