Skip to main content

A lightweight educational neural network library

Project description

QuackNet

The QuackNet is a python based library designed for building and training neural networks and convolutional networks from scratch. It offers foundational implementations of key components such as forward propagation, backpropagation and optimisation algorithms, without relying on machine learning frameworks like TensorFlow or Pytorch

Why this Library?

This project was developed to:

  • Deepen understanding of neural network by implementing them from scratch
  • Provide a lightweight alternative to large scale frameworks for educational purposes
  • Offer flexibility for experimentation with custom architectures

Features

1. Custom Implementation:

  • Fully handwritten implementations for neural network layers, activation functions and loss functions.
  • No reliance on external libraries for machine learning (except for numpy)

2. Core neural network functionality:

  • Support for common activation functions (eg.Leaky ReLU, Sigmoid, Softmax)
  • Multiple loss functions with derivatives (eg. MSE, MAE, Cross entropy)

3. Training:

  • includes backpropagation for gradient calculation and parameter updates
  • ability to experiment with different optimisation techniques.

Highlights

  • Custom Architectures: Define and train neural networks with fully customisable architectures
  • Optimisation Algorithms: Includes Gradient Descent, Stochastic Gradient Descent and Adam optimiser for efficient training
  • Loss and Activation Functions: Prebuilt support for common loss and activation functions with the option to make your own
  • Layer Support:
    • Fully Connected (Dense)
    • Convolutional
    • Pooling (max and Average)
    • Global Average Pooling
    • Activation layer
  • Evaluation Tools: Includes metrics for model evaluation such as accuracy and loss
  • Save and Load: Save weights and biases for reuse for further training
  • Demo Projects: Includes example implementations such as MNIST digit classification

Roadmap

  • Forward propagation Implemented the feed forward pass for neural network layers
  • Activation functions Added support for Leaky ReLU, Sigmoid, Softmax and others
  • Loss functions Implemented MSE, MAE and cross entropy loss with their derivatives
  • Backpropagation Completed backpropagation for gradient calculation and parameter updates
  • Optimisers Added support for batching, stochastic gradient descent and gradient descent
  • Convolutional Neural Network Implemented kernels, pooling and dense layers for Convolutional Neural Network
  • Visualisation tools
    Added support for visualising training, such as loss and accuracy graphs
  • Benchmark against PyTorch/TensorFlow Benchmark against popular machine learning frameworks on MNIST library
  • Add Adams optimiser
    Implement the Adam optimiser to improve training performance and convergence
  • Data augmentation add data augmentation such as flipping, rotation and cropping
  • Input Data augmentation: add normalisation of pixels and one hot labels
  • Skin Lesion detector
    use the neural network library to create a model for detecting skin lesions using HAM10000 for skin lesion images
  • Additional activation functions
    implement advanced activation functions (eg. GELU and Swish)

Usage

Here is an example of how to create and train a simple neural network using the library:

from quacknet.main import Network

# Define a neural network architecture
n = Network(
    lossFunc = "cross entropy",
    learningRate = 0.01,
    optimisationFunc = "sgd", #stochastic gradient descent
)
n.addLayer(3, "relu") # Input layer
n.addLayer(2, "relu") # Hidden layer
n.addLayer(1, "softmax") # Output layer
n.createWeightsAndBiases()

# Example data
inputData = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]
labels = [[1], [0]]

# Train the network
accuracy, averageLoss = n.train(inputData, labels, epochs = 10)

# Evaluate
print(f"Accuracy: {accuracy}%")
print(f"Average loss: {averageLoss}")

Examples

Code structure

Neural Network Class

  • Purpose Handles fully connected layers for standard neural network
  • Key Components:
    • Layers: Dense Layer
    • Functions: Forward propagation, backpropagation
    • Optimisers: SGD, GD, GD using batching

Convolutional Neural Network Class

  • Purpose Specialised for image data processing using convolutional layers
  • Key Components:
    • Layers: Convolutional, pooling, dense and activation layers
    • Functions: Forward propagation, backpropagation, flattening, global average pooling
    • Optimsers: Adams optimiser, SGD, GD, GD using batching

Benchmark

The library was benchmarked on the MNIST dataset using the following setup:

  • Model Architecture: 784 (input) → 128 → 64 → 10 (output)
  • Activation Function: Leaky Relu for input and hidden layer, and softmax for hidden layer
  • Optimiser: Batches
  • Batch Size: 64
  • Learning rate: 0.01
  • Epochs 10

Results:

  • Training accuracy: 97.1%
  • Average Loss: 0.10
  • Training Time: 30 seconds per epoch

Code:

The code for this benchmark can be found here

Training Performance

Below is the graph showing the training accuracy and loss over 10 epochs, across 5 runs:

Training Accuaracy

Benchmark Against Pytorch and Tensorflow

The library was benchmarked on the MNIST dataset using the following setup:

  • Neural Network Model Architecture: 784 (input) → 128 → 64 → 10 (output)
  • Activation Function: Leaky Relu for input and hidden layer, and softmax for hidden layer
  • Optimiser: Batches
  • Batch Size: 64
  • Learning rate: 0.01
  • Epochs 10

Results For QuackNet:

  • Training Accuracy: 97.1%
  • Average Loss: 0.10

Results For Pytorch:

  • Training Accuracy: 93.4%
  • Average Loss: 0.23

Results For Tensorflow:

  • Training Accuracy: 95.1%
  • Average Loss: 0.17

Code:

  • The code for the QuackNet benchmark can be found here
  • The code for the Pytorch benchmark can be found here
  • The code for the Tensorflow benchmark can be found here

Training Performance

Below is the graph showing the training accuracy and loss over 10 epochs, across 5 runs:

Training Accuaracy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quacknet-0.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quacknet-0.3-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file quacknet-0.3.tar.gz.

File metadata

  • Download URL: quacknet-0.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for quacknet-0.3.tar.gz
Algorithm Hash digest
SHA256 7aa610cab5b61a7c526b7df23a353d11acde6af9ea496d0d2faa24963e056301
MD5 0926bfc55ef317512606ac5dca9f84bd
BLAKE2b-256 2bc4989c8fbf71f6f0bceb36b7c474c20213ba1eae5a923b61dc0fedd1c31a66

See more details on using hashes here.

File details

Details for the file quacknet-0.3-py3-none-any.whl.

File metadata

  • Download URL: quacknet-0.3-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for quacknet-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 25aa88a228589c1a4c7da5db4eede7495f010862b8e584936ab0083d44124b67
MD5 1b41a8af703e769eabaf2b7d6baa1878
BLAKE2b-256 b340eb12210d6b1fa445434905303d883b9cf8f63b8131dc74b18b4d17e180c6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page