Skip to content

knetic0/mnist-live-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LIVE-LEARNING: MNIST Trainer & Predictor

πŸ“„ Overview

LIVE-LEARNING is a real-time, browser-based MNIST digit trainer and predictor built with TensorFlow.js and Express.js. Users can draw handwritten digits on a canvas, train a convolutional neural network (CNN) model with their own samples, and perform live predictionsβ€”all in a seamless web interface.

image image

✨ Features

  • Interactive Canvas UI: Draw digits (0–9) directly in the browser.
  • On-Demand Training: Submit drawn digits with labels to train the model incrementally.
  • Live Prediction: Switch to prediction mode to classify new drawings in real time.
  • Model Persistence: Automatically save and load the trained model to disk every hour.
  • Lightweight Backend: Server built on Express.js and TensorFlow.js (Node.js).

πŸš€ Prerequisites

  • Node.js v14 or higher
  • npm (comes with Node.js)

Optional:

  • A modern browser (Chrome, Firefox, Safari) for the front-end.

πŸ› οΈ Installation

  1. Clone the repository

    git clone https://github.com/knetic0/mnist-live-learning.git
    cd mnist-live-learning
  2. Install dependencies

    npm install
  3. Configure environment

    • Copy .env.example to .env and set any custom variables (e.g., PORT).

    • Defaults:

      PORT=3000
  4. Run the server

    npm start

Open your browser and navigate to http://localhost:3000.

🎨 Front-End Usage

The front-end lives in the public folder:

  • index.html: Main UI with canvas and control buttons.
  • app.js: Canvas drawing logic, mode toggling (Train/Predict), and API calls.
  • styles.css: Basic styling and layout.

Training Mode

  1. Select Train.
  2. Use the number input to choose the current label (0–9).
  3. Draw the digit on the canvas.
  4. Click Train to send a POST request to /train with the image blob and label.

Prediction Mode

  1. Select Predict.
  2. Draw a digit on the canvas.
  3. Click Predict to send a POST request to /predict with the image blob.
  4. View the predicted digit on-screen.

πŸ”Œ Back-End API

The Express server (index.js) exposes two endpoints:

POST /train

  • Description: Train the model on a single sample.

  • Request: multipart/form-data

    • blob (File): PNG image buffer of the 28Γ—28 pixel drawing.
    • label (Number): Digit label (0–9).
  • Response: HTTP 200 on success.

POST /predict

  • Description: Predict the class of a single drawing.

  • Request: multipart/form-data

    • blob (File): PNG image buffer.
  • Response: JSON object:

    { "prediction": <digit> }

πŸ“‚ Project Structure

LIVE-LEARNING
β”œβ”€β”€ public/           # Front-end (HTML, JS, CSS, assets)
β”œβ”€β”€ node_modules/     # npm dependencies
β”œβ”€β”€ model/            # Saved TensorFlow.js model files (auto-created)
β”œβ”€β”€ .env              # Environment variables
β”œβ”€β”€ .gitignore        # Ignored files and folders
β”œβ”€β”€ index.js          # Express server setup and routes
β”œβ”€β”€ train.js          # TensorFlow.js model definition, train & predict logic
β”œβ”€β”€ package.json      # Project metadata and scripts
β”œβ”€β”€ README.md         # Project documentation (you are here)
└── package-lock.json # Exact dependency versions

βš™οΈ Configuration

  • PORT: Port on which the Express server runs (default: 3000).
  • MODEL_DIR: Directory for saving/loading the trained model (default: ./model).

Adjust these in the .env file or environment before starting the server.

πŸ“ Scripts

  • npm start: Start the server in production mode.
  • npm run dev: Start the server with nodemon for development (auto-reload on changes).

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/my-new-feature.
  3. Make your changes and commit: git commit -am 'Add feature'.
  4. Push to the branch: git push origin feature/my-new-feature.
  5. Open a Pull Request.

Ensure your code adheres to existing style and includes relevant tests or manual checks.

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ™ Acknowledgments

  • TensorFlow.js for client and server-side ML in JavaScript.
  • The MNIST dataset and community contributions.

About

πŸ”₯ Everyone is Trainer on this project. Deep Learning with TF.js & MNIST Dataset.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published