In [1]:
import tensorflow as tf
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(512, activation=tf.nn.relu),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)


Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434==============================] - 15s 1us/step
WARNING: Logging before flag parsing goes to stderr.
W0130 07:40:29.433949 140009686058432 deprecation.py:506] From /usr/lib/python3.7/site-packages/tensorflow/python/ops/init_ops.py:1253: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
W0130 07:40:29.456531 140009686058432 deprecation.py:506] From /usr/lib/python3.7/site-packages/tensorflow/python/keras/layers/core.py:144: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
W0130 07:40:29.484415 140009686058432 deprecation.py:506] From /usr/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py:123: calling Zeros.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
Epoch 1/5
60000/60000==============================] - 5s 83us/sample - loss: 0.2173 - acc: 0.9358
Epoch 2/5
60000/60000==============================] - 5s 81us/sample - loss: 0.0985 - acc: 0.9697
Epoch 3/5
60000/60000==============================] - 5s 81us/sample - loss: 0.0697 - acc: 0.9780
Epoch 4/5
60000/60000==============================] - 5s 81us/sample - loss: 0.0554 - acc: 0.9825
Epoch 5/5
60000/60000==============================] - 5s 81us/sample - loss: 0.0434 - acc: 0.9860
10000/10000==============================] - 0s 30us/sample - loss: 0.0604 - acc: 0.9812
Out[1]:
[0.060414932515623514, 0.9812]

In [ ]: