Skip to main content

This Python library aims to evaluate model robustness under corrupted test sets and to enhance domain generalization through domain-specific augmentations.

Project description

🏥 MedMNIST-C

We introduce MedMNIST-C [preprint], a benchmark dataset based on the MedMNIST+ collection covering 12 2D datasets and 9 imaging modalities. We simulate task and modality-specific image corruptions of varying severity to comprehensively evaluate the robustness of established algorithms against real-world artifacts and distribution shifts. We further show that our simple-to-use artificial corruptions allow for highly performant, lightweight data augmentation to enhance model robustness.

Preview of image corruptions

Installation and Requirements

pip install medmnistc

We do require Wand for image manipulation, a Python binding for ImageMagick. Thus, if you are using Ubuntu:

sudo apt-get install libmagickwand-dev

otherwise, please check the tutorial.

Main components

  • medmnistc/corruptions/registry.py: List of all the corruptions and respective intensity hyperparameters.
  • medmnistc/dataset_manager.py: Dataset class responsible for the creation of the corrupted datasets.
  • medmnistc/visualizer.py: Class used to visualize and store the defined corruptions.
  • medmnistc/augmentation.py: Augumentation class based on the defined corruptions.
  • medmnistc/dataset.py: Dataset class used for the corrupted datasets.
  • medmnistc/eval.py: PyTorch class used for model evaluation under corrupted datasets.
  • medmnistc/assets/baseline/*: Normalization baselines used for model evaluation under corrupted datasets.

Basic usage

Create the corrupted datasets

from medmnistc.dataset_manager import DatasetManager

medmnist_path = ... # PATH TO THE CLEAN IMAGES
medmnistc_path = ... # PATH TO THE CORRUPTED IMAGES

ds_manager = DatasetManager(medmnist_path = medmnist_path, output_path=output_path)
ds_manager.create_dataset(dataset_name = "breastmnist") # create a single corrupted test set
ds_manager.create_dataset(dataset_name = "all") # create all

Augmentations

from medmnistc.augmentation import AugMedMNISTC
from medmnistc.corruptions.registry import CORRUPTIONS_DS
import torchvision.transforms as transforms

dataset = "breastmnist" # select dataset
train_corruptions = CORRUPTIONS_DS[dataset] # load the designed corruptions for this dataset
images = ... # load images

# Augment with AugMedMNISTC
augment = AugMedMNISTC(train_corruptions)
augmented_img = augment(images[0])

# Integrate into transforms.Compose
aug_compose = transforms.Compose([
    AugMedMNISTC(train_corruptions),
    transforms.ToTensor(),
    transforms.Normalize(mean=..., std=...)
])

augmented_img = aug_compose(images[0])

Notebooks

License

The code is under Apache-2.0 License.

The MedMNIST-C dataset is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0), except DermaMNIST-C under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).

Citation

If you find this work useful, please consider citing us:

@article{,
   title={},
   author={},
   journal={},
   year={}
}

DISCLAIMER: This repository is inspired by MedMNIST APIs and the ImageNet-C repository. Thus, please also consider citing MedMNIST, the respective source datasets (described here) and ImageNet-C.

Release versions

  • v0.1.0: MedMNIST-C beta release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medmnistc-0.1.0.tar.gz (4.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

medmnistc-0.1.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file medmnistc-0.1.0.tar.gz.

File metadata

  • Download URL: medmnistc-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for medmnistc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e3898a8ff5cec9be9e969314d1207f677d8d933dfcafe4576f4a102776654d36
MD5 d68b72d08cc157be32ac658ccb13605b
BLAKE2b-256 4c7d1ab377e05bbae1853b95103713670a2f7c1af05b3ddeadf2165608d9e7d1

See more details on using hashes here.

File details

Details for the file medmnistc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: medmnistc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for medmnistc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4529626f0ce7e498fe876acd12e50c3776103f9bfeb99afd3e7dba34a1779e34
MD5 e15cc11fcbae764bd5d467b29aa064d3
BLAKE2b-256 231f01546d9b6077570c3cdcc181dd586ece77914c1905b45a25fb9e7ab29a0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page