AIC2100 AI Programming with Python
Lab 6
Yonsei University
Lab 6 AIC2100
2
You must follow the specification thorougly!
• Any typos (including whitespace and linebreak) will result in a point deduction.
• If you’re asked to write the comment or docstring, you must add them.
• If some Python libraries are prohibited, importing them will result in 0 points.
• Depending on the lab content, additional rules can be added.
• Please read the specification document carefully and submit your code.
• We won't accept appeals for point deductions based on misinterpreting the lab specification
documentation.
• If any specification is unclear, please post your question on the Q&A board.
Lab 6 AIC2100
3
Please refer to the guidelines noted in previous labs. They remain applicable for this and
subsequent labs.
Any updates in guidelines will be announced again.
Coding guideline
Lab 6 AIC2100
4
Notation
• To clearly instruct the lab specifications, (1) we use “˽” to depict a whitespace (blank)
character and (2) “¤” for a “\n” (newline) character.
• Underlined text refers to the user input. -> input()
• New notations will be demonstrated additionally on there first mention.
Lab 6 AIC2100
5
Importing modules/libraries
You may be asked or permitted to use some specific modules/libraries. You are allowed to use
only specified ones in each problem. For example, if math module is mentioned in problem 1 but
not in problem 2, you are not allowed to use math module in problem 2.
Some custom modules may be required to use in the implementation. We will provide such
module python codes via LearnUs if necessary.
Lab 6 AIC2100
6
Class
In this lab, you will be asked to implement class. If you are asked to implement
the class only, you should not include the main program in your code, just like
the function.
Unexpected execution of the main program during the grading can result in 0
points, so please be careful!!
Lab 6 AIC2100
7
Class Docstring
You must put the docstring inside the class itself and all class methods, just
like you did in the function.
• 10 points will be deducted per lab problem with missing or insufficient docstrings.
• Don't forget to fill in the docstrings in the provided template code, too!
• Each docstring must be written in English and contain at least 20 characters.
class MyClass:
"""Class docstring"""
def __init__(self):
"""Method docstring"""
(your code continues…)
def method1(self, a, b):
"""Method docstring"""
(your code continues…)
Lab 6 AIC2100
8
[Recap] Marking Rule : Comments
• 10 points will be deducted per lab problem with missing or insufficient comments.
• Please put brief comments (#...) with all your code (including functions).
• You must include at least two comments in your code.
• Each comment must be at least 10 characters long and written in English.
Lab 6 AIC2100
9
[Recap] Marking Rule : Docstrings
• 10 points will be deducted per lab problem with missing or insufficient docstrings in all
functions.
• Please provide docstrings with all functions.
• Each function must include at least one docstring.
• Each docstring must be written in English and contain at least 20 characters.
• A docstring should briefly explain :
• The purpose of each parameter (if any).
• What the function computes.
• What the function returns to the caller (if anything).
def your_function(*your_args):
"""Your docstring"""
(your code continues…)
Lab 6 AIC2100
10
Comment vs Docstring in Function
• If you execute the following code,
• …here’s the result.
• They are different! Be careful not to confuse them.
• Docstring is a “string variable”.
• Comment is not a variable.
Lab 6 AIC2100
11
Programming Problems: Function
In some programming problems, you will be asked to implement a function. To solve such problems, you
must read the problem specification to understand:
1. What is the name of the asked function?
2. What input(s) does the asked function receive?
3. What should the function compute?
4. What should the function return?
▪ Unless requested in the problem specification, in your function you should not read input from the user,
and you should not print the results of your function!
▪ To test your function, you must write your own main program, which must call your function with
appropriate input values. In the main program, you can then print the value(s) returned from your
function to check for correctness.
• Do not hand in such a main program that you used to test your function!
• Only the function itself must be handed in.
Lab 6 AIC2100
12
Programming Problems: Function
Here’s an example. Assume that you are asked to implement a function my_add that takes two
numbers as parameters and returns their addition.
This is the correct program.
This is the incorrect program.
1. Wrong function name → No point
2. Wrong parameter input → No point
3. Missing docstring → 10 points deduction
4. Including print (or any implementation not requested in the lab
specification) in the main program part → No point
Lab 6 AIC2100
13
Problem 1
Fashion-MNIST is a dataset of Zalando's article images—consisting of a training set of 60,000 examples and
a test set of 10,000 examples. Each example is a 28 x 28 grayscale image, associated with a label from 10
classes.
Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning Algorithms. Han Xiao, Kashif Rasul, Roland Vollgraf. arXiv:1708.07747
Lab 6 AIC2100
14
Problem 1
Labels
Each training and test example is assigned to one of the following labels:
0. T-shirt/top 1. Trouser 2. Pullover
3. Dress 4. Coat 5. Sandal
6. Shirt 7. Sneaker 8. Bag
9. Ankle boot
Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning Algorithms. Han Xiao, Kashif Rasul, Roland Vollgraf. arXiv:1708.07747
Lab 6 AIC2100
15
Problem 1
Write a classifier model code to classify clothes using the given Fashion MNIST dataset and Pytorch.
The files you need to submit are as follows:
1. Training script (File name must be “lab6_p1.py”)
We have provided a basic skeleton code to LearnUs. Complete and extend the provided LearnUs skeleton
code to include all parts necessary to train your model (see next slide for details).
2. Trained weights (.pth file, File name must be “lab6_p1.pth”)
You must also submit the weights trained based on the code. Scoring is done based on (1) the weights and
(2) the model structure of the code you wrote, and you will be given a score based on whether 12 new
clothing data are correctly classified (see slide 21 for details).
Lab 6 AIC2100
16
Problem 1
1. Set network
In this section, write code to define and instantiate the layers of your neural
network with appropriate input and output dimensions.
2. Initialize weight (if needed)
Here, add code to apply a weight initialization scheme to each learnable layer
before training.
3. Set activation function
In this part, specify the activation functions that should follow your layers.
4. Set model
Combine your previously defined layers and activations into a single model
container and move it to the chosen device with .to method.
5. Set loss and optimizer
Write code to choose a loss function and instantiate an optimizer using your
model’s parameters.
Lab 6 AIC2100
17
Problem 1
train
In this stage, the model learns patterns
by repeatedly processing the training
data, comparing its predictions to the
true labels, and adjusting its internal
parameters to reduce errors. Through
this iterative optimization, the network’s
weights are refined so that its outputs
become increasingly accurate.
Lab 6 AIC2100
18
Problem 1
eval
In this phase, the model is set to
inference mode and processes a single
input image to produce a set of class
scores. It then selects and returns the
class with the highest score as its final
prediction, without altering any model
parameters.
Lab 6 AIC2100
19
Problem 1
Generate trainer: Instantiates FashionMNIST Trainer, setting random seed,
device, data loaders, and model skeleton.
Run train: Executes the training loop to optimize the model’s weights on the
FashionMNIST training set.
Evaluate on test set: Computes and prints overall accuracy of the trained model
on the test dataset.
Pick a sample and predict: Randomly selects one test image and its true label,
runs it through eval(), and prints both the actual label and the model’s predicted
label.
Export model: Saves the current model’s learned weights to a file (lab6_p1.pth).
Import model: Loads the saved weights back into the model to restore its state.
Re-evaluate on test set: Runs eval_all() again to confirm the imported weights
yield the same test accuracy as before.
Lab 6 AIC2100
20
Problem 1
Note 1. Do not change the seed value (2025) in the code! We will check whether the weights you
submit are derived from the code you actually wrote. This is used to check for plagiarism.
Note 2. The recommended versions of the libraries provided are as follows (latest versions as of
2025/05):
numpy ==2.2.5
torch==2.7.0
torchvision==0.22.0
matplotlib==3.10.3
Lab 6 AIC2100
21
Problem 1
Note 3.
This Lab6 Problem1 is scored in the following guide.
1. There are 12 clothing images that are not in the Fashion MNIST dataset.
2. We will classify the 12 images using your submitted model and code.
3. [1] Whether the image was classified correctly and [2] the classification accuracy are evaluated, and up to 6-7
points are given per image. (Since there are 12 images, the total score is 80 points.)
4. Once you have submitted your code and model to Gradescope, you can view the scores for the 12 images. If
you’re not satisfied with your scores, you may retrain your model and resubmit both your code and model.
Note 4.
Do not use different data for model train and test! (Even if it is the Fashion MNIST dataset)
Lab 6 AIC2100
22
Marking Criteria
• Score is only given to programs that compile and produce the correct output with Python version
3.
• No points for programs that are named wrongly. Please refer to the following slide for the
required file names.
• Points are deducted for programs that produce warnings.
• Please pay particular attention to the requested output format of your programs. Deviating from
the requested output format results in points deductions.
• Gradescope only allows code to run for up to 10 minutes!
• If your code takes longer than 10 minutes to execute due to excessive computation, it will not be
graded and will be marked as incorrect.
• (10 minutes is a very generous limit for this Lab assignment, but please still pay attention to the
efficiency of your code.)
Lab 6 AIC2100
23
Plagiarism
• Plagiarism (Cheating)
– This is an individual assignment. All or some submissions are checked for plagiarism.
• We will not inform you which problems will be checked.
– Once detected, measures will be taken for all students involved in the plagiarism incident
(including the "source'' of the plagiarized code).
Lab 6 AIC2100
24
Please prepare the files for the programming problems. The names of the files, their due dates, and the
archive file names are given in the table above.
• Please upload your file by the stated due date on Gradescope.
• Please pay attention to file names.
Deliverables, Due Date and Submission
Problem File name Due
1
lab6_p1.py
lab6_p1.pth
Friday
June 6, 2025,
23:59
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。