We can now move on to building the actual model. We will use a very simple architecture composed of two fully connected (also called dense) layers. Before we explore the architecture, let's have a look at the code. As you can see, Keras code is very concise:
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation='relu'))
model.add(tf.keras.layers.Dense(num_classes, activation='softmax'))
Since our model is a linear stack of layers, we start by calling the Sequential function. We then add each layer one after the other. Our model is composed of two fully connected layers. We build it layer by layer:
- Flatten: This will take the 2D matrix representing the image pixels and turn it into a 1D array. We need to do this before adding a fully connected layer. The 28 × 28 images are turned into a vector of size 784.
- Dense of size 128: This will turn the 784 pixel values into 128 activations...