A light weight simple, multi layer ,feedforward neural network library
Project description
TINN
TINN acronym for Tiny Neural Network is a lightweight, neural network library,build over numpy.
Installation
You can download tinn using pip via pypi.
$ pip install tinn
Getting Started
Creating a neural network
Lets start by creating a 3 layer neural network
First start with importing the required modules
from tinn.neural import NeuralNet
from tinn.layer import Layer
A neural network is composed of a series of layers of neurons, such that all the neurons in each layer connect to the neurons in the next layer.
Lets see how to make a layer using tinn.
A layer in tinn requires 2 parameters
- num_neurons : No of neurons in that layer
- activation : Activation function for that layer
Lets create a layer with 5 neurons and sigmoid activation function
l1=Layer(5,'sigmoid')
Once the layer is created a neural network can be created by combining multiple layers using tinn.neural.NeuralNet
class.
model= NeuralNet() # Creates an empty neural network with 0 layers
model.add(Layer(3,'sigmoid') # Hidden layer with 3 neurons
model.add(Layer(5,'sigmoid') # Hidden layer with 5 neurons
model.add(Layer(1,'sigmoid') # Outpput layer with1 neuron
Above code creates a 3 layered neural network with 2 hidden layers and 1 output layer.
Training the model
tinn.neural.NeuralNet.train()
can be used to train the neural network on a given set of training data using stochastic gradient descent algorithm.
Here is the prototype of train method in NeuralNet class.
def train(self,inputData,outputData,learning_rate=0.01,epocs=100,suffle=True)
- inputData : An array of all inputs of the training set.
- outputData : Array of corresponding outputs of the training set.
- learning_rate : Could be used to tweak the learning rate parameter
- epocs : Default epocs is 100, it denotes the number of traning iterations over the given dataset
- suffle : If set to false, dataset will not be shuffled between epocs.
Accuracy of the model
tinn.neural.NeuralNet.validate()
is used to compute the accuracy of the model on given testing data. It returns a floating number between [0,1] inclusive where 1 represents 100 percent accuracy.
Prediction
Once the model is trained tinn.neural.NeuralNet.predict()
can be used to get the predicted outputs from the trained neural network.
Saving the model
tinn.neural.NeuralNet.save()
saves the model to a file.
NeuralNet.save(self,filepath)
Saves the model along with weights and architecture ,in the specified file, uses pickle module of python.
Loading the model
Trained model can be loaded from the file using tinn.neural.NeuralNet.load()
model=NeuralNet.load('handWrittenDigit.pkl')
Once loaded the model can be use for prediction.
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
File details
Details for the file tinn-2.1.tar.gz
.
File metadata
- Download URL: tinn-2.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.4.2 requests/2.21.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 795861cb1b5cfb4b0e1c1a1173a2d524369b10db81dac2b437ca7ee7ae087fa9 |
|
MD5 | d6f7c086b4f17d3c9051ea963f1a8ad6 |
|
BLAKE2b-256 | 7bed147bf2d55113d41e811c601a58cc8e7c60bc8a4c9669730d549f2b288c1e |