CMPUT 328辅导、辅导Python编程
CMPUT 328 Fall 2022
Assignment 3
Worth 8% of the total weight
Part 1: Logistic Regression [Worth 4% of the total weight]:
Implement Logistic Regression in PyTorch:
a) Train and test on both MNIST and CIFAR10 datasets.
Define your own data pipeline for training, validation and testing using PyTorch dataloader.
Use the 12,000 samples of the train set as validation set for both datasets. You can use
random_split from pytorch to achieve this.
Test the trained model on the validation set every few epochs to prevent overfitting
Do not use the test set for training.
Take note of the differences between MNIST and CIFAR10 to make your code work for both. For
example:
MNIST images are grayscale, while CIFAR10 images are RGB.
MNIST and CIFAR10 images have different spatial dimensions (height and width).
b) Add a regularization term to improve your model (L1 or L2 regularization, whichever gives better
accuracy)
Expected Performance: A correctly implemented, and somewhat well-tuned version of this algorithm will
have an accuracy of 82-92% on MNIST and 28-38% on CIFAR10 for both test and validation sets.
Collaboration Policy: This must be your own work. Do not share or look at the code of
other people (whether they are inside or outside the class). Do not search for or copy code from the
Internet. You can talk to others that are in the class about solution ideas but not in so much detail that
you are verbally sharing or hearing about or seeing the code. You must cite whom you talked to in
the comments of your programs.
All submissions involved in detected cases of plagiarism will be penalized with no marks for this
assignment irrespective of who copied from whom.
Part 2: Hyperparameter Search [Worth 4% of the total weight]
Find optimal hyperparameters for Adaptive Moment Estimation (Adam) and Stochastic Gradient Descent
(SGD) on CIFAR10 dataset including the regularization method you used in part 1.
You should perform grid search or random search for finding the optimal hyper-parameters using
accuracy on the validation set and select the best configuration.
You can also use more advanced search strategies like evolutionary search, but you are not allowed
to use any automatic parameter search methods like scorch.
You should not use the test set during this process.
You only need to complete the function tune_hyper_parameter in A3_submission.py for this part.
Template Code: You are provided with template code in the form of 1 file: A3_submission.py.
You need to complete all the functions in A3_submission.py (i.e. logistic_regression for part 1,
tune_hyper_parameter for part 2).
The code can be run using python3 A3_submission.py on your own machine or !python3 “A3_submission.py >” from a code cell in Colab.
You can also use the provided notebook (i.e. Assignment_3_notebook.ipynb) on Colab for your convenience
(two files have identical code). But make sure to submit the A3_submission.py, not the notebook.
Submission: You need to submit only the completed A3_submission.py. Make sure to import any
additional libraries you need so it can be used as a standalone Python module from A3_submission.py
Marking: Marks are separated into two parts, 4% for Part 1 and 4% for Part 2. See the following
explanations:
Part 1: Code marks will depend on correctness of the implementation and following metrics:
Runtime: The total runtime of your submission (including training and testing) should not exceed 300
seconds for either dataset using GPU on Colab.
One trick to improve your run time is to grid search the hyperparameters first but only put in the best
hyperparameters you found in your submission.
Accuracy: Each dataset will give you 4% of the total score in this assignment, in a total of 8%.
MNIST: score scales linearly from 82 - 92% on the test set.
CIFAR10: score scales linearly from 28 - 38% on the test set.
Part 2: Code marks will depend only on the correctness of your search implementation.
Runtime: The runtime of your submission should not exceed 1500 seconds using GPU on Colab.
Accuracy: There are no specific accuracy requirements except there should be improvement in loss /
accuracy compared to part 1.
- QQ:99515681
- 邮箱:99515681@qq.com
- 工作时间:8:00-21:00
- 微信:codinghelp
联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!