Skip to content

About

An end-to-end computer vision and deep learning project engineering high-accuracy image classification across five target categories: airplane, car, horse, ship, and truck.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

5-Class Vision Classifier: Custom CNN & ConvNeXt-Tiny Pipeline

PyTorch Python Kaggle Accuracy License

An end-to-end computer vision and deep learning project engineering high-accuracy image classification across five target categories: airplane, car, horse, ship, and truck.

This repository contains:

  1. Custom 6-Layer CNN Architecture with Batch Normalization constructed from scratch in PyTorch.
  2. Modern ConvNeXt-Tiny Transfer Learning Pipeline achieving 97.78% Test Accuracy and 98.04% Peak Validation Accuracy on Kaggle Dual NVIDIA T4 GPUs.
  3. Curated and Deduplicated Dataset of 17,500 balanced images with zero duplicate images.
  4. Interactive Local Notebooks and CLI Inference Tools supporting local files and direct web URLs.
  5. Publication-Grade Technical Report compiled into PDF (Technical_Report.pdf).

Project Links


Empirical Benchmarks & Quantitative Results

Comparative Performance Summary

Architecture Parameters Input Resolution Peak Val Accuracy Test Top-1 Accuracy Test Loss Hardware Latency
Custom 6-Layer CNN (Baseline) 2.39 M $64 \times 64$ 88.40% 87.82% 0.6420 4.2 ms (MPS)
ConvNeXt-Tiny (SOTA Transfer Learning) 27.83 M $224 \times 224$ 98.04% 97.78% 0.4357 18.5 ms (MPS)
Net Improvement +25.44 M +3.5x Res +9.64% +9.96% -0.2063 High Fidelity

Detailed Per-Class Classification Report (ConvNeXt-Tiny)

Evaluated on 1,125 stratified test samples:

=================================================================
DETAILED TEST SET CLASSIFICATION REPORT (ConvNeXt-Tiny)
=================================================================
              Precision    Recall  F1-Score   Support
    Airplane     0.9908    0.9862    0.9885       218
         Car     0.9917    0.9636    0.9774       247
       Horse     0.9952    1.0000    0.9976       209
        Ship     0.9870    0.9661    0.9764       236
       Truck     0.9251    0.9767    0.9502       215

    Accuracy                         0.9778      1125
   Macro Avg     0.9780    0.9785    0.9780      1125
Weighted Avg     0.9785    0.9778    0.9779      1125
=================================================================

Technology Stack & Methods

  • Deep Learning Framework: PyTorch 2.x and Torchvision
  • Vision Architectures:
    • ConvNeXt-Tiny: $7 \times 7$ depthwise separable convolutions, inverted bottleneck (1:4), GELU activations, LayerScale, LayerNorm.
    • CustomCNN: 6 Conv2d layers with BatchNorm2d, MaxPool2d, Dropout ($p=0.4$), and a 2-layer FC classifier head.
  • Optimization Strategy:
    • Optimizer: AdamW (learning rate $= 10^{-3}$, weight decay $= 10^{-2}$)
    • Scheduler: CosineAnnealingLR decaying down to $\eta_{\text{min}} = 10^{-6}$
    • Loss Function: CrossEntropyLoss with Label Smoothing ($\epsilon = 0.1$)
    • Precision: Automatic Mixed Precision (AMP torch.amp.autocast('cuda') with GradScaler)
  • Data Engineering & Auditing:
    • Parallel multi-threaded MD5 byte and RGB pixel hashing for exact deduplication (concurrent.futures).
    • Strict stratified train (70%) / validation (15%) / test (15%) splits.
  • Visualization & Reporting:
    • Matplotlib, Seaborn for confusion matrices, progression curves, and probability bar charts.
    • ReportLab and PyMuPDF for PDF Technical Report compilation.
  • Hardware Acceleration:
    • Apple Silicon GPU acceleration via Metal Performance Shaders (mps).
    • NVIDIA Dual T4 GPUs with nn.DataParallel on Kaggle.

Repository Structure

.
├── dataset/                         # Local dataset directory (gitignored, download from Kaggle)
│   ├── airplane/                    # 3,500 images
│   ├── car/                         # 3,500 images
│   ├── horse/                       # 3,500 images
│   ├── ship/                        # 3,500 images
│   └── truck/                       # 3,500 images
├── models/                          # Model checkpoints & weights
│   ├── best_cnn_model.pth           # Custom 6-Layer CNN weights (~9.5 MB, tracked in Git)
│   └── best_convnext_model.pth      # ConvNeXt-Tiny model weights (~111 MB, Kaggle link)
├── outputs/                         # Visual outputs & inference plots
│   ├── New_dataset_samples.png      # 5x5 dataset inspection grid
│   ├── prediction_result.png        # Custom CNN inference visual breakdown
│   └── convnext_prediction_result.png # ConvNeXt inference visual breakdown
├── reports/                         # Technical reports & source assets
│   ├── figures/                     # High-resolution benchmark figures
│   │   ├── training_curves.png
│   │   ├── confusion_matrices.png
│   │   └── per_class_metrics.png
│   ├── generate_technical_report.py # ReportLab PDF generation script
│   └── Technical_Report.pdf         # Publication-grade technical report
├── scripts/                         # Operational CLI scripts
│   ├── test_convnext.py             # CLI inference with ConvNeXt-Tiny
│   ├── test_external.py             # CLI inference with Custom CNN
│   ├── verify_dataset.py            # Dataset integrity & balance verifier
│   ├── detect_duplicates.py         # Multi-threaded duplicate image scanner
│   └── remove_duplicates.py         # Automated deduplication script
├── Image_classifier.ipynb           # Original local assignment training notebook
├── Kaggle_Image_Classifier.ipynb    # Kaggle-ready execution notebook
├── ConvNeXt_Local_Classifier.ipynb  # Dedicated local ConvNeXt inference notebook
├── Technical_Report.pdf             # Root copy of Technical Report PDF
├── README.md                        # Documentation & project guide
├── LICENSE                          # MIT License
└── .gitignore                       # Git ignore rules

Quick Start Guide

1. Installation & Environment Setup

Clone the repository and install dependencies:

git clone https://github.com/manisandar/5-Class-Image-Classification.git
cd 5-Class-Image-Classification

# Install required packages
pip install torch torchvision torchaudio pillow matplotlib seaborn reportlab pymupdf

2. Running Local Inference via CLI

Classify any local image file or online web URL directly from your terminal:

# Test with ConvNeXt-Tiny (SOTA 97.78% accuracy)
python3 scripts/test_convnext.py path/to/my_photo.jpg

# Test with a direct web image URL
python3 scripts/test_convnext.py "https://images.unsplash.com/photo-1540959733332-eab4deabeeaf?w=600"

# Test with Custom 6-Layer CNN
python3 scripts/test_external.py path/to/my_photo.jpg

Sample output:

=================================================================
CONVNEXT INFERENCE RESULT : photo-1540959733332-eab4deabeeaf
=================================================================
Compute Device            : MPS
Predicted Class           : SHIP
Confidence Score          : 91.46%
-----------------------------------------------------------------
Class Probabilities Breakdown:
  airplane   :   0.95% | 
  car        :   0.03% | 
  horse      :   0.05% | 
  ship       :  91.46% | ███████████████████████████ [Top Prediction]
  truck      :   7.52% | ██
=================================================================
Visualization saved to: 'outputs/convnext_prediction_result.png'

3. Running the Jupyter Notebooks

  • ConvNeXt_Local_Classifier.ipynb: Dedicated local inference notebook for interactive single-image and batch prediction using the trained ConvNeXt weights.
  • Image_classifier.ipynb: Full assignment walkthrough (Steps 1 through 7) training the Custom 6-Layer CNN from scratch.
  • Kaggle Notebook: Dual T4 GPU training run with full classification report and confusion matrix visualizations.

4. Dataset Verification & Duplicate Audit

To audit the dataset balance and verify that there are zero duplicates:

# Verify class balance, dimensions, and total size
python3 scripts/verify_dataset.py

# Run parallel MD5 byte + pixel duplicate detector
python3 scripts/detect_duplicates.py

5. Recompiling the PDF Technical Report

To regenerate the multi-page publication-grade PDF report with refreshed benchmark figures:

python3 reports/generate_technical_report.py

Technical Report Preview

The comprehensive 3-page technical report covers:

  • Section 1: Executive Summary and Project Objectives
  • Section 2: Dataset Engineering and Quality Assurance (17,500 images)
  • Section 3: Model Architecture Comparison (CNN vs. ConvNeXt)
  • Section 4: Quantitative Benchmarks, Loss/Accuracy Curves and Empirical Results
  • Section 5: Per-Class F1, Precision, Recall and Confusion Matrices
  • Section 6: Production CLI Deployment and Local Workflows
  • Section 7: Conclusion and Key Takeaways

Download and view the full report: Technical_Report.pdf.


License

This project is licensed under the MIT License - see the LICENSE file for details.

About

An end-to-end computer vision and deep learning project engineering high-accuracy image classification across five target categories: airplane, car, horse, ship, and truck.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages