Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECE4179

Deep Learning and Neural Networks

Assignment 2

Due: 16/10/2022, 11:55pm

General Comments.

• Please submit your report along with the code (Jupyter notebook is preferred) as a single zip file. The minimum your submission has will be:  report (as PDF), code (as Jupyter notebook), and converted code (as .py file).

• Include your name and student number in the filename for both the zip file and PDF. Do not send doc/docx files.

• Include your name and email address on the report and use a single column format when you prepare your report.

• Please ensure all of your results are included in your report. Marking is based on what is in the report. This includes plots, tables, code screen-shots etc.

• Make sure you answer questions in full and support any discussions with relevant additional informa- tion/experiments if necessary.

Late submission. Late submission of the assignment will incur a penalty of 10% for each day late. That is with one day delay, the maximum mark you can get from the assignment is 90 out of 100, so if you score 99, we will (sadly) give you 90. Assignments submitted with more than a week delay will not be assessed. Please apply for special consideration for late submission as soon as possible (e .g ., documented serious illness).

Note from ECE4179/5179/6179 Team. The nature of assignments in ECE4179/5179/6179 is different from many other courses.  Here, we may not have a single solution to a problem.  Be creative in your work and feel free to explore beyond questions.

Good Luck

Question:

1

2

3

4

5

6

Total

Points:

10

5

20

30

15

20

100

Score:

Note:  The DAE task has bonus marks that will be applied to your continuous assessment (2% of unit

total)

Calculation Exercises

For the calculation exercises, ensure that you document any calculations/working-out. You can use a word editor to format your answers properly. You will receive a 0 if you do not provide calculations/working-out.

Multilayer Perceptron (MLP)

1.  Consider the MLP network in Figure 1.   Table 1 shows the value of each of the parameters of the network. The activation functions for all neurons are shown in Table 2. The neurons in the input layer, i. e . neuron 1 and neuron 2, do not use any activation function and simply pass in the input to the network.  All the neurons in the hidden layer use a ReLU activation function,  i. e ., a3 (x) = a4 (x) = a5 (x) = ReLU(x) = max(0,x). The neuron in the output layer uses a Sigmoid activation function, i. e ., a6 (x) = σ(x) = 1/ (1 + exp(x)). Answer the following questions.



Figure 1: An MLP with one hidden layer (Question 1).

Parameter

Value

1 ,3

0.1

1 ,4

0.3

1 ,5

-0.2

2 ,3

0.6

2 ,4

0.4

2 ,5

0.0

3 ,6

-0.5

4 ,6

-0.3

5 ,6

0.8

Table 1: Parameter values of the MLP (Figure 1).

Neuron

Activation function

1

None

2

None

3

ReLU

4

ReLU

5

ReLU

6

Sigmoid

Table 2: Activation functions of the MLP (Figure 1).

1.1. [2 points]  Compute the output of the network for x = (x1 ,x2 )= (1, 2)

1.2. [1 point]  Assume the label of x = (x1 ,x2 )= (1, 2)is y = 0. If we use the Binary Cross Entropy

(BCE) loss to train our MLP, what will be the value of the loss for (x,y)?

1.3. [1 point]  Now assume the label of x = (x1 ,x2 )= (1, 2)is y = 1.  For BCE loss, what will be

the value of the loss for  (x,y)?  Do you expect the loss to be bigger or smaller compared to the previous part? Why? Explain your answer and your observation.

1.4. [3 points]  Assume the learning rate of the SGD is lr = 0 .01. For a training sample x = (x1 ,x2 )= (1, 2)and y = 1, obtain the updated value of w3 ,6 .

1.5. [3 points]  Using the assumptions from the previous part  (i. e .,  the learning rate of the  SGD is lr = 0.01, the training sample is x = (x1 ,x2 )= (1, 2)and y = 1), obtain the updated value of w2 ,5 .

Activation Function

2.  [5 points]  Consider the following activation function:

( exp(x) exp(x), 1 x 1 ,

z = exp(1) exp(1),    x > 1 ,                                                             (1)

(exp(−1) − exp(1),    x < −1 .

We stack 1,000 of z, to form z1000  = z z ◦ · · · ◦ z, where ◦ denotes function composition. What would

be the response of z1000  to x ∈ R? You need to discuss the behaviour of z1000 (x) for x ∈ R. We plot the activation function in Equation (1) along with the 45-degree line in Figure 2 for your convenience.

2

1

0

x

1

2

Figure 2: Activation function for Question 2.

Coding Exercises

It is recommended that you code up these exercises with the provided skeleton notebook.  The results you obtain from the notebook need to be placed into a written report (ie.  word doc), and discussions need to be added within this report.  Remember to submit the PDF version of your report (and also your python notebook and .py file).

Denoising autoencoder (DAE) with MNIST

Whenever you measure a signal,  noise creeps in.   Denoising  (aka noise reduction) is the process of removing noise from a signal and is a profound and open engineering problem. In this exercise, you will learn and implement a Denoising AutoEncoder (DAE) to remove additive Gaussian noise from images.

Autoencoders. An autoencoder is a neural model that is trained to attempt to copy its input to its output.  Internally, it has a hidden layer z that describes a code used to represent the input.  To be precise, an autoencoder realizes two functions/networks, a function fenc  to transform the input x ∈ Rn to a new representation z ∈ Rm , followed by a function fdec , which converts the new representation z back into the original representation.  We call these two functions the encoder and the decoder (see Figure 3 for an illustration).

You may ask yourself if an autoencoder succeeds in simply learning to set fdec (fenc (x)) = x everywhere, then what  is it useful  for?   The short  answer to that  is,  the new representation z learned by the autoencoder captures useful information about the structure of the data in a compact form that is friendly to ML algorithms. But that is not all. In deep learning, we can borrow the idea of autoencoding and design many useful solutions, denoising being one.

DAE. In a DAE, instead of showing x to the model, we show a noisy input as = x + ϵ . The noise ϵ is task specific. If you are working with MRI images, this noise should model the noise of an MRI machine. If you are working on speech signals, the noise could be the babble noise recorded in a cafe. What you will ask your DAE to do is now to generate clean samples, i. e . = x (see Figure 3 for an illustration). So in essence, knowing about the problem and associated noise will enable you to simulate it. This will give you a very task-specific solution, which is in many cases desirable.

3.  [20 points] In this section, you will implement a DAE to reduce the amount of noise within the dataset. Table 3 shows the hyperparameters and network architecture that you will be using.

Parameter

Value

Description

λ 1e-3 (0.001) Learning rate

Weight decay 1e-5 (0.00001) Weight decay in optimizer

# Encoder layer(s)               1 The number of layers in the encoder

# Neurons {128} Number of neurons in the encoder

# Decoder layer(s) {???} The number of layers in the decoder

# Neurons {???} Number of neurons in the decoder

Activation function ReLU Use Fmodule (Functional)

Loss function ??? For the entire DAE

Optimiser Adam For the entire DAE

Table 3: Hyperparameters for the DAE model. Note that some of the hyperparameters have been replaced with ???”

The tasks for this section are the following:

• Task D1: Create the dataloader for MNIST. Visualise a few samples.

Figure 3: Top. An autoencoder is comprised of two subnetworks, an encoder and a decoder. In its vanilla form, the goal is to extract useful strcuture and information about the input. Bottom. In a DAE, you feed the network with a noisy input and train the model to produce clean outputs.

• Task D2: Design your network architecture for the DAE.

• Task D3: Train and evaluate the DAE results.

• Task D4: Visualise predictions along with the clean data.

• Task D5: Discuss both the DAE training results and the visualised predictions of the outputs.

Note: To create the noisy data, you will inject random noise into the data samples during the training step within your network.  This is shown in the skeleton code.  You will also need to reshape the output predictions to visualize the output image.

Bonus marks [2% of unit total]

For the DAE section, you can earn an additional 2% (out of 50%) towards your continuous assessment. Your continuous assessment mark will not exceed the total maximum mark (it does not add to your overall marks).

To earn the bonus marks, you must complete at least two of the given ideas to some satisfactory degree. The ideas/improvements must be related to auto encoders AND the MNIST dataset.  If you choose to implement your own improvement, it must be something worthwhile (not just simply changing λ for example). The results must be shown, and if you end up any external references, please cite it here and in your report.

Here are a few ideas to choose from:

• Improve the design of the network (hence improve the performance)

• Handle various noise types (speckle noise, Gaussian noise, inpainting etc.)

• Instead of downsampling to a smaller latent space, can you increase it while reducing noise?

• Any other improvements related to this task

MLP vs. CNN

4.  [30 points]  This section requires you to compare MLPs against CNNs on an image classification problem. We will be using the SVHN (Street View House Number) dataset.  This section assumes you have the fundamental principles in applying the modelling process. You will need to create your dataloaders and two models (one MLP, one CNN). You will also be comparing their performance in several ways.  The tasks are split as follows:

• Task C1 Download the SVHN Train and Test datasets.

• Task C2 Visualise a few training samples.

• Task C3 Define an MLP and a CNN model.

• Task C4 Train and evaluate both models.

• Task C5 Visualise the results for both using validation accuracies.

• Task C6 Discuss the performance and number of parameters used for each model.

MLP - SVHN

The hyperparameters for the MLP model can be found in Table 4. Train your MLP model and compare it against the CNN version.