OCR_AI is a self-implemented neural network written in Python and powered only by NumPy. It recognizes handwritten digits from the MNIST dataset using a 28x28 input grid. This project is completely independent of machine learning libraries like TensorFlow or PyTorch and is intended for learning, experimentation, or lightweight deployment.
π‘ Inspired in part by "500 Lines or Less β Optical Character Recognition" by Marina Samuel. (Read it here)
The model processes 28x28 grayscale images (flattened into 784-dimensional vectors), runs them through a feedforward neural network, and outputs a digit prediction from 0 to 9.
The user draws a digit on the 28x28 canvas and gets a prediction in real time using the trained model.
The model updates its weights and biases in real time based on new user-supplied training samples.
OCR_AI/
β
βββ src/
β βββ ocr.py # Neural network logic
β βββ server.py # Web basic server to interact with the model
β βββ ocr.js # Input preprocessing
β βββ ocr.html # Page Structure
β βββ wb_training.py # Script to train the model using mnist
β βββ neural_network.json # Stored model weights
β
βββ README.md
βββ .gitignore
- Fully custom neural network:
- Input layer: 784 neurons (28x28 pixels)
- Hidden layer: customizable (default: 25 neurons)
- Output layer: 10 neurons (digits 0β9)
- Option to train the model on MNIST data or test existing model weights
- Simple training using
train_on_instance()for per-sample learning (batch: 1) - Model weights saved as JSON (
neural_network.json) - Activation functions: ReLU (default), support for sigmoid
- No machine learning libraries used β just NumPy
python src/server.py-
MNIST dataset: http://yann.lecun.com/exdb/mnist/
-
Base inspiration: 500 Lines or Less β Optical Character Recognition"* by Marina Samuel.
This project is licensed under the MIT License.

