Last active
April 22, 2020 15:18
-
-
Save Ending2015a/c0c5e44b430e24056e96ec96794389cf to your computer and use it in GitHub Desktop.
tensorflow mnist example from https://www.tensorflow.org/overview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import time | |
import multiprocessing as mp | |
mnist = tf.keras.datasets.mnist | |
(x_train, y_train),(x_test, y_test) = mnist.load_data() | |
x_train, x_test = x_train / 255.0, x_test / 255.0 | |
model = tf.keras.models.Sequential([ | |
tf.keras.layers.Flatten(input_shape=(28, 28)), | |
tf.keras.layers.Dense(128, activation='relu'), | |
tf.keras.layers.Dropout(0.2), | |
tf.keras.layers.Dense(10, activation='softmax') | |
]) | |
model.compile(optimizer='adam', | |
loss='sparse_categorical_crossentropy', | |
metrics=['accuracy']) | |
start = time.time() | |
epochs = 5 | |
model.fit(x_train, y_train, epochs=epochs, workers=mp.cpu_count(), use_multiprocessing=True) | |
end = time.time() | |
print('Run epochs: {}'.format(epochs)) | |
print('Total run time: {} s'.format(end-start)) | |
print('Avg run time: {} s/epoch'.format( (end-start)/epochs )) | |
model.evaluate(x_test, y_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment