Skip to content

Team-Synapse-UoM/Custom-CNN-ImageClassification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom-CNN-ImageClassification

This project trains a Convolutional Neural Network (CNN) to classify images from the MNIST dataset.

Dataset - MNIST

Developed with the software and tools below.

Python Anaconda Jupyter PyTorch Numpy Seaborn scikit-learn Matplotlib

Overview

1. Data Preparation

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. Model Building

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.

Setup Instructions

1. Import Required Libraries

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

2. Load the MNIST Dataset

  • Dataset is loaded using torchvision.datasets.MNIST.
  • Images are resized to 224x224, normalized, and converted to tensors.

3. Optional Setup for Visualization

If you wish to visualize the model architecture:

pip install torchview
sudo apt-get install graphviz

4. Reuse Saved Model

If you have previously trained and saved the model:

  • Ensure the files models/custom_cnn_model.pth and models/losses.pkl exist in the models/ directory.
  • The notebook will automatically load these files and skip training.

Results

Visualization

Image 1 Image 2
Correlation Matrix PCA Analysis

Test Accuracy:

The accuracy achieved on the test set is 99.14%

Training and Validation Losses

About

CNN for image classification

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors