Python keras.datasets.cifar100.load_data() Examples
The following are 30
code examples of keras.datasets.cifar100.load_data().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keras.datasets.cifar100
, or try the search function
.
Example #1
Source File: utils.py From ResNet-Tensorflow with MIT License | 7 votes |
def load_cifar100() : (train_data, train_labels), (test_data, test_labels) = cifar100.load_data() # train_data = train_data / 255.0 # test_data = test_data / 255.0 train_data, test_data = normalize(train_data, test_data) train_labels = to_categorical(train_labels, 100) test_labels = to_categorical(test_labels, 100) seed = 777 np.random.seed(seed) np.random.shuffle(train_data) np.random.seed(seed) np.random.shuffle(train_labels) return train_data, train_labels, test_data, test_labels
Example #2
Source File: test_datasets.py From CAPTCHA-breaking with MIT License | 6 votes |
def test_cifar(self): print('cifar10') (X_train, y_train), (X_test, y_test) = cifar10.load_data() print(X_train.shape) print(X_test.shape) print(y_train.shape) print(y_test.shape) print('cifar100 fine') (X_train, y_train), (X_test, y_test) = cifar100.load_data('fine') print(X_train.shape) print(X_test.shape) print(y_train.shape) print(y_test.shape) print('cifar100 coarse') (X_train, y_train), (X_test, y_test) = cifar100.load_data('coarse') print(X_train.shape) print(X_test.shape) print(y_train.shape) print(y_test.shape)
Example #3
Source File: test_datasets.py From CAPTCHA-breaking with MIT License | 6 votes |
def test_imdb(self): print('imdb') (X_train, y_train), (X_test, y_test) = imdb.load_data()
Example #4
Source File: utils.py From ResNet-Tensorflow with MIT License | 6 votes |
def load_mnist() : (train_data, train_labels), (test_data, test_labels) = mnist.load_data() train_data = np.expand_dims(train_data, axis=-1) test_data = np.expand_dims(test_data, axis=-1) train_data, test_data = normalize(train_data, test_data) train_labels = to_categorical(train_labels, 10) test_labels = to_categorical(test_labels, 10) seed = 777 np.random.seed(seed) np.random.shuffle(train_data) np.random.seed(seed) np.random.shuffle(train_labels) return train_data, train_labels, test_data, test_labels
Example #5
Source File: convert.py From MobileNetV2 with MIT License | 6 votes |
def convert(): train = 'train//' val = 'validation//' (X_train, y_train), (X_test, y_test) = cifar100.load_data(label_mode='fine') for i in range(len(X_train)): x = X_train[i] y = y_train[i] path = train + str(y[0]) x = cv2.resize(x, (224, 224), interpolation=cv2.INTER_CUBIC) if not os.path.exists(path): os.makedirs(path) cv2.imwrite(path + '//' + str(i) + '.jpg', x) for i in range(len(X_test)): x = X_test[i] y = y_test[i] path = val + str(y[0]) x = cv2.resize(x, (224, 224), interpolation=cv2.INTER_CUBIC) if not os.path.exists(path): os.makedirs(path) cv2.imwrite(path + '//' + str(i) + '.jpg', x)
Example #6
Source File: utils.py From ResNet-Tensorflow with MIT License | 6 votes |
def load_fashion() : (train_data, train_labels), (test_data, test_labels) = fashion_mnist.load_data() train_data = np.expand_dims(train_data, axis=-1) test_data = np.expand_dims(test_data, axis=-1) train_data, test_data = normalize(train_data, test_data) train_labels = to_categorical(train_labels, 10) test_labels = to_categorical(test_labels, 10) seed = 777 np.random.seed(seed) np.random.shuffle(train_data) np.random.seed(seed) np.random.shuffle(train_labels) return train_data, train_labels, test_data, test_labels
Example #7
Source File: utils.py From ResNet-Tensorflow with MIT License | 6 votes |
def load_cifar10() : (train_data, train_labels), (test_data, test_labels) = cifar10.load_data() # train_data = train_data / 255.0 # test_data = test_data / 255.0 train_data, test_data = normalize(train_data, test_data) train_labels = to_categorical(train_labels, 10) test_labels = to_categorical(test_labels, 10) seed = 777 np.random.seed(seed) np.random.shuffle(train_data) np.random.seed(seed) np.random.shuffle(train_labels) return train_data, train_labels, test_data, test_labels
Example #8
Source File: utils.py From AnomalyDetectionTransformations with MIT License | 5 votes |
def load_fashion_mnist(): (X_train, y_train), (X_test, y_test) = fashion_mnist.load_data() X_train = normalize_minus1_1(cast_to_floatx(np.pad(X_train, ((0, 0), (2, 2), (2, 2)), 'constant'))) X_train = np.expand_dims(X_train, axis=get_channels_axis()) X_test = normalize_minus1_1(cast_to_floatx(np.pad(X_test, ((0, 0), (2, 2), (2, 2)), 'constant'))) X_test = np.expand_dims(X_test, axis=get_channels_axis()) return (X_train, y_train), (X_test, y_test)
Example #9
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_reuters(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = reuters.load_data() assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) assert len(x_train) + len(x_test) == 11228 (x_train, y_train), (x_test, y_test) = reuters.load_data(maxlen=10) assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) word_index = reuters.get_word_index() assert isinstance(word_index, dict)
Example #10
Source File: load_datasets.py From deepcaps with MIT License | 5 votes |
def load_cifar10(): from keras.datasets import cifar10 (x_train, y_train), (x_test, y_test) = cifar10.load_data() x_train = x_train.reshape(-1, 32, 32, 3).astype('float32') / 255. x_test = x_test.reshape(-1, 32, 32, 3).astype('float32') / 255. # mean = np.mean(x_train, axis=(0,1,2)) # x_train -= mean # x_test -= mean y_train = to_categorical(y_train.astype('float32')) y_test = to_categorical(y_test.astype('float32')) # return (x_train[0:100], y_train[0:100]), (x_test[0:100], y_test[0:100]) return (x_train, y_train), (x_test, y_test)
Example #11
Source File: load_datasets.py From deepcaps with MIT License | 5 votes |
def load_cifar100(): from keras.datasets import cifar100 (x_train, y_train), (x_test, y_test) = cifar100.load_data() x_train = x_train.reshape(-1, 32, 32, 3).astype('float32') / 255. x_test = x_test.reshape(-1, 32, 32, 3).astype('float32') / 255. y_train = to_categorical(y_train.astype('float32')) y_test = to_categorical(y_test.astype('float32')) return (x_train, y_train), (x_test, y_test)
Example #12
Source File: load_datasets.py From deepcaps with MIT License | 5 votes |
def load_mnist(): # the data, shuffled and split between train and test sets from keras.datasets import mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(-1, 28, 28, 1).astype('float32') / 255. x_test = x_test.reshape(-1, 28, 28, 1).astype('float32') / 255. y_train = to_categorical(y_train.astype('float32')) y_test = to_categorical(y_test.astype('float32')) return (x_train, y_train), (x_test, y_test)
Example #13
Source File: load_datasets.py From deepcaps with MIT License | 5 votes |
def load_fmnist(): # the data, shuffled and split between train and test sets from keras.datasets import fashion_mnist (x_train, y_train), (x_test, y_test) = fashion_mnist.load_data() x_train = x_train.reshape(-1, 28, 28, 1).astype('float32') / 255. x_test = x_test.reshape(-1, 28, 28, 1).astype('float32') / 255. y_train = to_categorical(y_train.astype('float32')) y_test = to_categorical(y_test.astype('float32')) return (x_train, y_train), (x_test, y_test)
Example #14
Source File: create_data.py From active-learning with Apache License 2.0 | 5 votes |
def get_keras_data(dataname): """Get datasets using keras API and return as a Dataset object.""" if dataname == 'cifar10_keras': train, test = cifar10.load_data() elif dataname == 'cifar100_coarse_keras': train, test = cifar100.load_data('coarse') elif dataname == 'cifar100_keras': train, test = cifar100.load_data() elif dataname == 'mnist_keras': train, test = mnist.load_data() else: raise NotImplementedError('dataset not supported') X = np.concatenate((train[0], test[0])) y = np.concatenate((train[1], test[1])) if dataname == 'mnist_keras': # Add extra dimension for channel num_rows = X.shape[1] num_cols = X.shape[2] X = X.reshape(X.shape[0], 1, num_rows, num_cols) if K.image_data_format() == 'channels_last': X = X.transpose(0, 2, 3, 1) y = y.flatten() data = Dataset(X, y) return data # TODO(lishal): remove regular cifar10 dataset and only use dataset downloaded # from keras to maintain image dims to create tensor for tf models # Requires adding handling in run_experiment.py for handling of different # training methods that require either 2d or tensor data.
Example #15
Source File: utils.py From AnomalyDetectionTransformations with MIT License | 5 votes |
def load_mnist(): (X_train, y_train), (X_test, y_test) = mnist.load_data() X_train = normalize_minus1_1(cast_to_floatx(np.pad(X_train, ((0, 0), (2, 2), (2, 2)), 'constant'))) X_train = np.expand_dims(X_train, axis=get_channels_axis()) X_test = normalize_minus1_1(cast_to_floatx(np.pad(X_test, ((0, 0), (2, 2), (2, 2)), 'constant'))) X_test = np.expand_dims(X_test, axis=get_channels_axis()) return (X_train, y_train), (X_test, y_test)
Example #16
Source File: utils.py From Matrix-Capsules-EM-Tensorflow with Apache License 2.0 | 5 votes |
def load_cifar100(is_training): # https://keras.io/datasets/ # https://www.cs.toronto.edu/~kriz/cifar.html: # "Each image comes with a 'fine' label (the class to which it belongs) # and a 'coarse' label (the superclass to which it belongs)." assert(K.image_data_format() == 'channels_last') if is_training: return cifar100.load_data(label_mode='fine')[0] else: return cifar100.load_data(label_mode='fine')[1]
Example #17
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_mnist(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = mnist.load_data() assert len(x_train) == len(y_train) == 60000 assert len(x_test) == len(y_test) == 10000
Example #18
Source File: utils.py From AnomalyDetectionTransformations with MIT License | 5 votes |
def load_cifar100(label_mode='coarse'): (X_train, y_train), (X_test, y_test) = cifar100.load_data(label_mode=label_mode) X_train = normalize_minus1_1(cast_to_floatx(X_train)) X_test = normalize_minus1_1(cast_to_floatx(X_test)) return (X_train, y_train), (X_test, y_test)
Example #19
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_reuters(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = reuters.load_data() assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) assert len(x_train) + len(x_test) == 11228 (x_train, y_train), (x_test, y_test) = reuters.load_data(maxlen=10) assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) word_index = reuters.get_word_index() assert isinstance(word_index, dict)
Example #20
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_cifar(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = cifar10.load_data() assert len(x_train) == len(y_train) == 50000 assert len(x_test) == len(y_test) == 10000 (x_train, y_train), (x_test, y_test) = cifar100.load_data('fine') assert len(x_train) == len(y_train) == 50000 assert len(x_test) == len(y_test) == 10000 (x_train, y_train), (x_test, y_test) = cifar100.load_data('coarse') assert len(x_train) == len(y_train) == 50000 assert len(x_test) == len(y_test) == 10000
Example #21
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_boston_housing(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = boston_housing.load_data() assert len(x_train) == len(y_train) assert len(x_test) == len(y_test)
Example #22
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_imdb(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = imdb.load_data() (x_train, y_train), (x_test, y_test) = imdb.load_data(maxlen=40) assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) word_index = imdb.get_word_index() assert isinstance(word_index, dict)
Example #23
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_mnist(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = mnist.load_data() assert len(x_train) == len(y_train) == 60000 assert len(x_test) == len(y_test) == 10000
Example #24
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_reuters(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = reuters.load_data() assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) assert len(x_train) + len(x_test) == 11228 (x_train, y_train), (x_test, y_test) = reuters.load_data(maxlen=10) assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) word_index = reuters.get_word_index() assert isinstance(word_index, dict)
Example #25
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_cifar(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = cifar10.load_data() assert len(x_train) == len(y_train) == 50000 assert len(x_test) == len(y_test) == 10000 (x_train, y_train), (x_test, y_test) = cifar100.load_data('fine') assert len(x_train) == len(y_train) == 50000 assert len(x_test) == len(y_test) == 10000 (x_train, y_train), (x_test, y_test) = cifar100.load_data('coarse') assert len(x_train) == len(y_train) == 50000 assert len(x_test) == len(y_test) == 10000
Example #26
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_boston_housing(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = boston_housing.load_data() assert len(x_train) == len(y_train) assert len(x_test) == len(y_test)
Example #27
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_imdb(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = imdb.load_data() (x_train, y_train), (x_test, y_test) = imdb.load_data(maxlen=40) assert len(x_train) == len(y_train) assert len(x_test) == len(y_test) word_index = imdb.get_word_index() assert isinstance(word_index, dict)
Example #28
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_mnist(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = mnist.load_data() assert len(x_train) == len(y_train) == 60000 assert len(x_test) == len(y_test) == 10000
Example #29
Source File: load_cifar.py From Model-Compression-Keras with MIT License | 5 votes |
def load_data(data='c10'): if data == 'c10': print('Loading CIFAR-10 dataset') nb_classes = 10 (x_train, y_train), (x_test, y_test) = cifar10.load_data() x_train = x_train.astype(np.float32) x_test = x_test.astype(np.float32) mean = np.array([125.3, 123.0, 113.9]) std = np.array([63.0, 62.1, 66.7]) x_train -= mean x_train /= std x_test -= mean x_test /= std else: print('Loading CIFAR-100 dataset') nb_classes = 100 (x_train, y_train), (x_test, y_test) = cifar100.load_data() x_train = x_train.astype(np.float32) x_test = x_test.astype(np.float32) mean = np.array([129.3, 124.1, 112.4]) std = np.array([68.2, 65.4, 70.4]) x_train -= mean x_train /= std x_test -= mean x_test /= std return x_train, y_train, x_test, y_test, nb_classes
Example #30
Source File: test_datasets.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_boston_housing(): # only run data download tests 20% of the time # to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: (x_train, y_train), (x_test, y_test) = boston_housing.load_data() assert len(x_train) == len(y_train) assert len(x_test) == len(y_test)