ylecun/mnist
Viewer • Updated • 70k • 118k • 246
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.