{"id":28403,"library":"torchxrayvision","title":"TorchXRayVision","description":"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.","status":"active","version":"1.4.0","language":"python","source_language":"en","source_url":"https://github.com/mlmed/torchxrayvision","tags":["chest-xray","medical-imaging","pytorch","pretrained-models","datasets"],"install":[{"cmd":"pip install torchxrayvision","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core dependency for tensor operations and model inference","package":"torch","optional":false},{"reason":"Used for transforms and dataset utilities","package":"torchvision","optional":false},{"reason":"Image array manipulation","package":"numpy","optional":false},{"reason":"Image preprocessing (resize etc.)","package":"skimage","optional":false},{"reason":"DICOM file handling (optional, needed for some datasets)","package":"pydicom","optional":true}],"imports":[{"note":"Wrong because xrv is not a top-level module; torchxrayvision is the correct package name but the library often used with alias xrv.","wrong":"import xrv","symbol":"torchxrayvision","correct":"import torchxrayvision as xrv"},{"note":"datasets is a submodule within torchxrayvision, but the common pattern is to use xrv.datasets after import torchxrayvision as xrv.","wrong":"import torchxrayvision.datasets as datasets or from torchxrayvision.datasets import ...","symbol":"datasets","correct":"from torchxrayvision import datasets"},{"note":"","wrong":"","symbol":"models","correct":"from torchxrayvision import models"}],"quickstart":{"code":"import torchxrayvision as xrv\n\n# Load a pretrained model\nmodel = xrv.models.DenseNet(weights='densenet121-res224-chex')\n\ndataset = xrv.datasets.PC_Dataset(\n    imgpath='images',\n    csvpath='labels.csv',\n    views=['PA']\n)\n\n# Process an image\nimport skimage.io\nimg = skimage.io.imread('image.png')\nimg = xrv.datasets.normalize(img, 255)\n\n# Run inference\nwith torch.no_grad():\n    outputs = model(img.unsqueeze(0))","lang":"python","description":"Load a pretrained DenseNet on CheXpert labels, create a PadChest dataset, and run inference on a single image."},"warnings":[{"fix":"If you need the old behavior, manually apply skimage.transform.resize before passing images to models.","message":"In 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.","severity":"breaking","affected_versions":">=1.3.2"},{"fix":"Use the download=False flag and manually place data in the expected location.","message":"The dataset classes download large files (e.g., CheXpert is ~300GB). Ensure you have sufficient disk space and a stable internet connection.","severity":"gotcha","affected_versions":"all"},{"fix":"Set the environment variable XRV_DATA_DIR or use the cache_dir parameter to redirect.","message":"Model weights are automatically downloaded to ~/.cache/torchxrayvision/ by default. This may fill up disk space over time.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run 'pip install torchxrayvision' in the correct Python environment.","cause":"Package not installed or installed in wrong environment.","error":"ModuleNotFoundError: No module named 'torchxrayvision'"},{"fix":"Download the dataset manually from the original source and place it in the expected directory, then pass download=False.","cause":"The dataset URL has changed or the download link is broken. The remote server may be offline.","error":"ValueError: unknown url: .../chexpert/CheXpert-v1.0-small.zip"},{"fix":"Convert input to a numpy array using np.array(img) or use torch.from_numpy().","cause":"Input image is of an unsupported type (e.g., PIL Image).","error":"RuntimeError: Image must be a numpy array or PyTorch tensor"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}