Skip to content

SurajAdhikari01/DeepNeuralNetwork

Repository files navigation

DeepNeuralNetwork

Simple L-layer neural network implementation for binary classification.

Repository contents

  • DeepNeuralNetwork.py — core implementation: initialization, forward/backward passes, training (L_layer_model) and predict.
  • train_and_test.py — script to load HDF5 datasets from datasets/, train the model, save parameters to parameters.npz, and evaluate train/test accuracy.
  • predict_from_test.py — loads saved parameters.npz and runs prediction on the test set.
  • datasets/ — contains train_catvnoncat.h5 and test_catvnoncat.h5 used by the example scripts.

Requirements

  • Python 3.8+
  • numpy
  • matplotlib
  • h5py

Install dependencies:

python3 -m pip install --user numpy matplotlib h5py

Quickstart — Train and evaluate

  1. Ensure the HDF5 datasets are in datasets/ and named train_catvnoncat.h5 and test_catvnoncat.h5.
  2. Run the training script:
python3 train_and_test.py

This will:

  • Load and preprocess the datasets (flatten images and scale by 255).
  • Train an L-layer network with default architecture [n_x, 20, 7, 5, 1].
  • Save trained parameters to parameters.npz.
  • Print train and test accuracies.

Quickstart — Predict using saved parameters

After training (or if you already have parameters.npz), run:

python3 predict_from_test.py

This loads parameters.npz, preprocesses the test set, and prints accuracy.

Files to edit

  • Edit train_and_test.py to change layers_dims, learning_rate, or number of iterations.
  • Edit DeepNeuralNetwork.py to modify the architecture or add utilities.

Notes

  • The scripts assume binary labels shaped (1, m).
  • If your HDF5 keys differ, update the loader functions in train_and_test.py and predict_from_test.py.
  • For larger datasets, consider minibatch gradient descent and checkpointing.

If you want, I can make the scripts accept command-line arguments for dataset paths and hyperparameters.

Here is training plot of the neural network for 2400 iteration for model size of [12288, 20, 7, 5, 1]

Figure_1

About

A "L layer" generic neural network implemented only using numpy.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages