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.
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]
- 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
The dataset consists of labeled RGB images for binary classification.
- Training images and labels
- Test images and labels
- Class labels
- Resize to 64 × 64 × 3
- Flatten into a 12288-dimensional vector
- Normalize pixel values
- Input layer: 12288 units
- Hidden layer: ReLU activation
- Output layer: Sigmoid activation
- Multiple fully connected layers
- Configurable using
layers_dims - ReLU activation for hidden layers
- Sigmoid activation for output layer
-
Forward Propagation
-
Cost Computation (Binary Cross-Entropy)
-
Backward Propagation
-
Gradient Descent Update
- Training accuracy
- Test accuracy
- Misclassification analysis
- Load image
- Resize
- Flatten and normalize
- Predict using trained model
- Save processed data using pickle
- Reload for faster experimentation
- numpy
- matplotlib
- scipy
- Pillow
- h5py
- 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
This repository provides a complete deep learning pipeline built from scratch, offering both practical implementation and a strong conceptual understanding of neural networks.