Downloads · 30 days
8
8% of all-time downloads
wenyun/cnn-mnist-digit-recognition
cnn-mnist-digit-recognition is a image classification model from wenyun. Use it when you need a label for an image.
A compact CNN trained on MNIST for handwritten digit recognition.
Downloads · 30 days
8
8% of all-time downloads
All-time downloads
105
Public
Repo size
1.5 MB
Likes
2
Public
Click a slice to open those files.
.pt719 KB · 50%
From the Hugging Face model README
A compact CNN trained on MNIST for handwritten digit recognition.
| Digit | Accuracy |
|---|---|
| 0 | 100.00% |
| 1 | 99.91% |
| 2 | 99.71% |
| 3 | 99.90% |
| 4 | 99.49% |
| 5 | 99.22% |
| 6 | 99.48% |
| 7 | 99.42% |
| 8 | 99.59% |
| 9 | 99.50% |
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%})")
This model repository was generated by ML Intern, an agent for machine learning research and development on the Hugging Face Hub.