辅导案例-COMP9444
COMP9444 Neural Networks and Deep Learning This assignment is divided into three parts: • Part 1 contains simple PyTorch questions designed to get you started and familiar with the automarking environment • Part 2 involves creating a single-layer Neural Network (i.e. linear model) in NumPy, without using PyTorch. • Part 3 involves implementing specific network structures to recognize handwritten Japanese Hiragana characters. Provided Files Copy the archive hw1.zip into your own filespace and unzip it. This should create a directory hw1 with two subdirectories: src and data. Then type: cd hw1/src You will see three skeleton files part1.py, part2.py and part3.py. Your task is to complete these files according to the specifications in this document, as well as in the comments in the files themselves. Each file contains functions or classes marked TODO: which correspond to the marking scheme shown below. This document contains general information for each task, with in-code comments supplying more detail. Each task in this assignment is sufficiently specified to have only one correct answer (although there may be multiple ways to implement it). If you feel a requirement is not clear you may ask for additional information on the FAQ, or the course forum. Marking Scheme All parts of the assignment will be automarked. Marks for each task are shown in brackets in the following table. Note that no partial marks are assigned. Part 1: 1 [0.5 ] simple_addition 2 [0.5] simple_reshape When you submit your files through give, simple submission tests will be run to test the functionality of part 1, and to check that the code you have implemented in parts 2 and 3 is in the correct format. After submissions have closed, we will run the final marking scripts, which will assign marks for each task. We will not release these final tests, however you will be able to see basic information outlining which sections of code were incorrect (if you do not receive full marks) when you view your marked assignment. 3 [0.5] simple_flat 4 [0.5] simple_transpose 5 [0.5] simple_permute 6 [0.5] simple_dot_product 7 [0.5] simple_matrix_mul 8 [0.5] broadcastable_matrix_mu l 9 [0.5] simple_concatenate 10 [0.5] simple_stack Part 2: 1 [1] Activation 2 [1] Forward Pass 3 [1] Loss 4 [1] Error 5 [2] Backward Pass Part 3: 1 [1] View Batch 2 [1] Loss 3 [1] FeedForward 4 [2] CNN Setting up your development environment If you plan to write and debug the assignment on a Unix-based laptop, the following commands may help you to install the necessary software. Note that the exact commands may vary, based on your system. 1. Create a new virtual environment:
conda create -n COMP9444 python=3.7 2. Activate it:
conda activate COMP9444 3. Install pytorch:
conda install pytorch torchvision cpuonly -c pytorch 4. Install everything else:
conda install tqdm matplotlib Another option for development is Google Colabs, which is a free service from Google that allows development in hosted notebooks that are able to connect to GPU and TPU (Googles custom NN chip - faster than GPUs) hardware runtimes. If you are having trouble getting PyTorch setup you might also want to consider this option, as the hosted environments have PyTorch preinstalled. More information and a good getting started guide is here. It is important to note this is just an option and not something required by this course - some of the tutors are not familiar with colabs and will not be able to give troubleshooting advice for colab-specific issues. If you are in doubt, develop locally. Part 1 [5 marks] For Part 1 of the assignment, you should work through the file part1.py and add functions where specified. Part 2 [6 marks] For Part 2, you will develop a linear model to solve a binary classification task on two dimensional data. The file data/ binary_classification_data.pkl contains the data for this part. We have included the file used to generate the data as data_generator.py. You may examine this for your reference, or modify it if you wish to watch Gradient Decent take place on different data. Note that running this file will replace the pickle file with another stochastically generated dataset. This shouldn't cause your solution to fail, but it will cause the final output image to appear different. It is good to check that your file works with the original pickle file provided. The file part2.py is the one you need to modify. It contains a skeleton definition for the custom LinearModel class. You need to complete the appropriate functions in this class. You may modify the plotting method during development (LinearModel.plot()) - it may help you to visualize additional information. Prior to submission, however, verify that the expected output is being produced with the original, unaltered, code. When completed, a correct implementation should produce the following image, along with model accuracies at each training step printed to stdout: