Skip to content

start-again-006/Deep-Neural-Network-Based-Image-Classification

Repository files navigation

Deep Neural Network Based Image Classification

Deep Neural Network Image Classifier

This repository presents a comprehensive pipeline for designing, implementing, training, and evaluating deep neural networks for image classification tasks using only low-level numerical libraries. The system is built entirely from scratch using NumPy, without relying on high-level frameworks such as TensorFlow or PyTorch.

The primary objective is to perform binary image classification, such as distinguishing between cats and non-cats, while providing complete transparency into the internal workings of neural networks. By avoiding abstraction layers, the implementation exposes every computational step, enabling a deeper understanding of model behavior.


System Architecture

flowchart TD

A[Raw Dataset - .h5 Images] --> B[Data Loading]
B --> C[Preprocessing]

C --> C1[Resize 64x64x3]
C --> C2[Flatten 12288 Vector]
C --> C3[Normalize]

C3 --> D[Train/Test Split]

D --> E[Model Selection]
E --> E1[Two-Layer NN]
E --> E2[L-Layer Deep NN]

E1 --> F[Forward Propagation]
E2 --> F

F --> G[ReLU Activations]
G --> H[Sigmoid Output]

H --> I[Loss Computation]
I --> J[Backpropagation]

J --> K[Gradient Descent Update]

K --> L{Converged?}
L -- No --> F
L -- Yes --> M[Trained Model]

M --> N[Evaluation]
N --> N1[Train Accuracy]
N --> N2[Test Accuracy]

M --> O[Prediction Module]
O --> O1[Custom Image Input]
O --> O2[Preprocess]
O --> O3[Predict Label]

D --> P[Pickle Storage]
P --> P1[Save Data]
P --> P2[Load Data]
Loading

Features

  • End-to-end implementation using NumPy from scratch
  • Two-layer neural network (baseline model)
  • L-layer deep neural network (scalable architecture)
  • Manual forward propagation
  • Manual backward propagation using the chain rule
  • Binary cross-entropy loss computation
  • Gradient descent-based optimization
  • Visualization using cost plots
  • Evaluation on real datasets
  • Custom image prediction
  • Dataset persistence using pickle

Dataset

The dataset consists of labeled RGB images for binary classification.

Includes

  • Training images and labels
  • Test images and labels
  • Class labels

Preprocessing

  • Resize to 64 × 64 × 3
  • Flatten into a 12288-dimensional vector
  • Normalize pixel values

Architecture

Two-Layer Model

  • Input layer: 12288 units
  • Hidden layer: ReLU activation
  • Output layer: Sigmoid activation

L-Layer Model

  • Multiple fully connected layers
  • Configurable using layers_dims
  • ReLU activation for hidden layers
  • Sigmoid activation for output layer

Learning Process

  1. Forward Propagation

  2. Cost Computation (Binary Cross-Entropy)

$$ L = -\frac{1}{m} \sum \left[y \log(\hat{y}) + (1-y)\log(1-\hat{y})\right] $$

  1. Backward Propagation

  2. Gradient Descent Update


Evaluation

  • Training accuracy
  • Test accuracy
  • Misclassification analysis

Predict on Custom Images

  1. Load image
  2. Resize
  3. Flatten and normalize
  4. Predict using trained model

Data Persistence

  • Save processed data using pickle
  • Reload for faster experimentation

Requirements

  • numpy
  • matplotlib
  • scipy
  • Pillow
  • h5py

Repository Structure

  • Models: Two-layer and deep network implementations
  • Utils: Forward and backward propagation, activation functions
  • Data: Loading and preprocessing
  • Prediction: Custom inference pipeline
  • Persistence: Pickle utilities

Summary

This repository provides a complete deep learning pipeline built from scratch, offering both practical implementation and a strong conceptual understanding of neural networks.

About

An end-to-end image classification pipeline based on deep neural networks is developed entirely from first principles using NumPy. Designed with an educational focus, the implementation emphasizes a clear understanding of core concepts such as forward propagation, backpropagation, and optimization techniques.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages