Skip to content

🧠 OCR Neural Network A handwritten digit recognition system built from scratch using a simple feedforward neural network. Accepts 28Γ—28 pixel grayscale inputs and classifies them into digits (0–9). Includes training, prediction, and a web-based drawing canvas.

License

Notifications You must be signed in to change notification settings

TiagoSBittencourt/OCR-From-Scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 OCR_AI – Lightweight Neural Network for Handwritten Digit Recognition (No ML Libraries)

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)


πŸ“Έ Example Use Case

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.

🎬 Demo

Live Testing (Drawing in the Browser)

The user draws a digit on the 28x28 canvas and gets a prediction in real time using the trained model.

Demo: Live Prediction

Training on MNIST Dataset

The model updates its weights and biases in real time based on new user-supplied training samples.

Demo: Training Process

πŸ“ Project Structure

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


πŸ”§ Features

  • 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

πŸš€ Run the Server

python src/server.py

πŸ™ Credits

πŸ“ License

This project is licensed under the MIT License.

About

🧠 OCR Neural Network A handwritten digit recognition system built from scratch using a simple feedforward neural network. Accepts 28Γ—28 pixel grayscale inputs and classifies them into digits (0–9). Includes training, prediction, and a web-based drawing canvas.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors