Shortcuts

CIFAR10C

class torch_uncertainty.datasets.classification.CIFAR10C(root, transform=None, target_transform=None, subset='all', shift_severity=1, download=False)[source]

The corrupted CIFAR-10-C Dataset.

Parameters:
  • root (str) – Root directory of the datasets.

  • transform (callable, optional) – A function/transform that takes in a PIL image and returns a transformed version. E.g, transforms.RandomCrop. Defaults to None.

  • target_transform (callable, optional) – A function/transform that takes in the target and transforms it. Defaults to None.

  • subset (str) – The subset to use, one of all or the keys in cifarc_subsets.

  • shift_severity (int) – The shift_severity of the corruption, between 1 and 5.

  • download (bool, optional) – If True, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again. Defaults to False.

References

Benchmarking neural network robustness to common corruptions and perturbations. Dan Hendrycks and Thomas Dietterich. In ICLR, 2019.

download()[source]

Download the dataset.

make_dataset(root, subset, shift_severity)[source]

Make the CIFAR-C dataset.

Build the corrupted dataset according to the chosen subset and

shift_severity. If the subset is ‘all’, gather all corruption types in the dataset.

Parameters:
  • root (Path) – The path to the dataset.

  • subset (str) – The name of the corruption subset to be used. Choose all for the dataset to contain all subsets.

  • shift_severity (int) – The shift_severity of the corruption applied to the images.

Returns:

The samples and labels of the chosen.

Return type:

Tuple[np.ndarray, np.ndarray]