A comprehensive benchmarking study across six architectures — from Logistic Regression to Vision Transformers — on binary image classification.
- Overview
- Models Evaluated
- Dataset
- Results & Benchmarks
- Key Techniques
- Project Structure
- Getting Started
- Training Pipeline
- Evaluation Metrics
- Sample Inference
- Future Enhancements
This project systematically evaluates six image classification architectures spanning three generations of computer vision, all benchmarked on the same Cat vs. Dog binary classification task.
The goal is to measure not just accuracy, but the full picture: training time, inference speed, parameter count, FLOPs, and generalization capability — providing a practical guide to choosing the right model for real-world constraints.
Traditional ML ──────────────────────────► Vision Transformers
(seconds) CNNs Transfer Learning (minutes)
Low accuracy ──────────────────────────► High accuracy
Few params ──────────────────────────► Millions of params
| Model | Approach |
|---|---|
| Logistic Regression | Hand-crafted pixel/feature vectors, gradient descent |
| Support Vector Machine (SVM) | Kernel-based margin maximization on flattened inputs |
| Model | Approach |
|---|---|
| Custom CNN | Lightweight convolutional network built from scratch |
| ResNet-34 | Fine-tuned on pretrained ImageNet weights (skip connections) |
| EfficientNet-B0 | Fine-tuned compound-scaled network (best efficiency/accuracy tradeoff) |
| Model | Approach |
|---|---|
| ViT-Base/Patch16-224 | Fine-tuned attention-based transformer on 16×16 image patches |
Binary image classification dataset:
dataset/
├── cats/ 🐱 (n images)
└── dogs/ 🐶 (n images)
Train/validation split is performed programmatically inside each notebook.
Preprocessing pipeline:
| Step | Detail |
|---|---|
| Resize | 224 × 224 px (ViT & CNNs) |
| Normalize | ImageNet mean/std ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) |
| Augmentation | Random flip, crop, color jitter, rotation |
| Label encoding | Cat → 0, Dog → 1 |
| Model | Accuracy | Precision | Recall | F1 Score | Params | Training Time |
|---|---|---|---|---|---|---|
| Logistic Regression | 61% | 0.61 | 0.60 | 0.61 | 12k | 5min |
| SVM | 61% | 0.62 | 0.59 | 0.61 | 12k | 10min |
| Custom CNN | 72% | 0.75 | 0.67 | 0.71 | 93K | 20min |
| ResNet-34 (FT) | 98% | 0.98 | 0.98 | 0.98— | 21.8M | 30 min |
| EfficientNet-B0 (FT) | 96% | 0.97 | 0.95 | 0.96 | 5.3M | 31 min |
| ViT-Base/16 (FT) | 99%+ | 0.99 | 0.99 | 0.99 | 86M | 2hrs |
Logistic Regression
Support Vector Machine (SVM)
Custom CNN
ResNet-34 (Fine-Tuned)
EfficientNet-B0 (Fine-Tuned)
ViT-Base/Patch16-224 (Fine-Tuned)
- Data Augmentation — Random crops, flips, and color jitter for regularization
- Feature Extraction — Pixel flattening for classical ML; learned hierarchical features for CNNs
- Transfer Learning — Leveraging ImageNet pretraining for rapid convergence
- Fine-Tuning — Unfreezing top layers to adapt pretrained representations
- Hyperparameter Tuning — Learning rate scheduling, weight decay, batch size sweeps
- Performance Benchmarking — Accuracy, speed, complexity across all models
- Custom Inference — Single-image prediction pipeline
- Confusion Matrix Analysis — Per-class error identification
- Precision / Recall / F1 — Balanced evaluation beyond raw accuracy
Animal_Classifier/
│
├── 📓 dataset_analysis.ipynb # Exploratory data analysis & class distribution
├── 📓 logistic_reg.ipynb # Logistic Regression (from scratch)
├── 📓 svm.ipynb # SVM (from scratch)
├── 📓 small-cnn-final.ipynb # Custom lightweight CNN
├── 📓 resnet-34-ft.ipynb # ResNet-34 fine-tuning
├── 📓 efficient_net_B0_FT.ipynb # EfficientNet-B0 fine-tuning
├── 📓 vit_base_patch_16_FT.ipynb # ViT-Base/16 fine-tuning
│
├── 📄 requirements.txt # Python dependencies
├── 🐱 cat.png # Sample inference image
└── 🐶 dog.jpeg # Sample inference image
git clone https://github.com/couder-04/VisionBench.git
cd VisionBenchpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtPlace your dataset in the following structure (or update the paths inside the notebooks):
dataset/
├── cats/
└── dogs/
The train/validation split is handled automatically inside each notebook.
jupyter notebook dataset_analysis.ipynb # Start hereThen proceed through each model notebook in any order.
┌─────────────────────────────────────────────────────────┐
│ TRAINING PIPELINE │
│ │
│ Dataset Analysis ──► Data Preprocessing │
│ │ │
│ ▼ │
│ Data Augmentation │
│ │ │
│ ┌──────────┴──────────┐ │
│ ▼ ▼ │
│ Train from Scratch Fine-Tune Pretrained │
│ (ML / Custom CNN) (ResNet/EffNet/ViT) │
│ │ │ │
│ └──────────┬──────────┘ │
│ ▼ │
│ Evaluation │
│ │ │
│ ▼ │
│ Benchmark Comparison │
│ │ │
│ ▼ │
│ Custom Image Inference │
└─────────────────────────────────────────────────────────┘
Every model is evaluated on a consistent set of metrics for fair comparison:
| Metric | Purpose |
|---|---|
| Accuracy | Overall correct predictions |
| Precision | True positives out of predicted positives |
| Recall | True positives out of actual positives |
| F1 Score | Harmonic mean of precision and recall |
| Confusion Matrix | Per-class breakdown of errors |
| Training Time | Wall-clock training duration |
| Inference Time | Per-image prediction latency |
| Parameters (#) | Model size in parameter count |
| FLOPs | Computational cost per forward pass |
from PIL import Image
from torchvision import transforms
import torch
# Load your trained model
model.eval()
# Preprocessing pipeline
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406],
[0.229, 0.224, 0.225])
])
# Run inference
img = Image.open("dog.jpeg").convert("RGB")
tensor = transform(img).unsqueeze(0) # Add batch dimension
with torch.no_grad():
output = model(tensor)
pred = torch.argmax(output, dim=1).item()
label_map = {0: "🐱 Cat", 1: "🐶 Dog"}
print(f"Prediction: {label_map[pred]}")
# Prediction: 🐶 Dog- MobileNetV3 — Lightweight mobile-optimized benchmark
- ConvNeXt — Modern pure-CNN architecture comparison
- Swin Transformer — Hierarchical ViT fine-tuning
- Automated Hyperparameter Optimization — Optuna / Ray Tune integration
- Streamlit Web App — Interactive drag-and-drop inference demo
- FastAPI Deployment — REST endpoint for production inference
- Model Quantization — INT8 / FP16 optimization for edge deployment
- Grad-CAM Visualizations — Saliency maps for model explainability
- ONNX Export — Cross-framework model portability
Found this project useful? ⭐ Star the repository to support the work!
Built with curiosity — from pixels to patches.





