data.datasets.classification package

Submodules

data.datasets.classification.base_image_classification_dataset module

class data.datasets.classification.base_image_classification_dataset.BaseImageClassificationDataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageDataset, ImageFolder

Image Classification Dataset.

This base class can be used to represent any image classification dataset which is stored in a way that meets the expectations of torchvision.datasets.ImageFolder. New image classification datasets can be derived from this similar to ImageNetDataset (imagenet.py) or Places365Dataset (places365.py) and overwrite the data transformations as needed. This dataset also supports sampling a random subset of the training set to be used for training. The subset size is determined by the arguments dataset.num_samples_per_category and dataset.percentage_of_samples in the input opts. Only one of these two should be specified. When dataset.percentage_of_samples is specified, data is sampled from all classes according to this percentage such that the distribution of classes does not change.

The randomness in sampling is controlled by the dataset.sample_selection_random_seed in the input opts.

Parameters:

opts – An argparse.Namespace instance.

__init__(opts: Namespace, *args, **kwargs) None[source]
classmethod add_arguments(parser: ArgumentParser) ArgumentParser[source]

Adds dataset related arguments to the parser.

Parameters:

parser – An argparse.Namespace instance

Returns:

Input argparse.Namespace instance with additional arguments.

share_dataset_arguments() Dict[str, Any][source]

Returns the number of classes in classification dataset along with super-class arguments.

extra_repr() str[source]

Extra information to be represented in __repr__. Each line in the output string should be prefixed with \t.

data.datasets.classification.base_imagenet_shift_dataset module

Base class for ImageNet distribution shift datasets.

class data.datasets.classification.base_imagenet_shift_dataset.BaseImageNetShiftDataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageClassificationDataset

ImageNet Distribution Shift Dataset.

This base class supports ImageNet out-of-distribution datasets. The class names for datasets are a subset of ImageNet. The __getitem__ method projects the labels to the classes of ImageNet to allow zero-shot evaluation.

Parameters:

opts – An argparse.Namespace instance.

__init__(opts: Namespace, *args, **kwargs) None[source]

Initialize BaseImageNetShiftDataset.

post_init_checks() None[source]

Verify the dataset is correctly initialized. Also called in testing.

static class_id_to_imagenet_class_id(class_id: int) int[source]

Return the corresponding class index from ImageNet given a class index.

data.datasets.classification.imagenet module

class data.datasets.classification.imagenet.ImageNetDataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageClassificationDataset

ImageNet dataset that follows the structure of ImageClassificationDataset.

“ImageNet: A large-scale hierarchical image database” Jia Deng; Wei Dong; Richard Socher; Li-Jia Li; Kai Li; Li Fei-Fei 2009 IEEE Conference on Computer Vision and Pattern Recognition

__init__(opts: Namespace, *args, **kwargs) None[source]

data.datasets.classification.imagenet_a module

ImageNetA dataset, a distribution shift of ImageNet.

class data.datasets.classification.imagenet_a.ImageNetADataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageNetShiftDataset

ImageNetA dataset, a distribution shift of ImageNet.

ImageNet-A contains real-world, unmodified natural images that cause model accuracy to substantially degrade.

@article{hendrycks2021nae, title={Natural Adversarial Examples}, author={Dan Hendrycks and Kevin Zhao and Steven Basart and Jacob Steinhardt and Dawn Song}, journal={CVPR}, year={2021} }

__init__(opts: Namespace, *args, **kwargs) None[source]

Initialize ImageNetA.

static class_id_to_imagenet_class_id(class_id: int) int[source]

Return the mapped class index using precomputed mapping.

data.datasets.classification.imagenet_r module

ImageNetR dataset, a distribution shift of ImageNet.

class data.datasets.classification.imagenet_r.ImageNetRDataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageNetShiftDataset

ImageNetR dataset, a distribution shift of ImageNet.

ImageNet-R(endition) contains art, cartoons, deviantart, graffiti, embroidery, graphics, origami, paintings, patterns, plastic objects, plush objects, sculptures, sketches, tattoos, toys, and video game renditions of ImageNet classes.

@article{hendrycks2021many, title={The Many Faces of Robustness: A Critical Analysis of Out-of-Distribution Generalization}, author={Dan Hendrycks and Steven Basart and Norman Mu and Saurav Kadavath and Frank Wang and Evan Dorundo and Rahul Desai and Tyler Zhu and Samyak Parajuli and Mike Guo and Dawn Song and Jacob Steinhardt and Justin Gilmer}, journal={ICCV}, year={2021} }

__init__(opts: Namespace, *args, **kwargs) None[source]

Initialize ImageNetR.

static class_id_to_imagenet_class_id(class_id: int) int[source]

Return the mapped class index using precomputed mapping.

data.datasets.classification.imagenet_sketch module

ImageNetSketch dataset, a distribution shift of ImageNet.

class data.datasets.classification.imagenet_sketch.ImageNetSketchDataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageNetShiftDataset

ImageNetSketch dataset, a distribution shift of ImageNet.

Data set is created from Google Image queries “sketch of __”, where __ is the standard class name. Search is only within the “black and white” color scheme.

@inproceedings{wang2019learning,

title={Learning Robust Global Representations by Penalizing Local Predictive Power}, author={Wang, Haohan and Ge, Songwei and Lipton, Zachary and Xing, Eric P}, booktitle={Advances in Neural Information Processing Systems}, pages={10506–10518}, year={2019}

}

__init__(opts: Namespace, *args, **kwargs) None[source]

Initialize ImageNetSketchDataset.

static class_id_to_imagenet_class_id(class_id: int) int[source]

Return class_id as the ImageNet Sketch classes are the same as ImageNet.

data.datasets.classification.imagenet_synsets module

data.datasets.classification.imagenet_v2 module

class data.datasets.classification.imagenet_v2.Imagenetv2Dataset(opts, *args, **kwargs)[source]

Bases: BaseImageDataset

ImageNetv2 Dataset for studying the robustness of models trained on ImageNet dataset

Parameters:

opts – command-line arguments

__init__(opts, *args, **kwargs) None[source]
classmethod add_arguments(parser: ArgumentParser) ArgumentParser[source]

Add dataset-specific arguments to the parser.

data.datasets.classification.places365 module

class data.datasets.classification.places365.Places365Dataset(opts: Namespace, *args, **kwargs)[source]

Bases: BaseImageClassificationDataset

Places365 dataset that follows the structure of ImageClassificationDataset.

“Places: A 10 million Image Database for Scene Recognition” B. Zhou, A. Lapedriza, A. Khosla, A. Oliva, and A. Torralba IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017

__init__(opts: Namespace, *args, **kwargs) None[source]

Module contents