This project implements a Convolutional Neural Network (CNN) for digit classification on the MNIST dataset using PyTorch with a web interface for live predictions.
🎯 Project Overview
The project consists of:
Data Loader (data_loader.py): Parses MNIST idx-ubyte binary files
CNN Model (model.py): 2-layer convolutional neural network
Training Script (train.py): Model training with visualization
Web Application (app.py): Flask web server with interactive digit drawing
Generate training history plots (training_history.png)
Display test accuracy
Expected output:
CNN Training Script (PyTorch)
============================================================
Using device: cpu
[1/5] Loading data...
✓ Loaded 60000 training samples and 10000 test samples
[2/5] Preprocessing data...
✓ Data preprocessed and loaded
Training samples: 54000
Validation samples: 6000
Test samples: 10000
[3/5] Creating model...
...
[4/5] Training model...
Epoch 1/10 - Train Loss: 0.2345, Train Acc: 0.9234 - Val Loss: 0.1234, Val Acc: 0.9567
...
[5/5] Evaluating model...
✓ Test Accuracy: 0.9812 (98.12%)
✓ Model saved to: mnist_cnn_model.pth
2. Start the Web Application
python app.py
The web server will start on http://localhost:5000
3. Use the Web Interface
Open your browser and navigate to http://localhost:5000
Draw a digit (0-9) on the canvas
Click "🔮 Predict" to see the model's prediction
View confidence scores and probability distribution
Click "🗑️ Clear" to draw again
🎨 Web Interface Features
Interactive Drawing Canvas: Draw digits with your mouse or touch
Real-time Predictions: Get instant predictions with confidence scores
Probability Visualization: See probability distribution for all digits (0-9)
Modern UI: Beautiful gradient design with smooth animations