Lightweight and easy to use ml library for small projects, create a neural network in minutes.
Project description
pile of feather
Pileoffeather is not an alternative to big ml library like pytorch or tensorflow, it lacks features and optimization, such as gpu support. The goal is to create a lightweight library of about 100 lines of code that is easy to use and quick to implement for creating small projects or experiment with ml.
Install module
pip install pileoffeather
Examples
examples/image_classifier
Handwritten digit image classifier, dataset is made out of 500 images of ones and 500 images of zeros taken from the mnist dataset. The first code snippet is defining the neural network model, uploading the dataset and than training the model
from pileoffeather import nn, data_loader
import numpy as np
#Create neural network model
model = nn.create(name = "test1", layers = [[400, 'input'], [30, 'relu'], [10, 'relu'], [1, 'sigmoid']])
#Load and prepare dataset
ones = data_loader.load(data_type = "image", color = "grayscale", folder = "ones", resize = (20,20))
zeros = data_loader.load(data_type = "image", color = "grayscale", folder = "zeros", resize = (20,20))
input = np.vstack((ones, zeros))
output = np.concatenate((np.ones(500), np.zeros(500)))
#Train the neural network and save the model
nn.mbgd(model, input, output, batch_size = 16, epoch_number = 10, rate = 0.6)
This second code snippet is used to run the trained model
from pileoffeather import nn, data_loader
#Load neural network model
model = nn.load(name = "test1")
#Load example input image
input = data_loader.loadImage("example_image_one.png", (20,20), "grayscale")
#Run the neural network model
output = model.run(input)
print(output)
Documentation
The module consists of 3 files: nn.py (create and train nn), data_loader.py (for loading and converting data) and engine.py (Hidden core neural network engine < 100 lines of code).
nn.py - neural network module
#Import module
from pileoffeather import nn
#Define neural network model, the available activation functions are "sigmoid","relu","leakyRelu"
model = nn.create(name = "test1", layers = [[400,""],[50,"relu"],[10,"relu"],[1,"sigmoid"]])
#Load an exsisting model
model = nn.load(name = "test1")
#Mini-batch gradient descent, parallel backprop execution on each run of the mini-batch
nn.mbgd(model, input_matrix, output_matrix, batch_size = 16, epoch_number = 100, rate = 0.03)
#Save the model
model.save()
#Use the neural network
output = model.run(input)
#Compute single mini_batch pass, model.computeBatch(batch_input, batch_output, batch_size, learning_rate)
model.computeBatch(batch_input, batch_output, 16, 0.3)
#Pop a layer out of the neural network model (ex. remove layer at index 2)
model.pop(2)
#Insert a model layers over an other model, training is preserved (ex. at index 2)
model.insert(model1,2)
data_loader.py - data load module
#Import module
from pileoffeather import data_loader
#Load dataset of images from local folder
dataset = data_loader.load(data_type = "image", color = "grayscale", folder = "folder_name_containing_all_images", resize = (20,20))
#Load training input data of mnist, normalize input from 0 to 1 using divide = 255
dataset = data_loader.load(data_type = "gz", path = "train-images-idx3-ubyte.gz", start_index = 16, input_number = 784, divide = 255)
#Load training output data of mnist, use one_hot encoding to convert a decimal number to an array
#4 -> [0,0,0,0,1,0,0,0,0,0] 0 -> [1,0,0,0,0,0,0,0,0,0]
dataset = data_loader.load(data_type = "gz", path = "train-labels-idx1-ubyte.gz", start_index = 8, one_hot = 10)
#Load a single image to feed the neural network loadImage(name, resize, color)
input = data_loader.loadImage("example_image.png", (20,20), "grayscale")
#Convert neural network output to image and save, saveImage(neural_network_output, image_path, resize, color)
data_loader.saveImage(neural_network_output, "image_path_and_name", (20,20), "grayscale")
TODO
- Add audio support on data_loader.py
- Add recurrent neural networks and common architectures like transformer or gan
- Possibility to live graph loss, accuracy or similar stats during training
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
File details
Details for the file pileoffeather-0.4.2.tar.gz
.
File metadata
- Download URL: pileoffeather-0.4.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 519de77e29a56155cfe0d64bfc39017a30c0734e76397819318bfe88b4b873a0 |
|
MD5 | 44fb60c974a39ae33035b010dc48725e |
|
BLAKE2b-256 | 0375e872ea31aa100c65de444ed65acf282fda772d930d5afd76e197478fbea0 |