In this lab we will define and train a simple Convolutional Neural Network (CNN) with PyTorch, working inside a Jupyter notebook. The slides introduce the building blocks of CNNs (convolution, batch normalization, ReLU, softmax, max pooling, dropout); the notebook then guides you through using them to build a network and train it on the Fashion-MNIST dataset.
The assignment is contained entirely in the notebook. Each task comes with its own resources, sub-tasks and tips:
- Creating a model
- Count the network's parameters and MAC operations
- Dataset & DataLoaders
- Testing the CNN over the dataset
- Training loop
- Save/load model
Guidelines to work on today's assignment:
- Read the slides
- Set up the environment, preferably on Google Colab, or locally in VS Code (see Quickstart)
- Complete Tasks 1-6 in the Jupyter notebook
AI policy: we will not prevent you from using AI to solve the assignments, but the lab is meant to be a hands-on learning experience. To keep it useful, this repository includes an AGENTS.md file (also used in a Stanford class) that AI agents should read automatically, so that they guide you towards finding the solution yourself instead of giving it to you directly.
- Run all the cells and save the notebook, so that the results show up in the cells. Do NOT clear the outputs of the cells.
- Rename the notebook to
LAB2_APAI_<name_surname>.ipynb - Upload it to Virtuale:
- If you run on Colab, download it first (
File → Download → Download .ipynb), then upload it - If you run locally, upload the saved notebook directly from your PC
- If you run on Colab, download it first (
For each lab that you solve and submit successfully, you will receive 1 extra point, up to a maximum of 4 points.
Assignment DEADLINE: Sunday, 25/10/2026 (at 23:59)
This lab must be run on your own personal computer, since the lab machines have very limited internet access, which doesn't allow you to access Google Colab or to download the necessary libraries.
There are 2 ways to complete the assignment. We recommend Google Colab:
Google Colab runs Python notebooks in the cloud and is accessed via your browser, so it should work on any system.
- Download the notebook, either from Virtuale or by cloning this repository
- Open Google Colab and choose the "Upload notebook" ("Carica notebook") option
- Use the pop-up to upload the notebook that you just downloaded
- Now you're ready to start!
- Clone this repository:
git clone https://github.com/EEESlab/APAI26-LAB02-DNN-definition-and-training
cd APAI26-LAB02-DNN-definition-and-training/
- Open the notebook in VS Code. It should work with minimal setup: if any component is missing (e.g., the Python or Jupyter extensions, or the kernel), VS Code will direct you to install it.
- Now you're ready to start!