Skip to content

Repository files navigation

neural-network

Two OCR applications built in Python, developed as a B.Eng. thesis at University of Pitești (grade 9.33/10). The project focuses on understanding neural networks from first principles, implementing everything from scratch before introducing a framework.


Projects

Project 1 — Neural Network from Scratch

A fully hand-rolled neural network for handwritten character recognition. No ML libraries — every component implemented manually.

Architecture:

  • Feedforward neural network with configurable input, hidden, and output layers
  • Sigmoid activation function throughout
  • Backpropagation implemented from scratch: delta computation for output and hidden neurons, weight update via gradient descent
  • Template-based training: each character drawn by hand in the template editor becomes a training sample

Applications:

  • Template Editor (tkinter GUI) — draw training shapes on a pixel canvas, save as templates
  • Neural Network Model — trains on the saved templates, learns character-to-output associations
  • Test Shape Editor (tkinter GUI) — draw new test inputs to feed to the trained network
  • Test Application — runs inference, shows predicted character

Key detail: The network learns that the same character drawn in a different style should map to the same output — generalization from hand-drawn variation, not pixel matching.

Note: The source code is written in Romanian. Feel free to fork and create an English version.

Usage:

  1. Run EditorSabloaneAntrenament.py — draw one or more training patterns for the network to learn. Saves pixel values (0/1) to sabloane antrenament.txt. More patterns = better training.
  2. Run ReteaNeuronalaAntrenament.py — trains the network until the gradient descends below a configurable threshold. Saves weights to ponderi.txt. You can also set a fixed number of epochs instead.
  3. Run EditorSabloaneTest.py — draw a test pattern for inference. Saves to sabloane test.txt. One pattern per run; running again overwrites the previous one.
  4. Run ReteaNeuronalaTest.py — loads weights and test pattern, computes output neuron activations, and prints the highest activation as the predicted label. Supports 10 labels (digits 0–9).

Project 2 — Keras / MNIST

A cleaner reimplementation using Keras/TensorFlow, trained on the MNIST dataset.

Architecture:

  • Dense layers with ReLU and Softmax activations
  • Adam optimizer
  • Trained on 60,000 MNIST samples, tested on 10,000
  • 97.5% accuracy on the test set

Applications:

  • Tensor Visualizer — displays MNIST images as 3D tensor graphs (raw pixel values) and grayscale, before and after normalization, using Matplotlib
  • Neural Network Model — Keras model definition and training
  • Test Application — inference on MNIST test samples (x_test[0], x_test[1000], etc.)

What's demonstrated

Concept Project 1 Project 2
Forward pass Manual Keras
Backpropagation Manual (from scratch) Keras (autograd)
Activation functions Sigmoid (manual) ReLU + Softmax
Training data Hand-drawn templates MNIST (60k samples)
Accuracy Template-dependent 97.5%
GUI Tkinter (template + test editors)
Visualization Matplotlib 3D tensor display

Tech Stack

Layer Technology
Language Python 3
ML (Project 1) None — from scratch
ML (Project 2) Keras / TensorFlow
Data Custom templates / MNIST
Visualization Matplotlib
GUI Tkinter
Numerics NumPy

Academic Context

B.Eng. thesis — "Application with neural networks in the Python language"
Faculty of Electronics, Communications and Computers, University of Pitești, 2020.
Grade: 9.33/10

Follow-up work: deepfake-animator — deepfake-powered 2D animation pipeline built on First Order Model (M.Sc. dissertation, grade 10/10).

About

Two OCR applications built in Python, developed as a B.Eng. thesis at University of Pitești (grade 9.33/10). The project focuses on understanding neural networks from first principles, implementing everything from scratch before introducing a framework.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages