skillfed

torchxrayvision

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

torchxrayvision v1.5.2 78.7K downloads/30d#14,417 on PyPI1,183
Permissive license Active released

What it is and what it does

TorchXRayVision is a PyTorch-based library for working with chest X-ray datasets and pre-trained deep learning models. It addresses two core problems in medical imaging research: avoiding redundant model training by providing models trained on large clinical cohorts, and standardizing dataset access so researchers can swap between multiple public chest X-ray datasets with a single line of code. The library includes DenseNet and ResNet models trained on datasets like NIH ChestX-ray8, CheXpert, MIMIC-CXR, and others, capable of detecting pathologies such as pneumonia, atelectasis, consolidation, and fractures.

The package wraps torch, torchvision, scikit-image, and image I/O libraries to provide dataset loaders, image preprocessing (normalization, cropping, resizing), and model inference. It also includes autoencoders for representation learning and segmentation models for anatomical landmark detection. Researchers can use pre-trained weights as baselines for rapid analysis or as feature extractors for few-shot learning tasks.

Use it for:

  • Rapidly screen large cohorts of chest X-rays for pathology detection using pre-trained models without training from scratch
  • Extract learned features from X-ray images for downstream machine learning tasks or few-shot learning scenarios
  • Evaluate and compare new algorithms across multiple public chest X-ray datasets in a standardized way
  • Build anatomical segmentation pipelines to identify specific chest structures for clinical analysis
  • Prototype medical imaging research without managing dataset preprocessing and model weight distribution

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

TorchXRayVision provides pre-trained deep learning models and unified dataset interfaces for chest X-ray analysis, enabling rapid classification and feature extraction on medical imaging data.

Yes. The package is actively maintained, has low install friction, carries permissive licensing, and directly solves a real problem in medical imaging research—standardizing access to multiple chest X-ray datasets and providing production-ready pre-trained models. It is well-suited for researchers and practitioners working with chest radiographs who want to avoid redundant model training and dataset engineering.

Install

torchxrayvision on PyPI

pip

pip install torchxrayvision

uv

uv add torchxrayvision

poetry

poetry add torchxrayvision

Installing torchxrayvision

Before you install

Low friction install via wheel distribution. Active maintenance with recent release (47 days ago) and steady repository activity. Depends on torch, torchvision, and standard scientific Python stack (numpy, pandas, scikit-image, pillow, imageio), all widely available.

License in practice

Permissive Apache license allows commercial and private use without restriction, making it suitable for both research and production medical imaging applications.

Quickstart

pip install torchxrayvision

import torchxrayvision as xrv
import torch, torchvision, skimage.io

img = skimage.io.imread("xray.jpg")
img = xrv.datasets.normalize(img, 255)
img = img.mean(2)[None, ...]
transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop(), xrv.datasets.XRayResizer(224)])
img = transform(img)
img = torch.from_numpy(img)

model = xrv.models.DenseNet(weights="densenet121-res224-all")
outputs = model(img[None,...])

Verify before relying

  • Whether pre-trained model weights are automatically downloaded on first use or require manual setup
  • Memory and compute requirements for inference on typical hardware
  • Performance benchmarks against other medical imaging frameworks

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.6)
Install friction low — pure-Python wheel
Runtime dependencies 9 — torch, torchvision, scikit-image, tqdm, numpy, pandas, requests, pillow, imageio
Maintenance actively maintained — 47 days since the last release
Last repo commit
First released
Downloads 78,708/month — #14,417 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: torchxrayvision-1.5.2-py3-none-any.whl

License :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Scientific/Engineering :: Medical Science Apps.

Tags

chest x-ray deep learningmedical image classification pytorchpretrained radiology modelsx-ray dataset loaderchest pathology detectionmedical imaging feature extractionradiograph analysis models
medical-imagingdeep-learningradiology

More Medical Science Apps. packages