Keras is TensorFlow’s high-level API for defining, training, evaluating, and saving neural-network models. It turns a prepared dataset into an executable model workflow. section 8.1.1
A typical Keras workflow:
- Load MNIST through tf.keras.datasets and inspect its NumPy arrays. section 8.1.1
- Normalize pixel values from 0–255 to 0–1. section 8.1.1
- Define a Sequential network with Flatten, Dense, and Dropout layers. section 8.1.1
- Compile with an optimizer, loss function, and accuracy metric, then fit and evaluate it. section 8.1.1
- Save the trained model and reload it for later use. section 8.1.1
MNIST classifier
A compact model flattens 28×28 images, applies a 128-unit ReLU layer and dropout, then predicts ten digit classes with softmax. Five epochs reach about 97.9% test accuracy. section 8.1.1
Listing 8.8 The sequential model definition
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') ])
Inspect the concrete Sequential architecture used for the image classifier. section 8.1.1





