NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

TorchXRayVision: A library of chest X-ray datasets and models

Joseph Paul Cohen, Joseph D Viviano, Paul Bertin, Paul Morrison, Parsa Torabian, Matteo Guarrera, Matthew P. Lungren, Akshay Chaudhari, Rupert Brooks, Mohammad Hashir, Hadrien Bertrand

Abstract

TorchXRayVision is an open source software library for working with chest X-ray datasets and deep learning models. It provides a common interface and common pre-processing chain for a wide set of publicly available chest X-ray datasets. In addition, a number of classification and representation learning models with different architectures, trained on different data combinations, are available through the library to serve as baselines or feature extractors.

Introduction

Chest X-rays are the most common medical imaging test globally, and the deep learning community has access to a massive amount of open X-ray data. However, despite this abundance, comparing models across different datasets is notoriously difficult. Tiny differences in how a dataset is organized, how images are pre-processed, or how training procedures are set up can drastically skew results.

Because of these inconsistencies, researchers waste countless hours re-implementing standard dataloaders and struggling to establish meaningful baselines. TorchXRayVision addresses this gap by providing a unified, plug-and-play software infrastructure for reproducible chest X-ray research, allowing practitioners to swap out datasets and models with a single line of code.

System Design and Methods

Built on PyTorch and modeled after the familiar torchvision API, TorchXRayVision takes an object-oriented approach to medical ML experiments. Key features include:

  • Standardized Pre-processing: The library scales image pixels to a standard range [-1024, 1024] based on the possible range of the image's bit-depth (e.g., 16-bit), rather than the min/max of the specific image. This prevents arbitrary contrast adjustments that could destroy clinical information.
  • Core & Baseline Classifiers: It provides pre-trained models (like DenseNet121 and ResNet50) trained on massive combinations of datasets to predict up to 18 different pathologies. It also includes official baseline models from other research groups (e.g., Stanford's CheXpert).
  • Feature Extraction & Autoencoders: Models can be used out-of-the-box for classification, as feature extractors for transfer learning (model.features), or as autoencoders to generate fixed latent representations.
  • Dataset Utilities: Built-in tools allow users to easily merge datasets, filter by view (e.g., PA vs. AP), ensure only one image per patient is used, and extract pathology/semantic segmentation masks.

Dataset Integration

The library integrates an impressive roster of public datasets, standardizing their metadata and labels into a common format. Combined, these datasets offer access to hundreds of thousands of images and over 728,000 positive pathology labels across 18 standardized categories.

Summary of datasets integrated into TorchXRayVision, showing image counts and geographic regions.

By mapping disparate dataset labels to a common set of 18 pathologies, the library allows models to be trained and evaluated across multiple hospital systems seamlessly. If a dataset doesn't track a specific pathology, the library intelligently handles it by returning a NaN label.

Feature Representation and Baselines

A primary utility of TorchXRayVision is providing immediate, strong baselines for any new chest X-ray architecture. Researchers can instantly download weights (e.g., densenet121-res224-all) trained on amalgamations of these datasets.

t-SNE visualization of latent features from XRV-DenseNet121 and CheXpert-DenseNet121 models, demonstrating pathology clustering.

As shown in the feature visualizations above, the library's models can effectively cluster different pathologies in a latent space, serving as powerful feature extractors for downstream tasks. Furthermore, the library includes a CovariateDataset tool to intentionally introduce covariate shifts. This allows researchers to rigorously test how models fail when they rely on spurious shortcuts (like hospital-specific scanner artifacts) rather than actual medical signals.

Discussion and Future Work

The authors acknowledge that because the library merges disparate datasets, not all datasets contain labels for all 18 pathologies. Users must ensure their loss functions and evaluation metrics can gracefully handle the resulting NaN values. Additionally, while the library standardizes views (PA, AP, AP Supine), non-standardized views may still exist in the raw data and require careful filtering.

Looking forward, the authors envision the community using this infrastructure to build better multi-modal models, rigorously study out-of-distribution generalization, and develop mitigation strategies for the clinical deployment shifts that currently plague medical AI.

Summary updated

BibTeX
@inproceedings{cohen2022torchxrayvision,
  author = {Joseph Paul Cohen and Joseph D Viviano and Paul Bertin and Paul Morrison and Parsa Torabian and Matteo Guarrera and Matthew P. Lungren and Akshay Chaudhari and Rupert Brooks and Mohammad Hashir and Hadrien Bertrand},
  title = {{TorchXRayVision: A library of chest X-ray datasets and models}},
  booktitle = {MIDL},
  year = {2022},
  url = {https://openreview.net/forum?id=_5iri84DJmE},
}
Figure