In this task, students are required to design and train a neural network capable of classifying handwritten digits using Python and PyTorch. The assignment focuses on a multiclass

Introduction

In this task, students are required to design and train a neural network capable of classifying handwritten digits using Python and PyTorch. The assignment focuses on a multiclass classification problem, where the model must correctly identify digits from 0 to 9 using the MNIST dataset. Through this exercise, students will strengthen their understanding of neural network components such as layers, activation functions, loss functions, and evaluation techniques.

Objective

The main aim is to achieve strong prediction accuracy by building, training, and tuning a feedforward neural network. This assignment will assess your knowledge of neural network fundamentals and your ability to apply them in practice.

Dataset Information

The MNIST dataset includes:

  • 60,000 training images
  • 10,000 test images

Each image contains a grayscale handwritten digit and has a resolution of 28 × 28 pixels. The following instructions outline how to prepare the dataset for model training.

Tasks

1.1 Dataset Preprocessing

Steps:

  1. Normalization
    Convert pixel values from the range 0–255 to 0–1 for numerical stability.
  2. Reshaping
    Each 28×28 image must be flattened into a one-dimensional vector of 784 values.

1.2 Model Architecture

You will build a feedforward neural network with this structure:

  • Input Layer: 784 units (one for each pixel)
  • Hidden Layers: 1–2 layers, each containing either 128 or 256 neurons
  • Activation Function: ReLU for the hidden layers
  • Output Layer: 10 output nodes, representing the digit classes from 0–9
    (Softmax used during evaluation)

1.3 Model Compilation

  1. Loss function: Use sparse categorical cross-entropy as the loss function since this is a multiclass classification problem with integer labels.
  2. Optimizer: Use Adam optimizer for training.
  3. accuracy: Monitor the model’s accuracy metric.

1.4 Model Training

  1. Train the model on the training data.
  2. Set epochs to 10–15 and use a batch size of 32.
  3. Use 20% of the training data as a validation set.

1.5 Evaluation

• Evaluate the model on the test dataset and report the accuracy.

1.6 Analysis and Report

  1. Plot the training and validation accuracy and loss over epochs to analyze any overfitting or under-fitting.
  2. Discuss how the number of neurons and hidden layers affects performance.
  3. Describe any improvements attempted, such as adding dropout layers or batch normalization.

Report Format

Name your report AIDI1009-24F-10827: Assignment#2 LastNameFirstName.pdf. Below is the general format of the report required:

  1. The front page (i.e., title page) should contain only the following:
    • Course #, Course Name and Date
    • Your Name and ID
    • Assignment # and title of the assignment
  2. Introduce the problem to be solved:• Problem Statement
    (a) Briefly describe the problem solved in the assignment.
    (b) Assumptions and Constraints
    (c) Constraints could be for example using certain libraries, datasets, or a specific programming language.
  3. Answer all questions posed in Section 3. Append the following to your answers:
    (a) Plots and Graphs.
    (b) Tables.
    (c) Figures.
  4. Python Code
    (a) Python code for the problem
    (b) Document your code.

Brief summary of assessment requirements

Assessment goal: Design, implement and evaluate a feedforward neural network in Python/PyTorch to perform multiclass classification of handwritten digits (0–9) using the MNIST dataset. The task tests understanding of data preprocessing, network architecture, training, tuning, evaluation, and reporting.

Key deliverables & constraints

  • Use the MNIST dataset: 60,000 training images and 10,000 test images (28×28 grayscale).
  • Preprocess: normalize pixel values (0–1) and reshape each image to a 1D vector of 784 features.
  • Build a feedforward neural network with:
    • Input layer: 784 units
    • 1–2 hidden layers with 128 or 256 neurons each (ReLU activation)
    • Output layer: 10 units (use softmax for evaluation)
  • Training setup:
    • Loss: sparse categorical cross-entropy (appropriate integer-label loss)
    • Optimizer: Adam
    • Epochs: 10–15, batch size: 32
    • Validation split: 20% of training data
  • Evaluation: report test accuracy and include plots of training/validation loss and accuracy.
  • Report requirements: include problem statement, assumptions, code (documented), plots/tables, and filename format.
  • Discuss architecture choices, overfitting/underfitting analysis, and any improvements tried (dropout, batch norm, regularization).