Python tensorflow.python.keras.datasets.mnist.load_data() Examples
The following are 6
code examples of tensorflow.python.keras.datasets.mnist.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
tensorflow.python.keras.datasets.mnist
, or try the search function
.
Example #1
Source File: mnist.py From Gun-Detector with Apache License 2.0 | 6 votes |
def _make_dataset(self): (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) dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)) dataset = dataset.repeat() dataset = dataset.shuffle(self.batch_size * 3) dataset = dataset.batch(self.batch_size) def _map_fn(image, label): image = tf.to_float(image) / 255. label.set_shape([self.batch_size]) label = tf.cast(label, dtype=tf.int32) label_onehot = tf.one_hot(label, 10) image = tf.reshape(image, [self.batch_size, 28, 28, 1]) return common.ImageLabelOnehot( image=image, label=label, label_onehot=label_onehot) self.dataset = dataset.map(_map_fn)
Example #2
Source File: mnist.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def _make_dataset(self): (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) dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)) dataset = dataset.repeat() dataset = dataset.shuffle(self.batch_size * 3) dataset = dataset.batch(self.batch_size) def _map_fn(image, label): image = tf.to_float(image) / 255. label.set_shape([self.batch_size]) label = tf.cast(label, dtype=tf.int32) label_onehot = tf.one_hot(label, 10) image = tf.reshape(image, [self.batch_size, 28, 28, 1]) return common.ImageLabelOnehot( image=image, label=label, label_onehot=label_onehot) self.dataset = dataset.map(_map_fn)
Example #3
Source File: mnist.py From models with Apache License 2.0 | 6 votes |
def _make_dataset(self): (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) dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)) dataset = dataset.repeat() dataset = dataset.shuffle(self.batch_size * 3) dataset = dataset.batch(self.batch_size) def _map_fn(image, label): image = tf.to_float(image) / 255. label.set_shape([self.batch_size]) label = tf.cast(label, dtype=tf.int32) label_onehot = tf.one_hot(label, 10) image = tf.reshape(image, [self.batch_size, 28, 28, 1]) return common.ImageLabelOnehot( image=image, label=label, label_onehot=label_onehot) self.dataset = dataset.map(_map_fn)
Example #4
Source File: mnist.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def _make_dataset(self): (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) dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)) dataset = dataset.repeat() dataset = dataset.shuffle(self.batch_size * 3) dataset = dataset.batch(self.batch_size) def _map_fn(image, label): image = tf.to_float(image) / 255. label.set_shape([self.batch_size]) label = tf.cast(label, dtype=tf.int32) label_onehot = tf.one_hot(label, 10) image = tf.reshape(image, [self.batch_size, 28, 28, 1]) return common.ImageLabelOnehot( image=image, label=label, label_onehot=label_onehot) self.dataset = dataset.map(_map_fn)
Example #5
Source File: io_api_test.py From autokeras with MIT License | 5 votes |
def test_io_api(tmp_path): num_instances = 100 (image_x, train_y), (test_x, test_y) = mnist.load_data() (text_x, train_y), (test_x, test_y) = utils.imdb_raw( num_instances=num_instances) image_x = image_x[:num_instances] text_x = text_x[:num_instances] structured_data_x = utils.generate_structured_data(num_instances=num_instances) classification_y = utils.generate_one_hot_labels(num_instances=num_instances, num_classes=3) regression_y = utils.generate_data(num_instances=num_instances, shape=(1,)) # Build model and train. automodel = ak.AutoModel( inputs=[ ak.ImageInput(), ak.TextInput(), ak.StructuredDataInput() ], outputs=[ak.RegressionHead(metrics=['mae']), ak.ClassificationHead(loss='categorical_crossentropy', metrics=['accuracy'])], directory=tmp_path, max_trials=2, tuner=ak.RandomSearch, seed=utils.SEED) automodel.fit([ image_x, text_x, structured_data_x ], [regression_y, classification_y], epochs=1, validation_split=0.2)
Example #6
Source File: utils.py From TF.Keras-Commonly-used-models with Apache License 2.0 | 5 votes |
def get_mnist_dataset(): (X_train, y_train), (X_test, y_test) = mnist.load_data() X_train = X_train.astype('float32') / 255 X_test = X_test.astype('float32') / 255 X_train = X_train[..., None] X_test = X_test[..., None] Y_train = keras.utils.to_categorical(y_train, 10) Y_test = keras.utils.to_categorical(y_test, 10) return (X_train, Y_train), (X_test, Y_test)