MNIST CNN Baseline (Ablation Study)

This model is a Convolutional Neural Network (CNN) trained on the MNIST dataset for handwritten digit classification. It serves as the baseline model for a larger scientific ablation study.

Model Details

  • Architecture: 2x Conv2D (with BatchNorm + ReLU) + MaxPooling, followed by Dense layers with Dropout (0.5).
  • Parameters: 421,834
  • Framework: PyTorch
  • Accuracy: 98.95% on the test set (only 105 misclassifications out of 10,000).

Ablation Study Context

This model was compared against:

  1. Without Dropout: Resulted in overfitting (train acc 99.34%, val loss increased).
  2. Without BatchNorm: Achieved 99.18% (highest on MNIST, but BN is crucial for deeper nets).
  3. With Data Augmentation: Achieved 98.82%, reducing overfitting.

How to Use

You can download the weights from this repository (mnist_baseline_cnn.pth) and load them in your PyTorch project.

import torch
import torch.nn as nn

# Define the architecture (same as training)
class BaselineCNN(nn.Module):
    def __init__(self):
        super(BaselineCNN, self).__init__()
        self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
        self.bn1 = nn.BatchNorm2d(32)
        self.relu1 = nn.ReLU()
        self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
        self.bn2 = nn.BatchNorm2d(64)
        self.relu2 = nn.ReLU()
        self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
        self.flatten = nn.Flatten()
        self.fc1 = nn.Linear(64 * 7 * 7, 128)
        self.dropout = nn.Dropout(0.5)
        self.fc2 = nn.Linear(128, 10)
    def forward(self, x):
        x = self.pool1(self.relu1(self.bn1(self.conv1(x))))
        x = self.pool2(self.relu2(self.bn2(self.conv2(x))))
        x = self.flatten(x)
        x = self.dropout(self.fc1(x))
        x = self.fc2(x)
        return x

model = BaselineCNN()
# Load weights from Hugging Face Hub (after downloading the .pth file)
# model.load_state_dict(torch.load('mnist_baseline_cnn.pth'))

Citation
If you use this model, please cite the GitHub repository:
Ablation Study of CNN Architectures on MNIST
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train smd20/mnist-cnn-ablation-baseline

Space using smd20/mnist-cnn-ablation-baseline 1

Evaluation results