This project implements a lightweight Convolutional Neural Network (CNN) for MNIST digit classification with a complete CI/CD pipeline using GitHub Actions. The model is designed to achieve >95% accuracy in a single epoch while maintaining less than 25,000 parameters.
The model uses a compact but effective CNN architecture:
- 4 Convolutional layers with batch normalization and ReLU activation
- Max pooling layers for dimensionality reduction
- Single fully connected layer for classification
- Batch normalization for training stability
Layer details:
- Conv2d(1→16, 3×3) + BatchNorm + ReLU
- Conv2d(16→32, 3×3) + BatchNorm + ReLU + MaxPool
- Conv2d(32→32, 3×3) + BatchNorm + ReLU
- Conv2d(32→16, 3×3) + BatchNorm + ReLU + MaxPool
- MaxPool
- Fully Connected (144→10)
Key features:
- Input: 28×28 grayscale images
- Output: 10 classes (digits 0-9)
- Parameters: <25,000
- Training accuracy: >95% in one epoch
.
├── .github
│ └── workflows
│ └── ml-pipeline.yml
├── model
│ ├── init.py
│ └── network.py
├── tests
│ ├── init.py
│ └── test_model.py
├── .gitignore
├── README.md
├── requirements.txt
└── train.py
- Clone the repository:
bash
git clone <your-repo-url>
cd <repo-name>
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
bash pip install -r requirements.txt
To train the model:
bash python train.py
The trained model will be saved in the models/
directory with a timestamp suffix.
To run the tests:
bash pytest tests/test_model.py -v
The tests verify:
- Model architecture (input/output dimensions)
- Parameter count (<25,000)
- Training accuracy (>95%)
The project includes a GitHub Actions workflow that automatically:
- Sets up a Python environment
- Installs dependencies
- Runs all tests
- Uploads the trained model as an artifact
The pipeline is triggered on every push to the repository.
- Python 3.8+
- PyTorch
- torchvision
- pytest
Trained models are saved with timestamps in the format: mnist_model_YYYYMMDD_HHMMSS.pth
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- MNIST Dataset: LeCun et al.
- PyTorch Documentation and Tutorials