Args: train_or_test (str): 'train' or 'test' shuffle (bool): defaults to True for training set. dir (str): path to the dataset directory cifar_classnum (int): 10 or 100
(self, train_or_test, shuffle=None, dir=None, cifar_classnum=10)
| 86 | label is an int. |
| 87 | """ |
| 88 | def __init__(self, train_or_test, shuffle=None, dir=None, cifar_classnum=10): |
| 89 | """ |
| 90 | Args: |
| 91 | train_or_test (str): 'train' or 'test' |
| 92 | shuffle (bool): defaults to True for training set. |
| 93 | dir (str): path to the dataset directory |
| 94 | cifar_classnum (int): 10 or 100 |
| 95 | """ |
| 96 | assert train_or_test in ['train', 'test'] |
| 97 | assert cifar_classnum == 10 or cifar_classnum == 100 |
| 98 | self.cifar_classnum = cifar_classnum |
| 99 | if dir is None: |
| 100 | dir = get_dataset_path('cifar{}_data'.format(cifar_classnum)) |
| 101 | maybe_download_and_extract(dir, self.cifar_classnum) |
| 102 | train_files, test_files, meta_file = get_filenames(dir, cifar_classnum) |
| 103 | if train_or_test == 'train': |
| 104 | self.fs = train_files |
| 105 | else: |
| 106 | self.fs = test_files |
| 107 | for f in self.fs: |
| 108 | if not os.path.isfile(f): |
| 109 | raise ValueError('Failed to find file: ' + f) |
| 110 | self._label_names = _parse_meta(meta_file, cifar_classnum) |
| 111 | self.train_or_test = train_or_test |
| 112 | self.data = read_cifar(self.fs, cifar_classnum) |
| 113 | self.dir = dir |
| 114 | |
| 115 | if shuffle is None: |
| 116 | shuffle = train_or_test == 'train' |
| 117 | self.shuffle = shuffle |
| 118 | |
| 119 | def __len__(self): |
| 120 | return 50000 if self.train_or_test == 'train' else 10000 |
nothing calls this directly
no test coverage detected