Registry / ai-ml / torchxrayvision

torchxrayvision

JSON →
library1.4.0pypypi✓ verified 85d ago

A library for chest X-ray datasets and pretrained models in PyTorch. Version 1.4.0 released Sept 2024. Provides easy access to common datasets (ChestX-ray14, CheXpert, MIMIC-CXR, PadChest, etc.) and pre-trained models for classification, segmentation, and representation learning.

pip install torchxrayvision
INSTALL
IMPORT
SIG · TORCHXRAYVISION
T
torchxrayvision
ai-mlpythonv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

torchxrayvision
import torchxrayvision as xrv
import xrv
Wrong because xrv is not a top-level module; torchxrayvision is the correct package name but the library often used with alias xrv.
datasets
from torchxrayvision import datasets
import torchxrayvision.datasets as datasets or from torchxrayvision.datasets import ...
datasets is a submodule within torchxrayvision, but the common pattern is to use xrv.datasets after import torchxrayvision as xrv.
models
from torchxrayvision import models

Load a pretrained DenseNet on CheXpert labels, create a PadChest dataset, and run inference on a single image.

import torchxrayvision as xrv # Load a pretrained model model = xrv.models.DenseNet(weights='densenet121-res224-chex') dataset = xrv.datasets.PC_Dataset( imgpath='images', csvpath='labels.csv', views=['PA'] ) # Process an image import skimage.io img = skimage.io.imread('image.png') img = xrv.datasets.normalize(img, 255) # Run inference with torch.no_grad(): outputs = model(img.unsqueeze(0))
Debug
Known issues
breakingIn version 1.3.2, automatic upsampling was changed to use interpolate instead of skimage's resize, which may affect reproducibility for models expecting the old preprocessing.
fix
If you need the old behavior, manually apply skimage.transform.resize before passing images to models.
affects: >=1.3.2
gotchaThe dataset classes download large files (e.g., CheXpert is ~300GB). Ensure you have sufficient disk space and a stable internet connection.
fix
Use the download=False flag and manually place data in the expected location.
affects: all
gotchaModel weights are automatically downloaded to ~/.cache/torchxrayvision/ by default. This may fill up disk space over time.
fix
Set the environment variable XRV_DATA_DIR or use the cache_dir parameter to redirect.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'torchxrayvision'
Package not installed or installed in wrong environment.
fix
Run 'pip install torchxrayvision' in the correct Python environment.
ValueError: unknown url: .../chexpert/CheXpert-v1.0-small.zip
The dataset URL has changed or the download link is broken. The remote server may be offline.
fix
Download the dataset manually from the original source and place it in the expected directory, then pass download=False.
RuntimeError: Image must be a numpy array or PyTorch tensor
Input image is of an unsupported type (e.g., PIL Image).
fix
Convert input to a numpy array using np.array(img) or use torch.from_numpy().
Upgrade
Version history
1.4.0latest on PyPI · released Sep 18, 2025
Audit
Dependencies
torchrequiredCore dependency for tensor operations and model inference
torchvisionrequiredUsed for transforms and dataset utilities
numpyrequiredImage array manipulation
skimagerequiredImage preprocessing (resize etc.)
pydicomoptionalDICOM file handling (optional, needed for some datasets)
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
torchxrayvision — pip install torchxrayvision · libregistry