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 neuralLibrary.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
- Simple Neural Network Example: A basic neural network implementation demonstrating forward and backpropagation
- Convolutional Neural Network Example: Shows how to use the convolutional layers in the library
- MNIST Neural Network Example: Shows how to use neural network to train on MNIST
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:
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quacknet-0.1.tar.gz.
File metadata
- Download URL: quacknet-0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a08a17644e26eb1a623745bd32a6436779c9c1a9e2c10fdae51bf70746e8ae0e
|
|
| MD5 |
a9f5ca2f5c63ab19e837bcaf4805c8fa
|
|
| BLAKE2b-256 |
df75f6c9980b599500a679554ecbf971ef8229abd2a718219c1588996808cfce
|
File details
Details for the file quacknet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: quacknet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
882ecd308e2e245c73f298d245440e400db18f718b508df36b881ba8e34c789b
|
|
| MD5 |
6d5379ff41f7ea3abab8fd30807b467e
|
|
| BLAKE2b-256 |
847e794f2567836c8702ed55b172f8e0ab57479326e755193847bf7e774a6057
|
File details
Details for the file quacknet-0.1-py3-none-any.whl.
File metadata
- Download URL: quacknet-0.1-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dee12684284abeea9640f549de1c3a4b72838a27cb710d8fd0b7488dbf4a9fbd
|
|
| MD5 |
c7daf4daf848dd73bfbb07fa802f53f9
|
|
| BLAKE2b-256 |
06c0ba3935c7f249becf81a68a53311045a4b82b12501ec44291cd1a12810523
|