$30
CS 6364 Homework 5
All assignments MUST have your name, student ID, course name/number at the beginning of your documents.
Your homework MUST be submitted via Blackboard with file format and name convention as follows:
HW# Name writeup.pdf (for writing part)
HW# Name code.zip (for coding part)
If you have any questions, please contact me.
For the following questions, if you need a GPU to run, Google provide a free Jupyter notebook
environment that requires no setup and runs entirely in the cloud. Here is the link:
https://colab.research.google.com/notebooks/welcome.ipynb?hl=enscrollTo=5fCEDCU qrC0
Q1 (Regression) Implement a neural network to train a regression model for the Boston housing data set
https://towardsdatascience.com/linear-regression-on-boston-housing-dataset-f409b7e4a155
Split the dataset to a training set (70% samples) and a testing set (30% samples). Report the root mean
squared errors (RMSE) on the testing sets.
– You have to use PyTorch deep learning library.
– Two hidden layers: the first hidden layer must contain 16 units using ReLU activation function; the
second layer must contain 32 units using tanh activation function.
Q2 (Classification): Implement a neural network to train a classification model for the Titantic dataset:
https://blog.goodaudience.com/machine-learning-using-logistic-regression-in-python-with-code-ab3c7f5f3bed.
Split the dataset to a training set (80% samples) and a testing set (20% samples). Report the overall
classification accuracies on the training and testing sets and report the precision, recall, and F-measure scores
for each of the two classes on the testing sets.
– You have to use PyTorch deep learning library.
– Two hidden layers: the first hidden layer must contain 5 units using ReLU activation function; the
second layer must contain 3 units using tanh activation function.
Q3 Given an input image (see the attachment), design two filters/kernels with size of 3 by 3 to detect all horizontal
and vertical edges. To make it easier, you can first convert the image into gray scale using OpenCV. Your
architecture only contains 1 convolutional layer, 1 pooling layer and 1 fully connected layer. Show the
visualizations of the output of the convolutional layer, the pooled layer and the ReLU activated convolutional
layer (not the fully connected layer) for both kernels.
What need to submit:
– Python programming code
– Outpus six figures (two kernels by three layers) in total.
Q4 Build an image classification model using Convolutional Neural Networks (CNN) in PyTorch. The data set
(i.e. Fashion-MNIST) can be found here:
https://github.com/zalandoresearch/fashion-mnist/tree/master/data/fashion.
Information about this dataset can be found here:
1
https://github.com/zalandoresearch/fashion-mnist.
It consists of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28
grayscale image, associated with a label from 10 classes.
By building the classification model, I suggest you divide it into several subtasks:
1. Loading the data set.
– Please explore a few samples and visualize these images.
2. Creating a validation set and preprocessing the images.
– Split the training data set to a training set (90% samples) and a validation set (10% samples)
– convert the images and the targets into torch format for both training and validation data sets.
3. Implementing CNNs using PyTorch.
– Define the architecture with just 2 convolutional layers to extract features from the images and then
use a fully connected dense layer to classify those features into their respective categories (i.e. two
Conv2d layers and a linear layer).
– Train the model for 25 epochs and show the validation losses by printing in console. You are expected
to see that the validation loss is decreasing as epoch increases.
– Visualize the training and validation losses by plotting them.
– Show the accuracy of the model on the training and validation set.
4. Generating predictions for the test set.
– Load the test images.
– Do the pre-processing steps on these images similar to what you did for the training images.
– Generate predictions for the test set.
What to submit:
– Python programming code
– Five image visualization when loading the data set.
– Plotting visualization of the training and validation losses.
– Report the accuracy of your model on training and validation set.
– Your predictions for the test images.
Q5 (Bonus Question): You will get an additional half point (0.5) if you can answer this bonus question correctly.
That means, if you answer Q1-Q4 correctly, you get a full point (1.0) for this HW assignment. If you can
answer Q1-Q5 correctly, you will get 1.5 points.
Following the step by step instructions below to build a LeNet-5 CNN architecture in Pytorch using FashionMNIST data set provided in Q2.
https://medium.datadriveninvestor.com/lenet-5-a-classic-cnn-architecture-c87d0b03560d
What to submit:
2
– Python programming code
– Visualization of plotting the training accuracy and loss after each epoch
– Your predictions for the test images.
3