Tiny VGG (MNIST)

A small VGG-style CNN trained from scratch on MNIST. Built as coursework for Сучасні методи розпізнавання образів (Modern Pattern Recognition Methods), Kharkiv National University of Radio Electronics, group ІНФм-25-1.

Test accuracy: 98.89% (9889 / 10000 on the MNIST test split).

Architecture

Block 1:  Conv2d(1→20, k=3, p=1)  → ReLU → Conv2d(20→20, k=3, p=1) → ReLU → MaxPool(2,2)
Block 2:  Conv2d(20→40, k=3, p=1) → ReLU → Conv2d(40→40, k=3, p=1) → ReLU → MaxPool(2,2)
Head:     Flatten → Linear(1960→160) → Dropout(0.3) → ReLU → Linear(160→10)

340,870 parameters. Output is raw logits — apply softmax yourself if you need probabilities.

Training

Dataset MNIST (60k train / 10k test)
Preprocessing ToTensor() only — no normalisation
Loss CrossEntropyLoss
Optimizer RMSprop, lr = 0.003
Batch size 40
Epochs 9
Seed 42

Usage

import torch
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file

from modeling import CustomCNN  # also in this repo

weights = hf_hub_download("sytossml/mnist-tiny-vgg", "model.safetensors")
model = CustomCNN()
model.load_state_dict(load_file(weights))
model.eval()

# x: float tensor of shape [B, 1, 28, 28] with values in [0, 1]
with torch.inference_mode():
    preds = model(x).argmax(dim=1)

Limitations

Trained only on MNIST, so it expects 28×28 grayscale digits centred and scaled the way MNIST is, on a black background with values in [0, 1]. Photographs of handwriting, inverted colours, or off-centre digits will degrade accuracy sharply. It is a teaching exercise, not a production OCR model.

Downloads last month
14
Safetensors
Model size
341k params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train sytossml/mnist-tiny-vgg

Space using sytossml/mnist-tiny-vgg 1