Datasets

Overview

TorchXRayVision provides a unified interface for a wide range of publicly available chest X-ray datasets. Every dataset class inherits from xrv.datasets.Dataset and exposes three key attributes:

  • pathologies – an ordered list of label names

  • labels – a 2-D NumPy array (samples × pathologies) with values 1, 0, or NaN

  • csv – a Pandas DataFrame of associated per-image metadata

Loading a dataset requires only the path to the image directory:

import torchxrayvision as xrv

d = xrv.datasets.NIH_Dataset(imgpath="/path/to/images")

Common keyword arguments accepted by most dataset classes:

Argument

Description

imgpath

Path to the directory containing the image files (required).

csvpath

Path to the metadata CSV file. Defaults to the bundled copy when available.

views

Restrict images to the specified radiographic views, e.g. ["PA"] or ["PA", "AP"].

transform

A torchvision-compatible transform applied to each sample at load time.

data_aug

An additional transform applied as data augmentation (separate seed).

unique_patients

When True (default for most datasets), only one image per patient is returned.

To combine multiple datasets or align their label columns, see Dataset Helpers.

Available Datasets

Class

Dataset

xrv.datasets.NIH_Dataset

NIH ChestX-ray14 (112 k images, 14 pathologies)

xrv.datasets.NIH_Google_Dataset

NIH ChestX-ray14 with Google radiologist re-labels

xrv.datasets.CheX_Dataset

CheXpert (Stanford, 224 k images, 14 pathologies)

xrv.datasets.MIMIC_Dataset

MIMIC-CXR (MIT/PhysioNet, 227 k images)

xrv.datasets.PC_Dataset

PadChest (Spain, 94 k images)

xrv.datasets.RSNA_Pneumonia_Dataset

RSNA Pneumonia Detection Challenge

xrv.datasets.Openi_Dataset

OpenI / Indiana University chest X-ray collection

xrv.datasets.COVID19_Dataset

COVID-19 image data collection

xrv.datasets.NLMTB_Dataset

NLM / Montgomery & Shenzhen tuberculosis datasets

xrv.datasets.TBX11K_Dataset

TBX11K tuberculosis dataset

xrv.datasets.SIIM_Pneumothorax_Dataset

SIIM-ACR Pneumothorax Segmentation

xrv.datasets.VinBrain_Dataset

VinBigData Chest X-ray Abnormalities Detection

xrv.datasets.StonyBrookCOVID_Dataset

Stony Brook University COVID-19 positive cases

xrv.datasets.ObjectCXR_Dataset

Object-CXR foreign-object detection dataset

Base Class

All dataset classes share the interface defined below.

class xrv.datasets.Dataset

The datasets in this library aim to fit a simple interface where the imgpath and csvpath are specified. Some datasets require more than one metadata file and for some the metadata files are packaged in the library so only the imgpath needs to be specified.

pathologies: List[str]

A list of strings identifying the pathologies contained in this dataset. This list corresponds to the columns of the .labels matrix. Although it is called pathologies, the contents do not have to be pathologies and may simply be attributes of the patient.

labels: ndarray

A NumPy array which contains a 1, 0, or NaN for each pathology. Each column is a pathology and each row corresponds to an item in the dataset. A 1 represents that the pathology is present, 0 represents the pathology is absent, and NaN represents no information.

csv: DataFrame

A Pandas DataFrame of the metadata .csv file that is included with the data. For some datasets multiple metadata files have been merged together. It is largely a “catch-all” for associated data and the referenced publication should explain each field. Each row aligns with the elements of the dataset so indexing using .iloc will work. Alignment between the DataFrame and the dataset items will be maintained when using tools from this library.

totals() Dict[str, Dict[str, int]]

Compute counts of pathologies.

Returns: A dict containing pathology name -> (label->value)

__repr__() str

Returns the name and a description of the dataset such as:

CheX_Dataset num_samples=191010 views=['PA', 'AP']

If in a jupyter notebook it will also print the counts of the pathology counts returned by .totals()

{'Atelectasis': {0.0: 17621, 1.0: 29718},
 'Cardiomegaly': {0.0: 22645, 1.0: 23384},
 'Consolidation': {0.0: 30463, 1.0: 12982},
 ...}

Dataset Classes

class xrv.datasets.NIH_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', bbox_list_path='USE_INCLUDED_FILE', views=['PA'], transform=None, data_aug=None, seed=0, unique_patients=True, pathology_masks=False)

NIH ChestX-ray14 dataset

The NIH ChestX-ray14 dataset contains 112,120 frontal-view chest X-ray images from 30,805 unique patients. Each image may carry one or more of 14 disease labels that were automatically mined from accompanying radiological reports using natural language processing. The text-mined labels are expected to have an accuracy greater than 90 %.

Pathologies (14): Atelectasis, Cardiomegaly, Consolidation, Edema, Effusion, Emphysema, Fibrosis, Hernia, Infiltration, Mass, Nodule, Pleural Thickening, Pneumonia, Pneumothorax.

Bounding-box annotations for a subset of images are included and are accessible via the pathology_masks=True argument.

Citation:

Wang X, Peng Y, Lu L, Lu Z, Bagheri M, Summers RM. ChestX-ray8: Hospital-scale Chest X-ray Database and Benchmarks. Proceedings of CVPR, 2017. https://arxiv.org/abs/1705.02315

Dataset release:

https://www.nih.gov/news-events/news-releases/nih-clinical-center-provides-one-largest-publicly-available-chest-x-ray-datasets-scientific-community

Download full-size images:

https://academictorrents.com/details/557481faacd824c83fbf57dcf7b6da9383b3235a

Download resized (224 × 224) images:

https://academictorrents.com/details/e615d3aebce373f1dc8bd9d11064da55bdadede0

class xrv.datasets.NIH_Google_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', views=['PA'], transform=None, data_aug=None, nrows=None, seed=0, unique_patients=True)

NIH ChestX-ray14 with Google radiologist re-labels

A subset of the NIH ChestX-ray14 dataset that has been re-annotated by radiologists at Google. Labels were adjudicated by a panel of US board-certified radiologists to produce high-quality reference standards for four findings.

Pathologies (4): Airspace Opacity (mapped to Lung Opacity), Fracture, Nodule/Mass, Pneumothorax.

The original release provides separate test and validation splits; this class combines both by default. To use only one split, pass the corresponding CSV file via the csvpath argument.

Note

This class loads images from an existing NIH ChestX-ray14 download. The image files themselves are not redistributed.

Citation:

Majkowska A, Mittal S, Steiner DF, et al. Chest Radiograph Interpretation with Deep Learning Models: Assessment with Radiologist-adjudicated Reference Standards and Population-adjusted Evaluation. Radiology, 2020. https://pubs.rsna.org/doi/10.1148/radiol.2019191293

Download NIH images (resized 224 × 224):

https://academictorrents.com/details/e615d3aebce373f1dc8bd9d11064da55bdadede0

class xrv.datasets.CheX_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', views=['PA'], transform=None, data_aug=None, flat_dir=True, seed=0, unique_patients=True)

CheXpert dataset (Stanford)

CheXpert is a large chest radiograph dataset from Stanford containing 224,316 images from 65,240 patients. Labels for 14 observations were generated automatically using the CheXpert labeler applied to free-text radiology reports. A key feature of this dataset is its handling of uncertain labels: the original CSV encodes uncertainty as -1, which this class converts to NaN for consistency with the rest of the library.

Pathologies (13): Atelectasis, Cardiomegaly, Consolidation, Edema, Effusion, Enlarged Cardiomediastinum, Fracture, Lung Lesion, Lung Opacity, Pleural Other, Pneumonia, Pneumothorax, Support Devices. (“No Finding” is used internally to zero-out pathology labels but is not returned as a column.)

Citation:

Irvin J, Rajpurkar P, Ko M, et al. CheXpert: A Large Chest Radiograph Dataset with Uncertainty Labels and Expert Comparison. arXiv:1901.07031, 2019. https://arxiv.org/abs/1901.07031

Dataset website:

https://stanfordmlgroup.github.io/competitions/chexpert/

class xrv.datasets.MIMIC_Dataset(imgpath, csvpath, metacsvpath, views=['PA'], transform=None, data_aug=None, seed=0, unique_patients=True)

MIMIC-CXR dataset (MIT / Beth Israel Deaconess Medical Center)

MIMIC-CXR is a large, de-identified dataset of chest radiographs collected from the Beth Israel Deaconess Medical Center between 2011 and 2016. It contains 227,835 images from 64,588 patients, along with structured labels extracted from free-text radiology reports using the CheXpert labeler. Both PA and AP views are available.

Pathologies (13): Atelectasis, Cardiomegaly, Consolidation, Edema, Effusion, Enlarged Cardiomediastinum, Fracture, Lung Lesion, Lung Opacity, Pleural Other, Pneumonia, Pneumothorax, Support Devices.

Note

Access requires a credentialed PhysioNet account and completion of the required data-use training. Both a csvpath (labels CSV) and a metacsvpath (DICOM metadata CSV) must be provided.

Citation:

Johnson AEW, Pollard TJ, Berkowitz S, et al. MIMIC-CXR: A large publicly available database of labeled chest radiographs. arXiv:1901.07042, 2019. https://arxiv.org/abs/1901.07042

Dataset website:

https://physionet.org/content/mimic-cxr-jpg/2.0.0/

class xrv.datasets.PC_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', views=['PA'], transform=None, data_aug=None, flat_dir=True, seed=0, unique_patients=True)

PadChest dataset

A large, multi-label chest X-ray dataset collected at the Hospital San Juan de Alicante (Spain). PadChest contains over 160,000 images from more than 67,000 patients, annotated with 174 radiographic findings across 27 diagnostic labels (28 as loaded here, including a support devices label). Labels were obtained via a combination of manual annotation and NLP applied to Spanish-language radiology reports. Roughly a quarter of the images were manually verified by a radiologist.

Pathologies (28): Atelectasis, Cardiomegaly, Consolidation, and many more — see self.pathologies for the full list after loading.

Note

Images with null labels (distinct from a normal finding) and a small number of images that cannot be loaded are excluded at load time, so the effective dataset size is slightly less than the file count.

Citation:

Bustos A, Pertusa A, Salinas JM, de la Iglesia-Vayá M. PadChest: A large chest x-ray image dataset with multi-label annotated reports. arXiv:1901.07441, 2019. https://arxiv.org/abs/1901.07441

Dataset website:

http://bimcv.cipf.es/bimcv-projects/padchest/

Download full-size images:

https://academictorrents.com/details/dec12db21d57e158f78621f06dcbe78248d14850

Download resized (224 × 224) images:

https://academictorrents.com/details/96ebb4f92b85929eadfb16761f310a6d04105797

class xrv.datasets.RSNA_Pneumonia_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', dicomcsvpath='USE_INCLUDED_FILE', views=['PA'], transform=None, data_aug=None, nrows=None, seed=0, pathology_masks=False, extension='.jpg')

RSNA Pneumonia Detection Challenge dataset

A subset of the NIH ChestX-ray14 images re-annotated by board-certified radiologists for the 2018 RSNA Pneumonia Detection Challenge. The dataset contains 26,684 frontal chest X-rays with bounding-box annotations for regions of pneumonia / lung opacity.

Pathologies (2): Lung Opacity, Pneumonia.

Per-image bounding-box masks are available via pathology_masks=True. Images can be loaded as JPEG (default) or DICOM by setting extension=".dcm" (requires pydicom).

Citation:

Shih G, Wu CC, Halabi SS, et al. Augmenting the National Institutes of Health Chest Radiograph Dataset with Expert Annotations of Possible Pneumonia. Radiology: Artificial Intelligence, 2019. doi: 10.1148/ryai.2019180041

Challenge site:

https://www.kaggle.com/c/rsna-pneumonia-detection-challenge

Download JPEG images:

https://academictorrents.com/details/95588a735c9ae4d123f3ca408e56570409bcf2a9

class xrv.datasets.Openi_Dataset(imgpath, xmlpath='USE_INCLUDED_FILE', dicomcsv_path='USE_INCLUDED_FILE', tsnepacsv_path='USE_INCLUDED_FILE', use_tsne_derived_view=False, views=['PA'], transform=None, data_aug=None, nrows=None, seed=0, unique_patients=True)

OpenI / Indiana University chest X-ray collection

The Indiana University chest X-ray collection (OpenI) contains 7,470 chest X-ray images from 3,955 radiology reports collected at Indiana University Health. Labels are derived automatically from MeSH terms embedded in the XML report files.

Pathologies (18): Atelectasis, Calcified Granuloma, Cardiomegaly, Edema, Effusion, Emphysema, Fibrosis, Fracture, Granuloma, Hernia, Infiltration, Lung Lesion, Lung Opacity, Mass, Nodule, Pleural Thickening, Pneumonia, Pneumothorax.

Note

View position labels in the original records are noisy. A T-SNE projection was used to derive higher-quality PA/AP labels. Set use_tsne_derived_view=True to use these derived labels instead of the raw metadata values.

Citation:

Demner-Fushman D, Kohli MD, Rosenman MB, et al. Preparing a collection of radiology examinations for distribution and retrieval. Journal of the American Medical Informatics Association, 2016. doi: 10.1093/jamia/ocv080

Dataset website:

https://openi.nlm.nih.gov/faq

Download images:

https://academictorrents.com/details/5a3a439df24931f410fac269b87b050203d9467d

class xrv.datasets.COVID19_Dataset(imgpath: str, csvpath: str, views=['PA', 'AP'], transform=None, data_aug=None, seed: int = 0, semantic_masks=False)

COVID-19 Image Data Collection

A manually curated, open-source collection of frontal and lateral chest X-rays (and CT scans) from COVID-19 cases, aggregated from published figures and public web repositories. It is one of the largest public resources for COVID-19 chest imaging and prognostic data.

In addition to image labels, the accompanying metadata CSV provides clinical context including time since first symptoms, ICU admission status, survival status, intubation status, and hospital location. These fields enable tasks such as severity prediction and patient trajectory modelling.

Lung segmentation masks (from V7 Labs) are optionally available via semantic_masks=True.

Note

Both imgpath and csvpath must be provided; neither is bundled with the library. Clone or download the dataset repository first.

Citations:

Cohen JP, Morrison P, Dao L, Roth K, Duong TQ, Ghassemi M. COVID-19 Image Data Collection: Prospective Predictions Are the Future. arXiv:2006.11988, 2020.

Cohen JP, Morrison P, Dao L. COVID-19 Image Data Collection. arXiv:2003.11597, 2020.

Dataset repository:

https://github.com/ieee8023/covid-chestxray-dataset

class xrv.datasets.NLMTB_Dataset(imgpath, transform=None, data_aug=None, seed=0, views=['PA'])

NLM Tuberculosis datasets (Montgomery County & Shenzhen)

Two public chest X-ray datasets released by the National Library of Medicine for computer-aided TB screening:

  • Montgomery County (USA): 138 normal and 80 TB-positive PA images, collected by the Montgomery County Department of Health and Human Services.

  • Shenzhen (China): approximately 326 normal and 336 TB-positive PA images, collected at Shenzhen No. 3 People’s Hospital.

Pathologies (1): Tuberculosis.

Note

Load each dataset separately by pointing imgpath at the corresponding root folder (NLM-MontgomeryCXRSet or ChinaSet_AllFiles). Use MergeDataset to combine them. All images are PA view.

Citation:

Jaeger S, Candemir S, Antani S, Wang YX, Lu PX, Thoma G. Two public chest X-ray datasets for computer-aided screening of pulmonary diseases. Quant Imaging Med Surg, 2014; 4(6):475–477. doi: 10.3978/j.issn.2223-4292.2014.11.20

Download Montgomery County images:

https://academictorrents.com/details/ac786f74878a5775c81d490b23842fd4736bfe33

Download Shenzhen images:

https://academictorrents.com/details/462728e890bd37c05e9439c885df7afc36209cc8

class xrv.datasets.TBX11K_Dataset(imgpath, split='train', transform=None, data_aug=None, seed=0)

TBX11K Tuberculosis X-ray dataset

TBX11K contains 11,200 chest X-ray images with bounding-box annotations for tuberculosis (TB) areas, spanning five categories: Healthy, Sick but Non-TB, Active TB, Latent TB, and Uncertain TB.

Note

This dataset overlaps with NLMTB_Dataset (Montgomery + Shenzhen images). Avoid training on one and evaluating on the other to prevent data leakage.

Pathologies (4): ActiveTuberculosis, ObsoletePulmonaryTuberculosis, PulmonaryTuberculosis, Tuberculosis (superclass).

Label notes:

  • ActiveTuberculosis: currently active, contagious TB, typically shown by infiltrates, consolidation, or cavities on the X-ray.

  • ObsoletePulmonaryTuberculosis: old, healed/inactive TB lesions from a prior infection, no longer active.

  • PulmonaryTuberculosis: a general pulmonary TB category defined in the dataset. Does not appear in train/val/trainval annotations so its label column is always 0.

  • Tuberculosis: superclass label, positive if any of the above TB findings are present. Use this column for binary TB vs. non-TB tasks.

This dataset incorporates images from four TB collections:

  • DA dataset (156 images, CC BY 4.0)

  • DB dataset (150 images, CC BY 4.0)

  • Montgomery County X-ray Set (138 images, public domain, NLM)

  • Shenzhen X-ray Set (662 images, public domain, NLM)

Citation:

Liu Y, Wu YH, Ban Y, Wang H, Cheng MM. Rethinking Computer-Aided Tuberculosis Diagnosis. IEEE/CVF CVPR, 2020, pp. 2643–2652. doi: 10.1109/CVPR42600.2020.00272

Dataset and annotations:

https://github.com/yun-liu/Tuberculosis

Paper:

https://ieeexplore.ieee.org/document/9156613

License:

CC BY-NC-SA 2.0 — https://creativecommons.org/licenses/by-nc-sa/2.0/

class xrv.datasets.SIIM_Pneumothorax_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', transform=None, data_aug=None, seed=0, unique_patients=True, pathology_masks=False)

SIIM-ACR Pneumothorax Segmentation dataset

The training corpus from the 2019 SIIM-ACR Pneumothorax Segmentation Kaggle challenge. It contains 12,954 chest X-ray images in DICOM format along with run-length-encoded (RLE) segmentation masks that delineate pneumothorax (collapsed lung) regions. Images without pneumothorax carry a mask value of -1.

Pathologies (1): Pneumothorax.

Per-image segmentation masks are available via pathology_masks=True. Requires pydicom to read the .dcm image files.

Note

Some training images have multiple annotations from different radiologists; all annotations are combined into a single mask.

Challenge site:

https://www.kaggle.com/c/siim-acr-pneumothorax-segmentation

Download DICOM images:

https://academictorrents.com/details/6ef7c6d039e85152c4d0f31d83fa70edc4aba088

class xrv.datasets.VinBrain_Dataset(imgpath, csvpath='USE_INCLUDED_FILE', views=None, transform=None, data_aug=None, seed=0, pathology_masks=False)

VinDr-CXR dataset

A large chest X-ray dataset collected at two major hospitals in Vietnam (Hanoi Medical University Hospital and Bach Mai Hospital), annotated by 17 experienced radiologists. The training set contains 15,000 DICOM images with bounding-box labels covering 14 thoracic abnormalities and a “No finding” class.

Pathologies (14): Aortic Enlargement, Atelectasis, Calcification, Cardiomegaly, Consolidation, Effusion, ILD, Infiltration, Lesion, Lung Opacity, Nodule/Mass, Pleural Thickening, Pneumothorax, Pulmonary Fibrosis.

Per-image bounding-box masks are available via pathology_masks=True. Requires pydicom to read the .dicom image files.

Example:

d_vin = xrv.datasets.VinBrain_Dataset(
    imgpath=".../train",
    csvpath=".../train.csv"
)
Citation:

Nguyen HQ, Lam K, Le LT, et al. VinDr-CXR: An open dataset of chest X-rays with radiologist’s annotations. arXiv:2012.15029, 2020. http://arxiv.org/abs/2012.15029

Challenge site:

https://www.kaggle.com/c/vinbigdata-chest-xray-abnormalities-detection

class xrv.datasets.StonyBrookCOVID_Dataset(imgpath, csvpath, transform=None, data_aug=None, views=['AP'], seed=0)

Stony Brook COVID-19 Radiographic Assessment of Lung Opacity (RALO) dataset

A dataset of chest X-rays from COVID-19 positive patients collected at Stony Brook University Hospital. Each image is scored for the geographic extent and opacity severity of lung involvement using the RALO scoring system. Labels are continuous scores rather than binary pathology labels.

Pathologies (2): Geographic Extent, Lung Opacity.

Note

Both imgpath (path to CXR_images_scored/) and csvpath (path to ralo-dataset-metadata.csv) must be provided. All images are AP view.

Citation:

Goldgof G, et al. Stony Brook Medicine COVID-19 Positive Cases. Zenodo, 2021. https://doi.org/10.5281/zenodo.4633999

class xrv.datasets.ObjectCXR_Dataset(imgzippath, csvpath, transform=None, data_aug=None, seed=0)

Object-CXR foreign object detection dataset

A challenge dataset from MIDL 2020 containing 10,000 frontal chest X-ray images: 5,000 with at least one foreign object present and 5,000 without. Images were collected from township hospitals in China via a telemedicine platform. Foreign objects are annotated with bounding boxes, ellipses, or pixel masks depending on object shape.

Pathologies (1): Foreign Object.

Note

Images are stored inside a ZIP archive. Pass the path to the ZIP file as imgzippath and the annotation CSV path as csvpath.

Challenge website:

https://jfhealthcare.github.io/object-CXR/

Download images and annotations:

https://academictorrents.com/details/fdc91f11d7010f7259a05403fc9d00079a09f5d5 https://archive.org/download/object-CXR/object-CXR/