Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Created February 26, 2020 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakshay-arora/f151a50db36418aa4d1b19ebcfb8a93e to your computer and use it in GitHub Desktop.
Save lakshay-arora/f151a50db36418aa4d1b19ebcfb8a93e to your computer and use it in GitHub Desktop.
# importing the libraries
from tensorflow.keras import datasets
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# loading dataset
(train_images, train_labels), (test_images, test_labels) = datasets.mnist.load_data()
# For training, we will use 10000 images
# And we will test our model on 1000 images
train_labels = train_labels[:10000]
test_labels = test_labels[:1000]
train_images = train_images[:10000].reshape(-1, 28 * 28) / 255.0
test_images = test_images[:1000].reshape(-1, 28 * 28) / 255.0
# define the model
model = Sequential()
model.add(Dense(512, activation='relu', input_shape=(784,)))
model.add(Dense(10,activation='softmax'))
# compile the model
model.compile(optimizer='adam',loss= 'sparse_categorical_crossentropy',metrics=['accuracy'])
# model summary
model.summary()
# Train the model with the new callback
model.fit(train_images, train_labels, epochs=10, validation_data=(test_images,test_labels))
# Evaluate the model
loss, acc = model.evaluate(test_images, test_labels, verbose=2)
print("model, accuracy: {:5.2f}%".format(100*acc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment