Package: pileoffeather
pile of featherPileoffeather 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.Documentation|ExamplesInstall modulepip install pileoffeatherExamplesexamples/image_classifierHandwritten 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 modelfrompileoffeatherimportnn,data_loaderimportnumpyasnp#Create neural network modelmodel=nn.create(name="test1",layers=[[400,'input'],[30,'relu'],[10,'relu'],[1,'sigmoid']])#Load and prepare datasetones=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 modelnn.mbgd(model,input,output,batch_size=16,epoch_number=10,rate=0.6)This second code snippet is used to run the trained modelfrompileoffeatherimportnn,data_loader#Load neural network modelmodel=nn.load(name="test1")#Load example input imageinput=data_loader.loadImage("example_image_one.png",(20,20),"grayscale")#Run the neural network modeloutput=model.run(input)print(output)DocumentationThe 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 modulefrompileoffeatherimportnn#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 modelmodel=nn.load(name="test1")#Mini-batch gradient descent, parallel backprop execution on each run of the mini-batchnn.mbgd(model,input_matrix,output_matrix,batch_size=16,epoch_number=100,rate=0.03)#Save the modelmodel.save()#Use the neural networkoutput=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 modulefrompileoffeatherimportdata_loader#Load dataset of images from local folderdataset=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 = 255dataset=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")TODOAdd audio support on data_loader.pyAdd recurrent neural networks and common architectures like transformer or ganPossibility to live graph loss, accuracy or similar stats during training