model.py
This file contains the Architecture of Neural Network developed for MNIST dataset with PyTorch.utils.py
This file contains utility functions required for model training, evaluation, plotting results etc.S5.ipynb
This is out main notebook where we perform our experiments with MNIST dataset and the defined model.
- Import required modules in S5.ipynb notebook, including
torch
,torchvision
and other submodules - Import NeuralNet model
Net
class frommodel.py
- Import training functions, helper functions for plotting etc from
utils.py
- Start with image transformation using
torchvision.transforms
- Download the MNIST data and create a dataset out of it, using
torchvision.datasets
- Create both training and testing dataloaders with required number of batches
- Define loss function, optimizer, learning rate, scheduler, epochs with preferred hyper paramters
- Start the model training and accumulate the losses and accuracy values for both training and testing phases
- Once training is completed, evaluate the losses and accuracy values collected during the training using plot_results function
- We can also check the internals of the model using
summary
function fromtorchinfo
module (Added sample below)
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
Conv2d-1 [-1, 32, 26, 26] 288
Conv2d-2 [-1, 64, 24, 24] 18,432
Conv2d-3 [-1, 128, 10, 10] 73,728
Conv2d-4 [-1, 256, 8, 8] 294,912
Linear-5 [-1, 50] 204,800
Linear-6 [-1, 10] 500
================================================================
Total params: 592,660
Trainable params: 592,660
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.00
Forward/backward pass size (MB): 0.67
Params size (MB): 2.26
Estimated Total Size (MB): 2.93
----------------------------------------------------------------