The code

First, here are the required imports:

import tensorflow as tfimport numpy as np

Next, we acquire and preprocess the data. Notice that fashion_mnist is handily present in tf.keras.datasets. The x values in the dataset are in the form of integer NumPy arrays, each element being in the range 0 to 255, representing the grayscale value at each of the pixels in the 28 x 28 pixels fashion image. For training purposes, these values must be converted into floats in the range of 0 to 1. The y values are in the form of unsigned 8-bit integers (uint8) and must be converted into 32-bit integers (int32), again for use by the Estimator.

The learning rate is set to quite a small value, although this hyperparameter value may be experimented with: ...

Get TensorFlow 2.0 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.