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.9.tar.gz (14.6 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.9-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for quacknet-0.9.tar.gz
Algorithm Hash digest
SHA256 c5dfb91824d339fcf75c92f6200d330ac9934b585846d64077228ac2521db31d
MD5 c2fa941c3491269e0b51a9ff952e7a23
BLAKE2b-256 48c9cdd7aad7de9d7b5b2fe87efd2265150b90e9ee871a9fd4b0903cd1676b01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quacknet-0.9-py3-none-any.whl
  • Upload date:
  • Size: 18.9 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 80ccf15fdbc2d27bc251804c9af144a51abcb24ee50d780e3beb243101650107
MD5 f3371ceaa1075bfc93649bb9c575550f
BLAKE2b-256 88b8621b31bf5306086f24997603662e62861014034f33d578aa7e574dd3d466

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