torchxrayvision
TorchXRayVision: A library of chest X-ray datasets and models
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 torchxrayvisionuv
uv add torchxrayvisionpoetry
poetry add torchxrayvisionInstalling 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
Tags
More Medical Science Apps. packages
Client library for the Firecrawl API that…
permissive · top 5,000 on PyPI
pydicomPydicom reads, modifies, and writes DICOM…
permissive · top 5,000 on PyPI
PubChemPyPubChemPy is a Python wrapper around the…
permissive · top 5,000 on PyPI
vtkVTK is a 3D graphics, image processing, and…
permissive · top 5,000 on PyPI
pyhmmerPyHMMER provides Python bindings to HMMER3, a…
permissive · top 5,000 on PyPI
firecrawlA Python SDK for web scraping, crawling,…
permissive · top 5,000 on PyPI
torchgeoTorchGeo provides PyTorch datasets, samplers,…
permissive · top 15,000 on PyPI
torchvisionTorchvision provides pre-built datasets, model…
permissive · top 1,000 on PyPI
efficientnet-pytorchLoads and runs pretrained EfficientNet image…
permissive · top 15,000 on PyPI
timmTimm provides a large collection of pretrained…
permissive · top 5,000 on PyPI
pytorchcvProvides a collection of pretrained computer…
unclear · top 15,000 on PyPI
segmentation-models-pytorchProvides PyTorch-based neural network models…
permissive · top 15,000 on PyPI
TotalSegmentatorAutomated segmentation of anatomical structures…
permissive · top 15,000 on PyPI
monaiMONAI is a PyTorch-based framework for building…
permissive · top 15,000 on PyPI
torchtexttorchtext provides text datasets, preprocessing…
permissive · top 15,000 on PyPI
hl7Parses HL7 version 2.x medical messages into…
permissive · top 15,000 on PyPI