Skip to content

Custom deep learning model for binary image classification. Entirely built from scratch in Python with NumPy, including all ML functions, activations, and optimizations.

License

Notifications You must be signed in to change notification settings

AmiraliSajadi/Image-Classification-Neural-Network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Image Classification Neural Network

This project showcases a custom-implemented deep neural network for binary image classification, written entirely in Python using NumPy. The model is trained to classify images as either containing a cat or not.


You got a cat!

Highlights

  • Mathematical Implementation: All machine learning computations, including forward propagation, backward propagation, activation functions (ReLU, sigmoid), cost computation, and gradient descent, were implemented from scratch using NumPy.
  • Custom-built Neural Network: No reliance on high-level libraries like TensorFlow or PyTorch; all components of the neural network are manually coded for transparency and understanding.
  • Performance: Achieved 100% training accuracy and 72.5% test accuracy on a small dataset.

Features

  • Dataset Handling: Images are preprocessed (resized, normalized, and flattened) and automatically labeled based on file naming conventions.
  • Neural Network Architecture: A flexible L-layer architecture using ReLU and sigmoid activations, designed for binary classification.
  • Visualization: Cost reduction is plotted over training iterations to showcase learning progress and convergence.

Project Workflow

Dataset Preparation:

  • Images are resized to a uniform shape and converted into flattened feature vectors (12,288 features for 64x64 RGB images).
  • Data is normalized to enhance numerical stability during training.
  • Labels are generated automatically based on image file formats.

Model Training:

  • Forward Propagation: Computes activations using manually implemented linear transformations (W·X + b) and activation functions (ReLU, sigmoid).
  • Cost Computation: Uses cross-entropy loss to measure prediction error.
  • Backward Propagation: Implements manual gradient computation for weights and biases.
  • Gradient Descent: Updates parameters iteratively to minimize the cost function.

Model Evaluation:

  • Predictions are made on test images using the trained model, and classification accuracy is calculated.
  • Outputs are visualized, comparing model predictions with ground truth labels.

Results

  • Training Accuracy: 100.0%
  • Test Accuracy: 72.5%

How to Run

  1. Clone the repository:
git clone https://github.com/AmiraliSajadi/Image-Classification-Neural-Network.git
  1. Organize your dataset:
catnoncat_dataset/
├── train/
│   ├── cat1.png
│   ├── noncat1.jpg
└── test/
    ├── cat2.png
    ├── noncat2.jpg
  1. Run the Jupyter Notebook:
jupyter notebook cat_noncat_L_layer_NN.ipynb

About

Custom deep learning model for binary image classification. Entirely built from scratch in Python with NumPy, including all ML functions, activations, and optimizations.

Topics

Resources

License

Stars

Watchers

Forks