Skip to content

Instantly share code, notes, and snippets.

@mgomes
Created March 19, 2019 03:05
Show Gist options
  • Save mgomes/36f77bd77f1fba2f04c5e5a8937f37eb to your computer and use it in GitHub Desktop.
Save mgomes/36f77bd77f1fba2f04c5e5a8937f37eb to your computer and use it in GitHub Desktop.
CNN With MNIST
import tensorflow as tf
print(tf.__version__)
mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=10)
test_loss, test_acc = model.evaluate(test_images, test_labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment