LAB_Quiz2
LAB_Quiz2
In this practical work, you will train a convolutional neural network model to classify images
of clothing, like sneakers and shirts. The database that we are going to use is the Fashion
MNIST dataset, which contains 70,000 grayscale images in 10 categories. The grayscale images
show individual articles of clothing at low resolution (28 by 28 pixels), as seen here:
Fashion MNIST is intended as a drop-in replacement for the classic MNIST dataset—often
used as the "Hello, World" of machine learning programs for computer vision. The MNIST
dataset contains images of handwritten digits (0, 1, 2, etc) in an identical format to the articles
of clothing we'll use here.
We will use 60,000 images to train the network and 10,000 images to evaluate how accurately
the network learned to classify images. You can access the Fashion MNIST directly from
TensorFlow.
fashion_mnist = tf.keras.datasets.fashion_mnist
It is very important to explore the format of the dataset before we build and train the
model.
a. Simply inspect the shape of the train_images and test_images by executing:
train_images.shape and test_images.shape. Write down the shapes of both
datasets.
c. Finally, just type train_labels in your console to view how class labels are stored.
You will get the following indicating that the label of classes is an integer between
0 and 9: array([9, 0, 0, ..., 3, 0, 5], dtype=uint8)
d. Create the list class_names and store in it the names of the 10 classes.
3. Build the architecture of the CNN such as it composed of 2 convolution layers and
2 fully-connected layers. We are going to use 32 filters of size 3x3 (feature
detectors) at the first convolution layer and 64 filters of size 3x3 at the second
convolution layer.
c. What optimization technique and what loss function are best suited for this
problem?
d. Schematize the architecture of the CNN and indicate the size of images as
well as the number of channels at the output of each convolution layer.
Specify the number of features at each fully connected layer (c.f. schema
provided in TensorFlow lab).
plt.imshow(img, cmap=plt.cm.binary)
predicted_label = np.argmax(predictions_array)
if predicted_label == true_label:
color = 'blue'
else:
color = 'red'
thisplot[predicted_label].set_color('red')
thisplot[true_label].set_color('blue')
Then look at the predictions provided by the CNN for 0 th and 12th images of the test
dataset:
i = 0
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predictions, np.argmax(test_labels,axis=1), test_images)
plt.subplot(1,2,2)
plot_value_array(i, predictions, np.argmax(test_labels,axis=1))
plt.show()
i = 12
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predictions, np.argmax(test_labels,axis=1), test_images)
plt.subplot(1,2,2)
plot_value_array(i, predictions, np.argmax(test_labels,axis=1))
plt.show()