Skip to content

๐Ÿ–ผ๏ธ๐Ÿ”ข A TensorFlow/Keras-based Fully Connected Neural Network for classifying 32ร—32 color images into 10 categories using the CIFAR-10 dataset.

Notifications You must be signed in to change notification settings

Amirbehnam1009/CIFAR10-Image-Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ–ผ๏ธ CIFAR-10 Image Classification Using Fully Connected Neural Network

"From foundational principles to optimized implementation - a complete neural network journey" ๐Ÿง 


๐Ÿ“‹ Project Overview

In this comprehensive project, we constructed a neural network from scratch using fundamental principles, leveraging the CIFAR-10 dataset for training. The implementation encompassed data preprocessing, forward/backward propagation, and highlighted the transformative power of vectorization for computational efficiency.

Core Insight: This project demonstrates the pivotal role of vectorization in accelerating neural network computations, illuminating its critical importance in modern machine learning workflows. โšก


๐Ÿ‘จโ€๐Ÿซ Supervision

Under the guidance of Prof. Mohammad Mehdi Ebadzadeh
๐Ÿ“… Spring 2022


๐Ÿ“š Libraries Used

  • NumPy - Fundamental package for scientific computing
  • Matplotlib - Comprehensive library for visualization
  • Scikit-image - Image processing algorithms
  • PIL (Pillow) - Image manipulation capabilities
  • Glob - File path pattern matching
  • OS - Operating system interface
  • Time - Time access and measurement utilities

๐Ÿš€ Implementation Steps

1. ๐Ÿ› ๏ธ Data Preprocessing

Step 1: Data Acquisition & Storage

  • ๐Ÿ“ฅ Read the first 4 classes from CIFAR-10 dataset (airplane โœˆ๏ธ, automobile ๐Ÿš—, bird ๐Ÿฆ, and cat ๐Ÿฑ)
  • ๐Ÿ’พ Store data in matrix format: (n_samples, width, height, channels)
  • ๐Ÿ”ข Encode labels using one-hot representation

Steps 2โ€“5: Data Transformation Pipeline

  • ๐ŸŽถ Grayscale Conversion - Reduce computational complexity by converting RGB to grayscale
  • ๐Ÿ“Š Normalization - Scale pixel values to [0, 1] range by dividing by 255
  • ๐Ÿงฉ Flattening - Reshape data to (n_samples, 1024) for input layer compatibility
  • ๐Ÿ”€ Shuffling - Randomize data order while maintaining data-label correspondence

2. ๐Ÿ“ˆ Feedforward Implementation

Objective: Compute network outputs using forward propagation

  • โœ… Data Selection: 200-sample subset from training data
  • โœ… Parameter Initialization:
    • ๐ŸŽฒ Random weight initialization
    • 0๏ธโƒฃ Zero bias initialization
  • โœ… Output Computation: Matrix multiplication + Sigmoid activation ฯƒ
  • โœ… Model Inference: Class prediction based on maximum activation ๐Ÿ“ˆ
  • โœ… Accuracy Assessment: ~25% baseline accuracy (random chance) ๐ŸŽฏ

Implementation Note: Leveraged NumPy for efficient matrix operations


3. ๐Ÿ” Backpropagation Implementation

  • Employed backpropagation to iteratively refine model parameters and minimize prediction error
  • โš™๏ธ Hyperparameter Tuning: Careful selection of batch size, learning rate, and epochs
  • ๐Ÿ”ง Algorithm Implementation: Followed standard pseudo-code for parameter updates

๐Ÿ“Š Performance Metrics:

  • Model accuracy on 200-sample subset
  • Execution time measurement โฑ๏ธ
  • Expected performance: ~30% accuracy (accounting for random initialization)
  • ๐Ÿ“‰ Cost Visualization: Plotted average cost reduction per epoch

4. โšก Vectorization Optimization

Implemented vectorized operations to dramatically improve computational efficiency

  • ๐ŸŽฏ Feedforward Vectorization: Matrix-based implementation
  • ๐Ÿ”„ Backpropagation Vectorization: Eliminated iterative loops

๐Ÿ“ˆ Enhanced Evaluation:

  • Increased to 20 epochs for comprehensive assessment
  • Reported final model accuracy and execution time
  • Multiple executions to account for performance variability
  • Cost trajectory visualization over training

5. ๐Ÿงช Model Testing & Evaluation

Comprehensive performance assessment using full dataset (4 classes, 8000 samples)

๐Ÿ‹๏ธ Training Configuration: Optimized hyperparameters

๐Ÿ“‹ Evaluation Metrics:

  • Training set accuracy ๐Ÿ“Š
  • Test set accuracy ๐Ÿ“‰
  • Comparative performance analysis
  • Learning visualization: Average cost reduction over epochs

๐ŸŽฏ Key Achievements

  • โœ… Built neural network from foundational principles
  • โœ… Implemented efficient data preprocessing pipeline
  • โœ… Demonstrated dramatic performance improvement through vectorization
  • โœ… Achieved measurable accuracy on CIFAR-10 subset
  • โœ… Visualized learning process through cost reduction graphs

๐Ÿ“ Repository Structure

๐Ÿ“ฆ CIFAR10-NeuralNetwork
โ”œโ”€โ”€ ๐Ÿ“„ README.md # Project documentation
โ”œโ”€โ”€ ๐Ÿ“Š data/ # Dataset handling utilities
โ”œโ”€โ”€ ๐Ÿง  models/ # Neural network implementation
โ”œโ”€โ”€ ๐Ÿ“ˆ results/ # Performance metrics and visualizations
โ”œโ”€โ”€ ๐Ÿ”ฌ experiments/ # Testing and evaluation scripts
โ””โ”€โ”€ ๐Ÿ“œ requirements.txt # Project dependencies

๐Ÿš€ How to Run

1. Install dependencies:

pip install -r requirements.txt

2. Preprocess data:

python data/preprocessing.py

3. Train model:

python models/train.py

4. Evaluate performance:

python experiments/evaluate.py

๐Ÿ“Š Expected Results

  • Baseline Accuracy: ~25โ€“30% (random initialization)

  • Vectorized Speedup: 5โ€“10x performance improvement

  • Final Accuracy: Measurable improvement over baseline

  • Learning Curve: Consistent cost reduction across epochs

๐Ÿ”ฎ Future Enhancements

  • Additional layer architectures

  • Alternative activation functions (ReLU, tanh)

  • Regularization techniques (Dropout, L2)

  • Hyperparameter optimization framework

  • Extension to full CIFAR-10 dataset (10 classes)

About

๐Ÿ–ผ๏ธ๐Ÿ”ข A TensorFlow/Keras-based Fully Connected Neural Network for classifying 32ร—32 color images into 10 categories using the CIFAR-10 dataset.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published