CoolFace
Modelpublic

wenyun/cnn-mnist-digit-recognition

sourceHugging Faceupdated 5mo agoView on Hugging Face
2likes16downloads
Model Card

CNN MNIST Digit Recognition

A compact CNN trained on MNIST for handwritten digit recognition.

Performance

  • —Test Accuracy: 99.63%
  • —Parameters: 175,594
  • —Training: 20 epochs on Apple M5 (MPS) in ~12 minutes

Architecture

  • —3 convolutional blocks with BatchNorm + Dropout
  • —Global average pooling → FC classifier
  • —Input: 28×28 grayscale images
  • —Output: 10 classes (digits 0-9)

Per-class Accuracy

DigitAccuracy
0100.00%
199.91%
299.71%
399.90%
499.49%
599.22%
699.48%
799.42%
899.59%
999.50%

Usage

python
import torch
from PIL import Image
from torchvision.transforms import Compose, ToTensor, Normalize, Resize, Grayscale

# Load model
checkpoint = torch.load("model.pt", map_location="cpu")

# Preprocess (28x28 grayscale, normalized)
transform = Compose([
    Grayscale(1),
    Resize((28, 28)),
    ToTensor(),
    Normalize((0.1307,), (0.3081,)),
])

image = Image.open("digit.png")
tensor = transform(image).unsqueeze(0)

# Predict
model.eval()
with torch.no_grad():
    logits = model(tensor)
    prediction = logits.argmax(dim=1).item()
    confidence = torch.softmax(logits, dim=1).max().item()
    
print(f"Predicted digit: {prediction} (confidence: {confidence:.2%})")

Training Details

  • —Dataset: MNIST (60K train / 10K test)
  • —Optimizer: AdamW (lr=1e-3, weight_decay=1e-4)
  • —Scheduler: OneCycleLR (cosine annealing)
  • —Augmentation: Random rotation ±15°, affine transforms (translate, scale, shear)
  • —Regularization: Dropout (0.25 conv, 0.5 FC) + BatchNorm

<!-- ml-intern-provenance -->

Generated by ML Intern

This model repository was generated by ML Intern, an agent for machine learning research and development on the Hugging Face Hub.

  • —Try ML Intern: https://smolagents-ml-intern.hf.space
  • —Source code: https://github.com/huggingface/ml-intern