Complete the code to add a convolutional layer with 32 filters and a 3x3 kernel.
model.add(tf.keras.layers.Conv2D([1], (3, 3), activation='relu', input_shape=(28, 28, 1)))
The first convolutional layer typically uses 32 filters to extract features from the input images.
Complete the code to add a max pooling layer with pool size 2x2.
model.add(tf.keras.layers.MaxPooling2D(pool_size=[1]))MaxPooling2D with pool size (2, 2) reduces the spatial dimensions by half, helping to reduce computation and control overfitting.
Fix the error in the code to flatten the output before the dense layer.
model.add(tf.keras.layers.[1]())Flatten layer converts the 2D feature maps into a 1D vector so it can be fed into dense layers.
Fill both blanks to add a dense layer with 128 units and ReLU activation.
model.add(tf.keras.layers.Dense([1], activation=[2]))
A dense layer with 128 units and ReLU activation helps the model learn complex patterns.
Fill all three blanks to compile the model with Adam optimizer, sparse categorical crossentropy loss, and accuracy metric.
model.compile(optimizer=[1], loss=[2], metrics=[[3]])
Adam optimizer is popular for training CNNs. Sparse categorical crossentropy is used for multi-class classification with integer labels. Accuracy measures how often predictions are correct.