A modern web application that uses machine learning to recognize handwritten digits in real-time. Draw numbers on a 200x200px canvas and watch AI predict them instantly using TensorFlow.js with 10 different model architectures for comparison.
- Interactive Canvas: Draw digits with mouse or touch input
- Real-time Recognition: Instant AI predictions as you draw
- 10 Model Architectures: Compare different AI models side-by-side
- Model Comparison: Switch between single model view and comparison mode
- Modern UI: Beautiful, responsive three-pane layout
- Multiple Predictions: See top 3 predictions with confidence scores
- Mobile Friendly: Works on desktop, tablet, and mobile devices
- Fallback Mode: Works even without trained models
- Brush Controls: Adjustable brush size for different line thickness
- Auto-Reload Development: Automatic browser refresh during development
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- Machine Learning: TensorFlow.js
- Canvas API: HTML5 Canvas for drawing
- Model Training: Python, TensorFlow/Keras
- Styling: CSS Grid, Flexbox, CSS Animations
DigitRecognizer/
โโโ index.html # Main HTML file
โโโ styles/
โ โโโ main.css # Main stylesheet
โโโ scripts/
โ โโโ canvas.js # Canvas drawing functionality
โ โโโ ml-model.js # TensorFlow.js model handling
โ โโโ app.js # Main application logic
โโโ models/
โ โโโ digit-recognizer.json # Pre-trained model (TensorFlow.js format)
โโโ training/
โ โโโ train_model.py # Python script to train the model
โ โโโ convert_model.py # Script to convert model to TensorFlow.js
โ โโโ requirements.txt # Python dependencies
โโโ assets/
โ โโโ images/ # Static images/icons
โโโ README.md # This file
โโโ plan.md # Detailed implementation plan
# Start development server with auto-reload
./dev.sh
# Or use npm script
npm run dev
# Or run directly
python3 simple_dev_server.pyThe development server will:
- Start on http://localhost:8000
- Automatically open your browser
- Watch for file changes and reload the browser
- Show console messages when files change
-
Clone the repository
git clone https://github.com/yourusername/DigitRecognizer.git cd DigitRecognizer -
Open in browser
# Using Python's built-in server python -m http.server 8000 # Or using Node.js npx serve . # Or simply open index.html in your browser
-
Start drawing!
- The app will work in fallback mode without a trained model
- Draw digits on the canvas and see predictions
-
Set up Python environment
cd training pip install -r requirements.txt -
Train the model
python train_model.py
-
Convert to TensorFlow.js format
python convert_model.py --input models/digit_recognizer_model.h5 --output ../models/digit-recognizer
-
Run the web app
cd .. python -m http.server 8000
- Draw a digit: Use your mouse or touch to draw a number (0-9) on the canvas
- See predictions: Watch real-time AI predictions with confidence scores
- Clear canvas: Click the "Clear Canvas" button or press 'C' key
- Adjust brush: Use the brush size slider for different line thickness
- View details: See top 3 predictions with probability bars
- Type: Convolutional Neural Network (CNN)
- Input: 28x28 grayscale images
- Output: 10 classes (digits 0-9)
- Architecture:
- 3 Convolutional blocks with Batch Normalization
- MaxPooling and Dropout for regularization
- Dense layers with dropout
- Softmax output layer
- Dataset: MNIST (60,000 training, 10,000 test images)
- Data Augmentation: Rotation, shifting, zooming
- Optimizer: Adam
- Loss Function: Categorical Crossentropy
- Callbacks: Early stopping, learning rate reduction
- Accuracy: >99% on MNIST test set
- Model Size: <5MB (optimized for web)
- Inference Time: <100ms on modern browsers
- Modern web browser with WebGL support
- Python 3.7+ (for training)
- Node.js (optional, for development server)
-
Clone and setup
git clone https://github.com/yourusername/DigitRecognizer.git cd DigitRecognizer -
Start development server
# Using Python python -m http.server 8000 # Using Node.js npx serve . # Using VS Code Live Server extension # Right-click index.html -> "Open with Live Server"
-
Open browser
http://localhost:8000
-
Install dependencies
cd training pip install -r requirements.txt -
Train model
python train_model.py
-
Convert to web format
python convert_model.py
-
Test the model
cd .. python -m http.server 8000
- โ Chrome 60+
- โ Firefox 55+
- โ Safari 11+
- โ Edge 79+
- โ Mobile browsers (iOS Safari, Chrome Mobile)
Edit styles/main.css to customize:
- Colors and themes
- Layout and spacing
- Animations and transitions
- Responsive breakpoints
Modify training/train_model.py to:
- Change model architecture
- Adjust training parameters
- Add data augmentation
- Experiment with different optimizers
Update scripts/canvas.js to:
- Change canvas size
- Modify brush behavior
- Add drawing tools
- Implement undo/redo
Deploy to any static hosting service:
- GitHub Pages: Push to
gh-pagesbranch - Netlify: Connect GitHub repository
- Vercel: Import project
- Firebase Hosting: Use Firebase CLI
# Build and deploy
git add .
git commit -m "Deploy DigitRecognizer"
git push origin main
# Enable GitHub Pages in repository settings
# Set source to main branch# Install Netlify CLI
npm install -g netlify-cli
# Deploy
netlify deploy --prod --dir .- Test drawing on different devices
- Verify predictions are reasonable
- Check responsive design
- Test keyboard shortcuts
- Test in multiple browsers
- Check mobile responsiveness
- Verify touch events work
- Test with different screen sizes
- Use model quantization
- Implement model pruning
- Optimize for mobile devices
- Use WebGL acceleration
- Enable gzip compression
- Use CDN for model files
- Implement lazy loading
- Optimize images and assets
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style
- Add comments for complex logic
- Test on multiple browsers
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- MNIST Dataset: Yann LeCun, Corinna Cortes, Christopher Burges
- TensorFlow.js: Google's machine learning library for JavaScript
- TensorFlow: Google's open-source machine learning platform
- CSS Grid: Modern CSS layout system
- HTML5 Canvas: For drawing functionality
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed description
- Include browser version and error messages
- Provide steps to reproduce the problem
- Multi-digit recognition
- Custom model training interface
- Real-time collaboration
- Mobile app version
- API for external applications
- Advanced drawing tools
- Prediction history and analytics
- Model comparison features
- Improved model accuracy
- Better mobile experience
- Performance optimizations
- Multi-digit support
- Custom training interface
- Export/import functionality
- Real-time collaboration
- Advanced analytics
- API integration
Made with โค๏ธ and TensorFlow.js
Draw, predict, and explore the world of machine learning in your browser!