7 DigitNet from scratch
Programming for AI · AIC270 · Project

A neural network built
from scratch — no libraries.

Every weight, activation and gradient in this network was written by hand in NumPy. Draw a digit below and watch it think — live, in your browser.

98.51%Test accuracy
109,451Parameters learned
189,000Training images + augmented + junk
0ML libraries used

Live demo

Draw any digit from 0 to 9. The prediction updates in real time, with the model's confidence for every digit.

Challenge mode

The app names a digit — you draw it. One point for every correct draw.

–

Draw here

Model prediction

–
Draw a digit (0–9)

Watch the network think — live activations

Live camera · Bonus

Draw digits in the air with your webcam

No mouse, no touch — your camera watches your hand. Pinch your thumb and index finger together to draw, separate them to lift the pen. The same network predicts.

Open Air Writing

How it works

Three steps between your mouse and the answer — all of them implemented by hand.

1

You draw

Your drawing is shrunk to 28×28 pixels and centred by its centre of mass — exactly how the MNIST dataset was prepared, so the network sees what it expects.

2

The network thinks

784 pixel values flow through two hidden layers (128 and 64 neurons, ReLU). Every connection multiplies by a weight the network learned during training.

3

Softmax answers

The output layer turns eleven scores into probabilities that sum to 1 — ten digits plus a “not a digit” class trained on scribbles, arrows and half-drawn shapes, so junk gets rejected instead of guessed.

The network

Trained with hand-written backpropagation and mini-batch gradient descent on MNIST.

784Input · pixels
→
128Hidden · ReLU
→
64Hidden · ReLU
→
11Output · digits + reject

Backpropagation by hand

Gradients are computed with the chain rule, layer by layer, in plain NumPy — no autograd, no framework magic.

He initialisation

Weights start as small random values scaled by √(2/fan-in), keeping the signal stable through the ReLU layers.

Cross-entropy loss

Training loss fell from 0.201 to 0.032 over 12 epochs on 189,000 images — digits, augmented copies and 24,000 “not a digit” examples — while validation accuracy climbed to 98.56%.

Results

Measured on the 10,000-image MNIST test set — images the network never saw during training.

98.51%Overall test accuracy (9,851 / 10,000 correct)
99.65%Best digit — 1, the easiest to recognise
97.76%Hardest digit — 5, often confused with 3

Team

Programming for AI (AIC270) — COMSATS University Islamabad, Attock Campus. Instructor: Ms. Fouzia Jabeen.

AW

Abdul Wahid

FA24-BAI-024
Network core + integration

SS

Saeed Shah

FA24-BAI-032
Demo + interfaces

AD

Adan

FA24-BAI-059
Testing + report

Questions, answered

The things everyone asks about this project.

Because then the library would be doing the learning — and we would learn nothing. Writing the forward pass, the loss and backpropagation by hand is the whole point of the project; the demo is proof it works.

Not yet — by design. The same code can be retrained on EMNIST with a 36-unit output layer (10 digits + 26 letters). That is the documented next step, listed as future work in the report.

Very slanted, broken or unusually styled digits differ from MNIST handwriting. Centring helps, but a digit drawn in a corner or with gaps can still fool it — the confidence bars show when the model is unsure. Anything that is not a digit at all — a scribble, an arrow, half a shape — is rejected by a dedicated “not a digit” output it was trained on.

A second page where your webcam tracks your hand: pinch thumb and index finger together to draw in the air, separate them to lift the pen. The same network predicts. Try it from the button in the hero.

See the code behind the network

The full source, training notebook and project brain are open on GitHub.

View on GitHub