Python keras.datasets.cifar10.load_data() Examples
The following are 30
code examples of keras.datasets.cifar10.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.cifar10
, or try the search function
.
Example #1
Source File: cnn.py From DeepFashion with Apache License 2.0 | 7 votes |
def load_and_preprocess_data_3(): # The data, shuffled and split between train and test sets: (X_train, y_train), (x_test, y_test) = cifar10.load_data() logging.debug('X_train shape: {}'.format(X_train.shape)) logging.debug('train samples: {}'.format(X_train.shape[0])) logging.debug('test samples: {}'.format(x_test.shape[0])) # Convert class vectors to binary class matrices. y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes) X_train = X_train.astype('float32') x_test = x_test.astype('float32') X_train /= 255 x_test /= 255 input_shape = X_train[0].shape logging.debug('input_shape {}'.format(input_shape)) input_shape = X_train.shape[1:] logging.debug('input_shape {}'.format(input_shape)) return X_train, x_test, y_train, y_test, input_shape
Example #2
Source File: datasets.py From super-simple-distributed-keras with MIT License | 7 votes |
def get_mnist(): """Retrieve the MNIST dataset and process the data.""" # Set defaults. nb_classes = 10 batch_size = 128 input_shape = (784,) # Get the data. (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 784) x_test = x_test.reshape(10000, 784) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_test /= 255 # convert class vectors to binary class matrices y_train = to_categorical(y_train, nb_classes) y_test = to_categorical(y_test, nb_classes) return (nb_classes, batch_size, input_shape, x_train, x_test, y_train, y_test)
Example #3
Source File: utils.py From RelativisticGAN-Tensorflow with MIT License | 6 votes |
def load_cifar10(size=64) : (train_data, train_labels), (test_data, test_labels) = cifar10.load_data() train_data = normalize(train_data) test_data = normalize(test_data) x = np.concatenate((train_data, test_data), axis=0) # y = np.concatenate((train_labels, test_labels), axis=0).astype(np.int) seed = 777 np.random.seed(seed) np.random.shuffle(x) # np.random.seed(seed) # np.random.shuffle(y) x = np.asarray([scipy.misc.imresize(x_img, [size, size]) for x_img in x]) return x
Example #4
Source File: train.py From neural-network-genetic-algorithm with MIT License | 6 votes |
def get_mnist(): """Retrieve the MNIST dataset and process the data.""" # Set defaults. nb_classes = 10 batch_size = 128 input_shape = (784,) # Get the data. (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 784) x_test = x_test.reshape(10000, 784) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_test /= 255 # convert class vectors to binary class matrices y_train = to_categorical(y_train, nb_classes) y_test = to_categorical(y_test, nb_classes) return (nb_classes, batch_size, input_shape, x_train, x_test, y_train, y_test)
Example #5
Source File: train.py From neural-network-genetic-algorithm with MIT License | 6 votes |
def get_cifar10(): """Retrieve the CIFAR dataset and process the data.""" # Set defaults. nb_classes = 10 batch_size = 64 input_shape = (3072,) # Get the data. (x_train, y_train), (x_test, y_test) = cifar10.load_data() x_train = x_train.reshape(50000, 3072) x_test = x_test.reshape(10000, 3072) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_test /= 255 # convert class vectors to binary class matrices y_train = to_categorical(y_train, nb_classes) y_test = to_categorical(y_test, nb_classes) return (nb_classes, batch_size, input_shape, x_train, x_test, y_train, y_test)
Example #6
Source File: 3leveldcnet.py From Multi-level-DCNet with GNU General Public License v3.0 | 6 votes |
def load_dataset(): # Load the dataset from Keras from keras.datasets import cifar10 (x_train, y_train), (x_test, y_test) = cifar10.load_data() # Preprocessing the dataset x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train= preprocess_input(x_train) x_test= preprocess_input(x_test) x_train = x_train.reshape(-1, 32, 32, 3).astype('float32') x_test = x_test.reshape(-1, 32, 32, 3).astype('float32') 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 #7
Source File: mobilenet_pseudo_cifar.py From Pseudo-Label-Keras with MIT License | 6 votes |
def __init__(self, model, n_labeled_sample, batch_size): self.n_labeled_sample = n_labeled_sample self.batch_size = batch_size self.model = model self.n_classes = 10 # labeled_unlabeledの作成 (X_train, y_train), (self.X_test, self.y_test) = cifar10.load_data() indices = np.arange(X_train.shape[0]) np.random.shuffle(indices) self.X_train_labeled = X_train[indices[:n_labeled_sample]] self.y_train_labeled = y_train[indices[:n_labeled_sample]] self.X_train_unlabeled = X_train[indices[n_labeled_sample:]] self.y_train_unlabeled_groundtruth = y_train[indices[n_labeled_sample:]] # unlabeledの予測値 self.y_train_unlabeled_prediction = np.random.randint( 10, size=(self.y_train_unlabeled_groundtruth.shape[0], 1)) # steps_per_epoch self.train_steps_per_epoch = X_train.shape[0] // batch_size self.test_stepes_per_epoch = self.X_test.shape[0] // batch_size # unlabeledの重み self.alpha_t = 0.0 # labeled/unlabeledの一致率推移 self.unlabeled_accuracy = [] self.labeled_accuracy = []
Example #8
Source File: pseudo_pretrain_cifar.py From Pseudo-Label-Keras with MIT License | 6 votes |
def __init__(self, model, n_labeled_sample, batch_size): self.n_labeled_sample = n_labeled_sample self.batch_size = batch_size self.model = model self.n_classes = 10 # labeled_unlabeledの作成 (X_train, y_train), (self.X_test, self.y_test) = cifar10.load_data() indices = np.arange(X_train.shape[0]) np.random.shuffle(indices) self.X_train_labeled = X_train[indices[:n_labeled_sample]] self.y_train_labeled = y_train[indices[:n_labeled_sample]] self.X_train_unlabeled = X_train[indices[n_labeled_sample:]] self.y_train_unlabeled_groundtruth = y_train[indices[n_labeled_sample:]] # unlabeledの予測値 self.y_train_unlabeled_prediction = np.random.randint( 10, size=(self.y_train_unlabeled_groundtruth.shape[0], 1)) # steps_per_epoch self.train_steps_per_epoch = X_train.shape[0] // batch_size self.test_stepes_per_epoch = self.X_test.shape[0] // batch_size # unlabeledの重み self.alpha_t = 0.05 # labeled/unlabeledの一致率推移 self.unlabeled_accuracy = [] self.labeled_accuracy = []
Example #9
Source File: mobilenet_transfer_pseudo_cifar.py From Pseudo-Label-Keras with MIT License | 6 votes |
def __init__(self, model, n_labeled_sample, batch_size): self.n_labeled_sample = n_labeled_sample self.batch_size = batch_size self.model = model self.n_classes = 10 # labeled_unlabeledの作成 (X_train, y_train), (self.X_test, self.y_test) = cifar10.load_data() indices = np.arange(X_train.shape[0]) np.random.shuffle(indices) self.X_train_labeled = X_train[indices[:n_labeled_sample]] self.y_train_labeled = y_train[indices[:n_labeled_sample]] self.X_train_unlabeled = X_train[indices[n_labeled_sample:]] self.y_train_unlabeled_groundtruth = y_train[indices[n_labeled_sample:]] # unlabeledの予測値 self.y_train_unlabeled_prediction = np.random.randint( 10, size=(self.y_train_unlabeled_groundtruth.shape[0], 1)) # steps_per_epoch self.train_steps_per_epoch = X_train.shape[0] // batch_size self.test_stepes_per_epoch = self.X_test.shape[0] // batch_size # unlabeledの重み self.alpha_t = 0.0 # labeled/unlabeledの一致率推移 self.unlabeled_accuracy = [] self.labeled_accuracy = []
Example #10
Source File: datasets.py From super-simple-distributed-keras with MIT License | 6 votes |
def get_cifar10(): """Retrieve the CIFAR dataset and process the data.""" # Set defaults. nb_classes = 10 batch_size = 64 input_shape = (3072,) # Get the data. (x_train, y_train), (x_test, y_test) = cifar10.load_data() x_train = x_train.reshape(50000, 3072) x_test = x_test.reshape(10000, 3072) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_test /= 255 # convert class vectors to binary class matrices y_train = to_categorical(y_train, nb_classes) y_test = to_categorical(y_test, nb_classes) return (nb_classes, batch_size, input_shape, x_train, x_test, y_train, y_test)
Example #11
Source File: pseudo_cifar.py From Pseudo-Label-Keras with MIT License | 6 votes |
def __init__(self, model, n_labeled_sample, batch_size): self.n_labeled_sample = n_labeled_sample self.batch_size = batch_size self.model = model self.n_classes = 10 # labeled_unlabeledの作成 (X_train, y_train), (self.X_test, self.y_test) = cifar10.load_data() indices = np.arange(X_train.shape[0]) np.random.shuffle(indices) self.X_train_labeled = X_train[indices[:n_labeled_sample]] self.y_train_labeled = y_train[indices[:n_labeled_sample]] self.X_train_unlabeled = X_train[indices[n_labeled_sample:]] self.y_train_unlabeled_groundtruth = y_train[indices[n_labeled_sample:]] # unlabeledの予測値 self.y_train_unlabeled_prediction = np.random.randint( 10, size=(self.y_train_unlabeled_groundtruth.shape[0], 1)) # steps_per_epoch self.train_steps_per_epoch = X_train.shape[0] // batch_size self.test_stepes_per_epoch = self.X_test.shape[0] // batch_size # unlabeledの重み self.alpha_t = 0.0 # labeled/unlabeledの一致率推移 self.unlabeled_accuracy = [] self.labeled_accuracy = []
Example #12
Source File: utils.py From Self-Attention-GAN-Tensorflow with MIT License | 6 votes |
def load_mnist(size=64): (train_data, train_labels), (test_data, test_labels) = mnist.load_data() train_data = normalize(train_data) test_data = normalize(test_data) x = np.concatenate((train_data, test_data), axis=0) # y = np.concatenate((train_labels, test_labels), axis=0).astype(np.int) seed = 777 np.random.seed(seed) np.random.shuffle(x) # np.random.seed(seed) # np.random.shuffle(y) # x = np.expand_dims(x, axis=-1) x = np.asarray([scipy.misc.imresize(x_img, [size, size]) for x_img in x]) x = np.expand_dims(x, axis=-1) return x
Example #13
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 #14
Source File: utils.py From Self-Attention-GAN-Tensorflow with MIT License | 6 votes |
def load_cifar10(size=64) : (train_data, train_labels), (test_data, test_labels) = cifar10.load_data() train_data = normalize(train_data) test_data = normalize(test_data) x = np.concatenate((train_data, test_data), axis=0) # y = np.concatenate((train_labels, test_labels), axis=0).astype(np.int) seed = 777 np.random.seed(seed) np.random.shuffle(x) # np.random.seed(seed) # np.random.shuffle(y) x = np.asarray([scipy.misc.imresize(x_img, [size, size]) for x_img in x]) return x
Example #15
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 #16
Source File: utils.py From RelativisticGAN-Tensorflow with MIT License | 6 votes |
def load_mnist(size=64): (train_data, train_labels), (test_data, test_labels) = mnist.load_data() train_data = normalize(train_data) test_data = normalize(test_data) x = np.concatenate((train_data, test_data), axis=0) # y = np.concatenate((train_labels, test_labels), axis=0).astype(np.int) seed = 777 np.random.seed(seed) np.random.shuffle(x) # np.random.seed(seed) # np.random.shuffle(y) # x = np.expand_dims(x, axis=-1) x = np.asarray([scipy.misc.imresize(x_img, [size, size]) for x_img in x]) x = np.expand_dims(x, axis=-1) return x
Example #17
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 #18
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 #19
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 #20
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 #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_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 #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_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 #27
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 #28
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 #29
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 #30
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)