Skip to content

Deep Learning Framework Implementation from scratch

Notifications You must be signed in to change notification settings

AmrElsersy/DL-Framework

Repository files navigation

Pyray2 Deep Learning Framework

Pyray2 is a deep learning framework implemnted from scratch using python and libraries such as numpy, matplotlib, pandas.

How to Install

 $ pip install pyray2

How to use ?

Check Colab:

UML Design

DL_Framework_UML

Supported Features

Layers

  • Convolution 2D
  • Dense
  • Max Pooling
  • Avg Pooling

Activations

  • Sigmoid
  • RelU
  • Softmax
  • Tanh

Losses

  • Mean Square Error
  • Cross Entropy

How to define a Model:

# Example
model = Model()
model.add(conv(1, 4, 3, padding=1))
model.add(MaxPool2D(kernel_size=(2,2)))
model.add(ReLU())
model.add(Flatten())
model.add(Dense(8*7*7, 10))
model.set_loss(CrossEntropyLoss())

Optimizers

  • Gradiant Decent
  • Momentum
  • Adam
optim = GradientDecent(model.parameters(), learning_rate = 0.01)
optim = MomentumGD(model.parameters(), learning_rate = 0.01)
optim = Adam(model.parameters(), learning_rate = 0.01)
lr_schedular = StepLR(optimizer, step_size = 1, gamma=0.1)

Visualization

  • View dataset's examples
  • Plotting for loss
  • live graph
# Show Dataset Examples
image, labels = dataloader.__getitem__(1)
images = image.T.reshape(batch_size, 1, width, height)
images = np.asarray(images)
img_viewer_examples(images, labels.tolist()[0], greyscale= True)

# Plotting Loss
model.graph()
# Training Loop ...

# Before the loop to start new thread
model.startGraph()

# Training Loop ...

# After the loop to close the thread
model.stopGraph()

Linear live graph gif

Evaluation

  • Precision
  • Recall
  • F1 Score
e = Evaluation(10)
for image, label in dataloader_test:
    predicted = .....
    pred = .....
    e.add_prediction(pred[np.newaxis],label)
print("the confusion Matrix :",e.get_confusion_Matrix())
print("the Mean F1 Score =",e.evaluate())

Dataset & Data Loader

  • CSV dataset loading
  • Batch loading by Data Loader
  • Interface for MNIST & CIFAR-10 datasets
  • Simillar to Pytorch Interface.
batch_size = 4
dataset = MNIST_dataset("train.csv")
dataloader = Data_Loader(dataset, batch_size)
for image, label in dataloader:
	...
	...

Save / Load utils

  • Saving / Loading model weights through .pth files.
model = load_weights(path)
save_weights(model, path)

Architectures

  • LeNet
  • AlexNet

About

Deep Learning Framework Implementation from scratch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published