-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MNIST model with <25K params and >95% accuracy - assignment 5
- Loading branch information
Showing
5 changed files
with
53 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
# ERA-V3 MNIST Project | ||
# MNIST Classification Project | ||
|
||
This project implements a CNN model for MNIST digit classification with CI/CD pipeline. | ||
A PyTorch implementation of MNIST digit classification that achieves >95% accuracy in one epoch with less than 25,000 parameters. | ||
|
||
## Project Structure | ||
- `mnist_project/`: Contains the main project code | ||
- `src/`: Source code directory | ||
- `model.py`: CNN model architecture | ||
- `train.py`: Training script | ||
- `utils.py`: Utility functions | ||
- `tests/`: Test files | ||
## Model Architecture | ||
- Input Layer: 28x28x1 | ||
- Conv1: 8 filters with BatchNorm and ReLU | ||
- Conv2: 16 filters with BatchNorm and ReLU | ||
- Conv3: 20 filters with BatchNorm and ReLU | ||
- MaxPooling layers | ||
- Fully Connected Layer: 10 outputs | ||
- Total Parameters: <25,000 | ||
|
||
## Local Setup | ||
1. Clone the repository: | ||
## Key Features | ||
- Achieves >95% accuracy in 1 epoch | ||
- Lightweight architecture (<25K parameters) | ||
- Uses BatchNormalization for faster convergence | ||
- Implements dropout for regularization | ||
|
||
## GitHub Actions Tests | ||
The CI/CD pipeline automatically verifies: | ||
1. Model has less than 25,000 parameters | ||
2. Achieves accuracy greater than 95% in one epoch | ||
|
||
## Setup and Training | ||
1. Install dependencies: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import torch | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
|
||
class MNISTModel(nn.Module): | ||
def __init__(self): | ||
super(MNISTModel, self).__init__() | ||
self.conv1 = nn.Conv2d(1, 8, kernel_size=3, padding=1) | ||
self.conv2 = nn.Conv2d(8, 16, kernel_size=3, padding=1) | ||
self.fc1 = nn.Linear(16 * 7 * 7, 64) | ||
self.fc2 = nn.Linear(64, 10) | ||
self.conv1 = nn.Conv2d(1, 8, kernel_size=3, padding=1) # 28x28x8 | ||
self.bn1 = nn.BatchNorm2d(8) | ||
self.conv2 = nn.Conv2d(8, 16, kernel_size=3, padding=1) # 28x28x16 | ||
self.bn2 = nn.BatchNorm2d(16) | ||
self.conv3 = nn.Conv2d(16, 20, kernel_size=3, padding=1) # 14x14x20 | ||
self.bn3 = nn.BatchNorm2d(20) | ||
self.pool = nn.MaxPool2d(2, 2) | ||
self.relu = nn.ReLU() | ||
self.fc1 = nn.Linear(20 * 7 * 7, 10) | ||
self.dropout = nn.Dropout(0.1) | ||
|
||
def forward(self, x): | ||
x = self.pool(self.relu(self.conv1(x))) # 14x14 | ||
x = self.pool(self.relu(self.conv2(x))) # 7x7 | ||
x = x.view(-1, 16 * 7 * 7) | ||
x = self.relu(self.fc1(x)) | ||
x = self.fc2(x) | ||
return x | ||
x = self.pool(F.relu(self.bn1(self.conv1(x)))) # 14x14x8 | ||
x = F.relu(self.bn2(self.conv2(x))) # 14x14x16 | ||
x = self.pool(F.relu(self.bn3(self.conv3(x)))) # 7x7x20 | ||
x = x.view(-1, 20 * 7 * 7) | ||
x = self.dropout(x) | ||
x = self.fc1(x) | ||
return F.log_softmax(x, dim=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters