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))
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'torchxrayvision'
Package not installed or installed in wrong environment.
fixRun '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.
fixDownload 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).
fixConvert 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)