Classifying clothing images with CNNs
As mentioned, the CNN model has two main components: the feature extractor composed of a set of convolutional and pooling layers, and the classifier backend similar to a regular neural network.
Architecting the CNN model
As the convolutional layer in Keras only takes in individual samples in three dimensions, we need to first reshape the data into four dimensions as follows:
>>> X_train = train_images.reshape((train_images.shape[0], 28, 28, 1))
>>> X_test = test_images.reshape((test_images.shape[0], 28, 28, 1))
>>> print(X_train.shape)
(60000, 28, 28, 1)
The first dimension is the number of samples, and the fourth dimension is the appended one representing the grayscale images.
Before we develop the CNN model, let's specify the random seed in TensorFlow for reproducibility:
>>> tf.random.set_seed(42)
We now import the necessary modules from Keras and initialize a Keras-based...