This project implements a Convolutional Neural Network (CNN) for MNIST digit classification with a complete CI/CD pipeline using GitHub Actions. The model architecture uses batch normalization, dropout, and global average pooling to achieve >95% accuracy on the test set.
- Input Layer: Accepts 28x28 grayscale images
- 5 Convolutional layers with batch normalization and dropout
- Global Average Pooling
- Final Dense layer with 10 outputs (one for each digit)
- Total parameters: = 19,050
- Automated training and testing pipeline
- Model validation checks:
- Parameter count verification (< 20,000 parameters)
- Input shape validation (28x28)
- Output shape validation (10 classes)
- Accuracy threshold (> 99.3% on test set)
- Automatic model versioning with timestamp and accuracy
- CPU-only training support for both local and CI environments
- Python 3.8 or higher
- PyTorch (CPU version)
- Other dependencies listed in requirements.txt
- Clone the repository:
git clone https://github.com/walnashgit/NNAndBasicCICD.git
cd NNAndBasicCICD
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate
On Windows:
venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Train the model:
python train.py
- Run tests:
python -m pytest test_model.py
The project includes a GitHub Actions workflow that automatically:
- Sets up a Python environment
- Installs dependencies (CPU-only versions)
- Trains the model
- Runs validation tests
- Archives the trained model as an artifact
The pipeline is triggered on every push to the repository.
- Dataset: MNIST (60,000 training images, 10,000 test images)
- Batch Size: 128
- Optimizer: SGD (lr=0.01)
- Loss Function: Negative Log Likelihood
- Training: Single epoch with progress bar showing loss and accuracy
- Model Saving: Automatic with timestamp and accuracy in filename
The test suite (test_model.py
) verifies:
- Model architecture compatibility with 28x28 input images
- Total parameter count (< 20,000)
- Model accuracy on test set (> 99.3%)
- Output shape (10 classes)
Trained models are saved in the models/
directory with the name mnist_model_YYYYMMDD_HHMMSS_accXX.X.pth
where:
- YYYYMMDD: Date
- HHMMSS: Time
- XX.X: Achieved accuracy