Skip to content

Library which can be used to build feed forward NN, Convolutional Nets, Linear Regression, and Logistic Regression Models.

Notifications You must be signed in to change notification settings

sharnam19/Networks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Networks - A Machine/Deep Learning Library

Machine Learning and Deep Learning Models from Scratch.
This Library allows users to create the following models:

  1. Feed-Forward Neural Networks
  2. Convolution Neural Networks
  3. Linear Regression
  4. Logistic Regression

Without having to write any backpropagation code.

To install the Networks Library

pip install networks

Layers in the Library & their Parameters in Add function

Activation Layers

1. Relu Layer

No Params

2. Sigmoid Layer

No Params

3. Tanh Layer

No Params

4. Leaky Relu Layer

No Params

Normalization Layers

1. Batch Normalization Layer

batch_params={
  'mode':'train'/'test',
  'momentum':0.9,
  'eps':1e-8
  }

2. Spatial Batch Normalization Layer

batch_params={
  'mode':'train'/'test',
  'momentum':0.9,
  'eps':1e-8
  }

Convolution Layers

1. Max Pooling Layer

pooling_params={
  'pooling_height':2,
  'pooling_width':2,
  'pooling_stride_height':2,
  'pooling_stride_width':2
}

2. Convolution Layer

num_kernels=64,
kernel_h=3,
kernel_w=3,
convolution_params={
  'stride':1
}

3. Padding Layer

padding_h=2,
padding_w=2

Loss Layers

1. Softmax Loss Layer

No params

2. SVM Loss Layer

No params

3. Mean Squared Error Layer

No params

4. Cross Entropy Loss Layer

No params

Fully Connected Layer

1. Affine Layer

affine_out = 64

2. Flatten Layer

No params

Example Usage

from networks.network import network
model = network(input_shape=(64,1,50,50),initialization="xavier2",
update_params={
  'alpha':1e-3,
  'method':'adam',
  'epoch':100,
  'reg':0.01,
  'reg_type':'L2',
  'offset':1e-7
})

To Add Padding Layer

model.add("padding",padding_h=3,padding_w=3)

To Add Convolution Layer

model.add("convolution",num_kernels=64,kernel_h=3,kernel_w=3,
convolution_params:{
    'stride':1
  })

To Add Relu Layer

model.add("relu")

To Add Pooling Layer

model.add("pooling",pooling_params={
  "pooling_height":2,
  "pooling_width":2,
  "pooling_stride_height":2,
  'pooling_stide_width':2
  })

To Add Batch Normalization Layer

model.add("batch_normalization",
batch_params={'mode':'train'/'test','momentum':0.9,'eps':1e-8})

To Add Spatial Batch Normalization Layer

model.add("spatial_batch",
batch_params={'mode':'train'/'test','momentum':0.9,'eps':1e-8})

To Add a Flatten Layer

model.add("flatten")

To Add Affine Layer

model.add("affine",affine_out=128)

To Add Softmax Loss Layer

model.add("softmax")

To Add SVM Loss Layer

model.add("svm")

To Add MSE Loss Layer

model.add("mse")

To Add Cross Entropy Loss Layer

model.add("cross_entropy")

To Save Model

model.save("model.json")

To Load Model

model = network.load("model.json")

To Train Model

model.train(X,y)

To Get Accuracy & Loss After Training

accuracy,loss = model.test(validX,validY)

To Predict

predictions = model.predict(X)