Downloads · 30 days
6
15% of all-time downloads
deepshah23/digit-blank-classifier-cnn
digit-blank-classifier-cnn is a image classification model from deepshah23. Use it when you need a label for an image. The card lists the license as gpl-3.0.
A high-accuracy convolutional neural network trained to classify handwritten digits from the MNIST and EMNIST Digits datasets, and additionally detect blank images (unfilled boxes) as a distinct class. This model is t…
Downloads · 30 days
6
15% of all-time downloads
All-time downloads
40
Public
Repo size
10.8 MB
Likes
0
Public
Click a slice to open those files.
.pt3.6 MB · 34%
From the Hugging Face model README
A high-accuracy convolutional neural network trained to classify handwritten digits from the MNIST and EMNIST Digits datasets, and additionally detect blank images (unfilled boxes) as a distinct class. This model is trained using PyTorch and exported in TorchScript format (.pt) for reliable and portable inference.
This model is licensed under the AGPL-3.0 license to comply with the Plom Project licensing requirements.
Authors & Credits:
.pt), ONNX (.onnx)10 to simulate unfilled regionsTo improve generalization and robustness to handwriting variation:
RandomRotation(±10°)RandomAffine: scale (0.9–1.1), translate (±10%)These transformations simulate handwritten noise and variation in real student submissions.
Input: (1, 28, 28)
↓ Conv2D(1 → 32) + BatchNorm + ReLU
↓ Conv2D(32 → 64) + BatchNorm + ReLU
↓ MaxPool2d(2x2) + Dropout(0.1)
↓ Conv2D(64 → 128) + BatchNorm + ReLU
↓ MaxPool2d(2x2) + Dropout(0.1)
↓ Flatten
↓ Linear(128*7*7 → 128) + BatchNorm + ReLU + Dropout(0.2)
↓ Linear(128 → 11)
→ Output: class logits (digits 0–9, blank = 10)
| Hyperparameter | Value |
|---|---|
| Optimizer | Adam (lr=0.001) |
| Loss Function | CrossEntropyLoss |
| Scheduler | ReduceLROnPlateau |
| Early Stopping | Patience = 5 |
| Epochs | Max 50 |
| Batch Size | 64 |
| Device | CPU or CUDA |
| Random Seed | 42 |
| Metric | Value |
|---|---|
| Test Accuracy | 99.73% |
| Blank Image Accuracy | 100.00% |
All 5,000 blank images were correctly classified.
import torch
# Load TorchScript model
model = torch.jit.load("mnist_emnist_blank_cnn_v1.pt")
model.eval()
# Dummy input (1 image, 1 channel, 28x28)
img = torch.randn(1, 1, 28, 28)
# Predict
with torch.no_grad():
out = model(img)
predicted = out.argmax(dim=1).item()
print("Predicted class:", predicted)
import onnxruntime as ort
import numpy as np
# Load ONNX model
session = ort.InferenceSession("mnist_emnist_blank_cnn_v1.onnx", providers=["CPUExecutionProvider"])
# Dummy input
img = np.random.randn(1, 1, 28, 28).astype(np.float32)
# Predict
outputs = session.run(None, {"input": img})
predicted = int(outputs[0].argmax(axis=1)[0])
print("Predicted class:", predicted)
If the prediction is
10, the model considers the image to be blank (no digits present).
train_digit_classifier.py: Training script with full documentationmnist_emnist_blank_cnn_v1.pth: Final trained model weightsmnist_emnist_blank_cnn_v1.pt: TorchScript export for deploymentmnist_emnist_blank_cnn_v1.onnx: ONNX export for deploymentrequirements.txt: Required dependencies for training or inferenceThis model was designed to support the Plom Project’s student ID digit detection system, helping automatically identify handwritten digits (and detect blank/unfilled boxes) from scanned exam sheets.
It may also be adapted for other handwritten digit classification tasks or real-time blank field detection applications.
<!-- --- ## Maintainer & Contact - **Deep Shah** — [Hugging Face Profile](https://huggingface.co/deepshah23) - For Plom inquiries: [The Plom Project GitLab](https://gitlab.com/plom/plom) -->