Skip to content

fella0x/ffnn-mnist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MNIST Digit Classifier - Nerual Network Implementated From Scratch in NumPy

Results

This project implements a fully connected neural network from scratch using NumPy to classify handwritten digits from the MNIST dataset.

The goal of the project was to understand the internal mechanics of nerual networks without relying on deep learning framrworks.

Architecture

Input layer: 784 (28x28 flattened image) Hidden layer: 256 neurons with ReLU activation Output layer: 10 neurons with Softmax activation

Features Implemented

  • Forward propagation
  • Backpropagation
  • Cross-entropy loss
  • Mini-batch stochastic gradient descent
  • Learning rate scheduling
  • Validation set monitoring
  • L2 regularisation
  • Early checkpoint selection

Results

Test Accuracy: ~98%

Training time: ~1 minute on CPU

Project Structure

MNIST.py

  • Loads the MNIST dataset using tensorflow.keras.datasets
  • Normalises image values
  • Flattens images into 784-dimensional vectors
  • Splits training into training and validation sets

model.py

  • Weight initialisation
  • Forward propagation
  • Backpropagation
  • Gradient Descent Update
  • Training step logic
  • Accuracy and loss computation
  • Full training of the model

utils.py

Includes functions used by the network:

  • ReLU activation + gradient
  • Softmax
  • Cross-entropy
  • Linear-layer computation

results/

Contains a visualisation of the output on the trained model (random state = 42 for replication)

requirements.txt

Lists Python dependencies required

Requirements

Install dependencies: pip install -r requirements.txt

Running the Project

Run training with: MNIST.py

Dataset

The MNIST dataset is loaded via tensorflow.keras.datasets

Images are normalised and flattened into 784-dimensional vectors before training

Purpose

This project focuses on building neural network training logic from first principles to better understand:

  • gradient descent
  • backpropagation
  • weight initialisation
  • optimisation behavior
  • feature learning

Future Improvements

  • Convolutional neural network implementation
  • Batch normalisation
  • Dropout regularisation
  • Hyperparameter search

About

MNIST Digit Classifier - Neural Network Implemented From Scratch in NumPy

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages