wenyun's picture
Update ML Intern artifact metadata
70e94ef verified
|
Raw
History Blame Contribute Delete
2.34 kB
---
tags:
- image-classification
- mnist
- digit-recognition
- pytorch
- onnx
- ml-intern
datasets:
- ylecun/mnist
metrics:
- accuracy
model-index:
- name: CNN MNIST Digit Recognition
results:
- task:
type: image-classification
dataset:
name: MNIST
type: ylecun/mnist
metrics:
- name: Accuracy
type: accuracy
value: 99.63
---
# 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
| 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% |
## 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](https://github.com/huggingface/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