def load_test_data(self): dirname = 'cifar-10-batches-py' path = os.path.join(self.data_dir, dirname) fpath = os.path.join(path, 'test_batch') x_test, y_test = self._load_batch(fpath) if K.image_data_format() == 'channels_last': x_test = x_test.transpose(0, 2, 3, 1) y_test_labels = one_hot_encoded(y_test, num_classes=self.n_classes) return x_test, np.array(y_test), y_test_labels
def load_training_data(self): dirname = 'cifar-10-batches-py' path = os.path.join(self.data_dir, dirname) n_train_batchs = 5 x_train = np.zeros((0, self.depth, self.width, self.height)) y_train = [] for batch in range(n_train_batchs): fpath = os.path.join(path, 'data_batch_' + str(batch + 1)) cur_data, cur_labels = self._load_batch(fpath) x_train = np.concatenate((cur_data, x_train), axis=0) y_train = cur_labels + y_train x_train = x_train.astype(np.uint8) if K.image_data_format() == 'channels_last': x_train = x_train.transpose(0, 2, 3, 1) y_train_labels = one_hot_encoded(y_train, num_classes=self.n_classes) return x_train, np.array(y_train), y_train_labels
def load_test_data(self): dirname = 'cifar-100-python' path = os.path.join(self.data_dir, dirname) fpath = os.path.join(path, 'test') x_test, y_test_fine = self._load_batch(fpath, 'fine_labels') data_size = len(y_test_fine) if K.image_data_format() == 'channels_last': x_test = x_test.transpose(0, 2, 3, 1) relevant_idxes = [i for i in range(data_size) if y_test_fine[i] in self.subsets_idxes] x_test = x_test[relevant_idxes, :, :, :] y_test = np.asarray(y_test_fine)[relevant_idxes] y_test_values = sorted(list(set(y_test))) assert(len(y_test_values) == self.n_classes) map_dict = {val: i for i, val in enumerate(y_test_values)} for i, y in enumerate(y_test): y_test[i] = map_dict[y] y_test_labels = one_hot_encoded(y_test, num_classes=self.n_classes) return x_test, y_test, y_test_labels
def load_training_data(self): dirname = 'cifar-100-python' path = os.path.join(self.data_dir, dirname) fpath = os.path.join(path, 'train') x_train, y_train_fine = self._load_batch(fpath, 'fine_labels') _, y_train_coarse = self._load_batch(fpath, 'coarse_labels') if K.image_data_format() == 'channels_last': x_train = x_train.transpose(0, 2, 3, 1) curr_superclass_idxes = [i for i in range(len(y_train_fine)) if y_train_coarse[i] == self.superclass_idx] x_train = x_train[curr_superclass_idxes] y_train = np.asarray(y_train_fine)[curr_superclass_idxes] y_train_values = sorted(list(set(y_train))) assert(len(y_train_values) == self.n_classes) map_dict = {val: i for i, val in enumerate(y_train_values)} for i, y in enumerate(y_train): y_train[i] = map_dict[y] y_train_labels = one_hot_encoded(y_train, num_classes=self.n_classes) return x_train, y_train, y_train_labels