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.


- 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).
- Node.js v14 or higher
- npm (comes with Node.js)
Optional:
- A modern browser (Chrome, Firefox, Safari) for the front-end.
-
Clone the repository
git clone https://github.com/knetic0/mnist-live-learning.git cd mnist-live-learning
-
Install dependencies
npm install
-
Configure environment
-
Copy
.env.example
to.env
and set any custom variables (e.g.,PORT
). -
Defaults:
PORT=3000
-
-
Run the server
npm start
Open your browser and navigate to http://localhost:3000
.
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.
- Select Train.
- Use the number input to choose the current label (0β9).
- Draw the digit on the canvas.
- Click Train to send a POST request to
/train
with the image blob and label.
- Select Predict.
- Draw a digit on the canvas.
- Click Predict to send a POST request to
/predict
with the image blob. - View the predicted digit on-screen.
The Express server (index.js
) exposes two endpoints:
-
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.
-
Description: Predict the class of a single drawing.
-
Request:
multipart/form-data
blob
(File): PNG image buffer.
-
Response: JSON object:
{ "prediction": <digit> }
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
- 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.
npm start
: Start the server in production mode.npm run dev
: Start the server withnodemon
for development (auto-reload on changes).
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/my-new-feature
. - Make your changes and commit:
git commit -am 'Add feature'
. - Push to the branch:
git push origin feature/my-new-feature
. - Open a Pull Request.
Ensure your code adheres to existing style and includes relevant tests or manual checks.
This project is licensed under the MIT License. See the LICENSE file for details.
- TensorFlow.js for client and server-side ML in JavaScript.
- The MNIST dataset and community contributions.