Skip to content

MedMNIST ​

MedMNIST v2 is a collection of standardized biomedical image datasets. MedMNIST loads one of them as images (N, 3, size, size) uint8 and labels (N,).

Yang et al., MedMNIST v2: A large-scale lightweight benchmark for 2D and 3D biomedical image classification, Scientific Data 2023. Paper · Data · CC BY 4.0

Usage ​

python
from torch_world.datasets import MedMNIST

blood = MedMNIST("bloodmnist", split="train", size=64)
item = blood[0]               # {"image": (3, 64, 64) uint8, "label": ()}

blood.images, blood.labels    # (N, 3, 64, 64), (N,)
blood.modality                # "blood smear microscopy"
blood.classes                 # ["basophil", "eosinophil", ...]
blood.malignant               # class ids that are malignant (empty here)
blood.info                    # "bloodmnist (train): blood smear microscopy, 8 classes, 11959 images"
argument
nameone of the datasets below
split"train", "val" or "test"
size28, 64, 128 or 224
rootcache directory, ~/.cache/torch_world/medmnist by default
downloadfetch the file if it is missing; otherwise raise FileNotFoundError

The .npz file is downloaded once from Zenodo and checked against its MD5 on every load. It is read without NumPy. Grayscale images are repeated to three channels, so every dataset feeds the same encoder.

Available datasets ​

namemodalityclassesmalignant classestrain / val / test
bloodmnistblood smear microscopy8 cell typesnone11,959 / 1,712 / 3,421
breastmnistbreast ultrasoundmalignant, benign lesionmalignant lesion546 / 78 / 156
dermamnistdermatoscopy7 skin lesionsactinic keratosis, basal cell carcinoma, melanoma7,007 / 1,003 / 2,005
organamnistabdominal CT11 organsnone34,561 / 6,491 / 17,778
pathmnistcolon pathology9 tissue typescolorectal adenocarcinoma epithelium89,996 / 10,004 / 7,180

Split sizes are those published with MedMNIST v2.

Reference ​

MedMNIST in the API reference.