This project trains a Convolutional Neural Network (CNN) to classify images from the MNIST dataset.
Dataset - MNIST
Developed with the software and tools below.
1.1 Data Loading
1.2 Data Preprocessing
1.3 Data Analysis and Visualization
- 1.3.1 Sample Images Visualization: Plotted random MNIST digit samples.
- 1.3.2 Correlation Matrix: Computed and visualized the pixel value correlation matrix.
- 1.3.3 Digit Distribution: Displayed the distribution of digits in the dataset.
- 1.3.4 Principal Component Analysis (PCA): Reduced image dimensions and visualized in 2D.
1.4 Data Augmentation
2.1 Model Creation
2.2 Model Training
2.3 Model Evaluation
main.ipynb - Jupyter notebook contains the code for the project.
test.ipynb - Jupyter notebook contains attempt where dataset was converted to numpy arrays, then split and converted to tensors.
To set up the environment, use the following commands:
conda create --name pytorch_env python=3.11.9 --file requirements.txt
conda activate pytorch_env- Dataset is loaded using
torchvision.datasets.MNIST. - Images are resized to 224x224, normalized, and converted to tensors.
If you wish to visualize the model architecture:
pip install torchview
sudo apt-get install graphvizIf you have previously trained and saved the model:
- Ensure the files
models/custom_cnn_model.pthandmodels/losses.pklexist in the models/ directory. - The notebook will automatically load these files and skip training.
![]() |
![]() |
|---|---|
| Correlation Matrix | PCA Analysis |


