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:
- Custom 6-Layer CNN Architecture with Batch Normalization constructed from scratch in PyTorch.
- Modern ConvNeXt-Tiny Transfer Learning Pipeline achieving 97.78% Test Accuracy and 98.04% Peak Validation Accuracy on Kaggle Dual NVIDIA T4 GPUs.
- Curated and Deduplicated Dataset of 17,500 balanced images with zero duplicate images.
- Interactive Local Notebooks and CLI Inference Tools supporting local files and direct web URLs.
- Publication-Grade Technical Report compiled into PDF (Technical_Report.pdf).
- Author: Min Khant Tin
- GitHub Repository: manisandar/5-Class-Image-Classification
- Kaggle Notebook: 5-Class Image Classification (Kaggle Dual T4 GPU Edition)
- Kaggle Dataset: Airplane, Car, Horse, Truck, Ship Dataset (17,500 Images)
- Technical Report: Technical_Report.pdf
| Architecture | Parameters | Input Resolution | Peak Val Accuracy | Test Top-1 Accuracy | Test Loss | Hardware Latency |
|---|---|---|---|---|---|---|
| Custom 6-Layer CNN (Baseline) | 2.39 M | 88.40% | 87.82% | 0.6420 | 4.2 ms (MPS) | |
| ConvNeXt-Tiny (SOTA Transfer Learning) | 27.83 M | 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 |
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
=================================================================
- 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:
CosineAnnealingLRdecaying down to$\eta_{\text{min}} = 10^{-6}$ - Loss Function:
CrossEntropyLosswith Label Smoothing ($\epsilon = 0.1$ ) - Precision: Automatic Mixed Precision (AMP
torch.amp.autocast('cuda')withGradScaler)
- Optimizer:
-
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.
- Parallel multi-threaded MD5 byte and RGB pixel hashing for exact deduplication (
-
Visualization & Reporting:
-
Matplotlib,Seabornfor confusion matrices, progression curves, and probability bar charts. -
ReportLabandPyMuPDFfor PDF Technical Report compilation.
-
-
Hardware Acceleration:
- Apple Silicon GPU acceleration via Metal Performance Shaders (
mps). - NVIDIA Dual T4 GPUs with
nn.DataParallelon Kaggle.
- Apple Silicon GPU acceleration via Metal Performance Shaders (
.
├── 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
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 pymupdfClassify 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.jpgSample 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'
- 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.
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.pyTo regenerate the multi-page publication-grade PDF report with refreshed benchmark figures:
python3 reports/generate_technical_report.pyThe 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.
This project is licensed under the MIT License - see the LICENSE file for details.