Question

Part 2: Deep Neural Networks (30 points)

The first part of this assignment covers contents from the lectures and lab sessions in Weeks 1

to 4. You are highly recommended to revise these materials before attempting this part.

You are going to work with the EMNIST dataset for image recognition task. This dataset can be

installed with the command pip install emnist. It has the exact same format as MNIST

(grayscale images of 28 x 28 pixels), but the images represent handwritten letters rather than

handwritten digits, so the problem is more challenging than MNIST.

Question 2.1 Load the EMIST Datasets and Process Data (4 points)

In this question, we use functions in the package emnist, namely

extract_training_samples and extract_test_samples, to load the training and

testing sets. We also want to encode labels using an ordinal encoding scheme.

The shape of training and testing data are (num_train, 28, 28) and (num_test, 28, 28), where

num_train and num_test are number of training and testing images respectively. We next

convert them to arrays of vectors which have shapes (num_train, 784) and (num_test, 784).

Question 2.2 Split Data into Training, Validation, and Testing Datasets (2 points)

You need to write the code to address the following requirements:

• Use 10% of training data for validation and the rest of training data for training.

Scale the pixels of training, validation and testing data to [0, 1].

You have now the separate training, validation, and testing sets for training your model.

Question 2.3 Visualize Some Images in the Training Set with Labels (5 points)

You are required to write the code to randomly show 36 images in training data (which is an

array of images) with labels as in the following figure.

W

W

M

R

K

U

W

0

W

X J

X

J

V

2 uu

Z

U

Se By

U

2

Q

N

X/nQuestion 2.4 Write Code for the Feed-Forward Neural Net Using TF 2.x (5 points)

We now develop a feed-forward neural network with the architecture 784 → 20 (RELU) →

40 (ReLU)→ 26 (Softmax). You can choose your own way to implement your network and an

optimizer of interest. You should train model in at least 20 epochs and evaluate the trained

model on the test set.

Question 2.5 Tune Hyperparameters with Grid Search (6 points)

Assume that you need to tune the number of neurons on the first and second hidden layers n₁ €

{20,40), n₂ € {20, 40}, and the used activation function act € {sigmoid, tanh, relu}. The network

has the architecture pattern 784 → n1 (act) → n2 (act)→ 26(softmax), where n1, n2, and act

are in their grides. Write the code to tune the hyperparameters n1, n2, and act. Note that you

can freely choose the optimizer and learning rate of interest for this task.

Question 2.6 Experimenting with the Label Smoothing Technique (8 points)

Implement the label smoothing technique by yourself. Note that you cannot use the built-in label

smoothing loss function in TF 2.x. Try the label smoothing technique with a = {0.1, 0.15,0.2}

and report the performances. You need to examine the label smoothing technique with the best

architecture obtained in Question 2.5.

Question image 1Question image 2