Table of Contents
This project implements a feed-forward neural network from scratch with numpy and uses the 360 Fruits Dataset for training and testing model. there are seven phases in this project which complete neural network implementation step by step, which includes the following steps
- Preprocess Data
- Forward Propagation
- Non-Vectorized Backward Propagetion
- Vectorized Backward Propagetion
- Final Test
- Hyperparameters Analyzing
- Learning Rate Decay
- Deeper Network !!!
As input data are images, so there are some feature extraction codes that can transform images into fixed dimensional vectors, so the model uses .pkl extension files as input (not direct images). In the beginning, non-vectorized backward propagation will be implemented, and after that implementation will be changed to vectorized backward propagation.
Project uses numpy array for increasing speed and Linear algebra, then you should install numpy library
$ pip install numpyalso, project needs matplotlib for visualizing plots
$ pip install matplotliband you should install tqdm for better experince (you can delete it from code if you want)
$ pip install tqdm(optional)
if you want to run feature extraction codes yourself, please install scikit-image too
$ pip install scikit-imageRun all cells in order, but you should run phase 7 before running the train function's cell at phase 3.
In this phase data is transformed from images into vectors, at beginning feature extraction reads all images and with the use of histogram function and number of 360 bins, images are transformed into vectors, then features with specific standard deviation are deleted, and finally, data is ready!
In this phase forward function is implemented and weights and biases are initialized, also the test function is implemented for testing the accuracy of the model. As activation function, this model uses sigmoid for all layers.
In this phase vectorized backward function is implemented, as you can see it is super fast.
Run cells to see effect of different hyperparameters on accuracy. I used a custom learning decay for improving convergence.
class LR_Decay:
def __init__(self, initial_lr, k):
self.initial_lr = initial_lr
self.t = 0
self.k = k
def step(self):
value = self.initial_lr * np.exp(-self.k * self.t)
self.t += 1
return max(value, 1)⚠️ warning: feel free to add more fruits to the dataset, but you should modify feature extraction a little bit and make your model more complex.
Distributed under the MIT license. See LICENSE.md for more information.


