Skip to content

About

A configurable computer vision training pipeline that handles real-world ImageFolder datasets, automates transfer learning setup, and generates reproducible training and inference scripts for Colab.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

CV Training Pipeline Generator ๐Ÿš€

Python PyTorch Streamlit License

A production-ready, configurable deep learning pipeline for image classification that automatically analyzes datasets, recommends architectures, and generates Google Colab-ready training scripts using transfer learning.

Built with engineering rigor โ€” focusing on correctness, usability, and real-world robustness over toy benchmarks.


๐ŸŽฏ Problem Statement

Building image classifiers shouldn't break because of:

  • โŒ Inconsistent dataset structures (single-folder vs pre-split)
  • โŒ Manual boilerplate for every project
  • โŒ Fragile training scripts that fail on edge cases
  • โŒ No clear separation between training and inference

This pipeline solves all of that.


โœจ What Makes This Different

Unlike typical ML projects that focus only on accuracy:

  • ๐Ÿ” Intelligent Dataset Analysis โ€” Automatically detects structure, validates ImageFolder format, analyzes class distribution
  • ๐Ÿง  Smart Recommendations โ€” Suggests optimal model, training approach, batch size, and epochs based on dataset characteristics
  • ๐ŸŽจ Interactive UI โ€” Streamlit-powered interface for dataset upload, visualization, and configuration
  • ๐Ÿ“„ Code Generation โ€” Produces clean, executable train.py and inference.py scripts
  • โ˜๏ธ Colab-First Design โ€” Generated scripts work out-of-the-box on Google Colab (GPU-friendly)
  • ๐Ÿ›ก๏ธ Robust Error Handling โ€” Handles messy real-world datasets gracefully

๐Ÿ—๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Dataset Input  โ”‚ โ† Upload ZIP or URL
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Structure Check โ”‚ โ† Detect single-folder vs pre-split
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    Analysis     โ”‚ โ† Class distribution, recommendations
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Configuration   โ”‚ โ† Override model/training settings
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Script Gen      โ”‚ โ† Generate train.py + inference.py
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Colab Exec     โ”‚ โ† Train on GPU, save model
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Features

๐Ÿ“‚ Dataset Handling

  • โœ… Automatic ImageFolder structure validation
  • โœ… Support for single-folder and pre-split datasets
  • โœ… Smart detection of train/val/test folder aliases
  • โœ… Class distribution visualization with recommendations
  • โœ… Upload via ZIP file or direct URL

๐Ÿง  Model & Training

  • โœ… Transfer learning with ResNet18 and MobileNetV2
  • โœ… Two training modes:
    • Final Head Only (fast, small datasets)
    • Layer4 + Final Head (better accuracy, larger datasets)
  • โœ… Adaptive learning rate with ReduceLROnPlateau
  • โœ… Early stopping at target accuracy
  • โœ… Automatic class mapping (class_mapping.json)

๐Ÿ“Š Analysis & Insights

  • โœ… Class distribution bar charts
  • โœ… Dataset statistics (total images, classes, balance)
  • โœ… Training curves (accuracy over epochs)
  • โœ… Automatic hyperparameter recommendations

๐Ÿ”ง Generated Scripts

  • โœ… train.py โ€” Fully configured training script
  • โœ… inference.py โ€” Interactive prediction script
  • โœ… Clean, well-commented, production-ready code
  • โœ… Works seamlessly in Google Colab

๐Ÿ“ฆ Installation

Local Setup

# Clone the repository
git clone https://github.com/theghostloop/cv-training-pipeline.git
cd cv-training-pipeline

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Requirements

streamlit>=1.28.0
torch>=2.0.0
torchvision>=0.15.0
pandas>=2.0.0
matplotlib>=3.7.0
Pillow>=10.0.0
requests>=2.31.0

๐ŸŽฎ Quick Start

1๏ธโƒฃ Launch Streamlit App

streamlit run app.py

2๏ธโƒฃ Upload Your Dataset

Option A: Upload ZIP file

  • Drag & drop a ZIP containing your dataset

Option B: Provide URL

  • Enter direct download link to dataset ZIP

3๏ธโƒฃ Review Analysis

The app will:

  • Detect dataset structure
  • Show class distribution
  • Recommend model & training settings

4๏ธโƒฃ Configure (Optional)

Override recommendations:

  • Model: ResNet18 vs MobileNetV2
  • Training mode: Final Head vs Layer4 + Head
  • Batch size: 16-64
  • Epochs: 1-50

5๏ธโƒฃ Download Scripts

Click "Generate Scripts" to download:

  • train.py โ€” Training script
  • inference.py โ€” Prediction script

6๏ธโƒฃ Train in Colab

# Upload train.py to Colab
!python train.py

# Follow prompts to load dataset
# Training begins automatically

7๏ธโƒฃ Run Inference

# After training completes
!python inference.py

# Predict on new images

๐Ÿ“ Supported Dataset Formats

Single-Folder Structure

dataset/
โ”œโ”€โ”€ class_1/
โ”‚   โ”œโ”€โ”€ img1.jpg
โ”‚   โ”œโ”€โ”€ img2.jpg
โ”œโ”€โ”€ class_2/
โ”‚   โ”œโ”€โ”€ img3.jpg
โ””โ”€โ”€ class_3/
    โ”œโ”€โ”€ img4.jpg

Pre-Split Structure

dataset/
โ”œโ”€โ”€ train/
โ”‚   โ”œโ”€โ”€ class_1/
โ”‚   โ”œโ”€โ”€ class_2/
โ”œโ”€โ”€ val/
โ”‚   โ”œโ”€โ”€ class_1/
โ”‚   โ”œโ”€โ”€ class_2/
โ””โ”€โ”€ test/  (optional)

Supported aliases:

  • Train: train, training
  • Val: val, valid, validation
  • Test: test, testing

๐Ÿงช Example Workflow

# 1. User uploads cat/dog dataset (1000 images, 2 classes)
# 2. App detects: single-folder structure
# 3. Recommendations:
#    - Model: MobileNetV2 (lighter for binary classification)
#    - Mode: Final Head Only
#    - Batch: 32
#    - Epochs: 15
# 4. User downloads train.py
# 5. Runs in Colab โ†’ achieves 95% accuracy
# 6. Saves best_model.pth
# 7. Uses inference.py for predictions

๐Ÿ“Š Output Files

After training:

outputs/
โ”œโ”€โ”€ best_model.pth           # Trained model weights
โ”œโ”€โ”€ class_mapping.json       # Class index mapping
โ””โ”€โ”€ training_curves.png      # Accuracy/loss plots

๐Ÿ”ฌ Technical Deep Dive

Dataset Structure Detection

def find_dataset_root(base_dir):
    """
    Intelligently detects:
    1. Pre-split (train/val/test folders)
    2. Single-folder (class subfolders)
    Handles nested ZIPs and edge cases
    """

Smart Recommendations

def get_recommended_details(df):
    """
    Based on:
    - Total images
    - Number of classes
    - Class balance
    
    Returns:
    - Model choice
    - Training approach
    - Batch size
    - Epoch count
    """

Transfer Learning Strategy

ResNet18:

  • Final Head Only: Freeze all, train fc layer
  • Layer4 + Head: Unfreeze layer4 + fc

MobileNetV2:

  • Final Head Only: Train classifier only
  • Deep Finetune: Unfreeze last 6 feature layers

โš™๏ธ Configuration Options

Parameter Options Description
Model ResNet18, MobileNetV2 Architecture choice
Training Mode Final Head Only, Layer4 + Head Freezing strategy
Batch Size 16, 24, 32, 40, 48, 56, 64 Training batch size
Epochs 1-50 Maximum training epochs

โš ๏ธ Known Limitations (By Design)

This is a learning-focused, prototyping pipeline, not a production ML system:

  • โŒ No hyperparameter search (Grid/Random/Bayesian)
  • โŒ No ensemble methods
  • โŒ No data augmentation beyond basic transforms
  • โŒ No distributed training
  • โŒ No model versioning (MLflow/Weights & Biases)
  • โŒ No deployment (FastAPI/TensorFlow Serving)

Why? These omissions keep the codebase clean, understandable, and focused on core engineering principles.


๐Ÿง  Design Philosophy

  1. Simplicity > Complexity โ€” No unnecessary abstractions
  2. Robustness > Assumptions โ€” Handle messy real-world data
  3. Reproducibility > One-offs โ€” Generated scripts are version-controllable
  4. Education > Black Boxes โ€” Code is readable and well-commented

๐Ÿ› ๏ธ Tech Stack

Component Technology
Backend Python 3.8+
ML Framework PyTorch 2.0+
Computer Vision Torchvision
UI Streamlit
Data Viz Matplotlib, Pandas
Image Processing Pillow

๐Ÿ“ˆ Future Enhancements

  • Support for multi-label classification
  • Custom augmentation policies
  • Integration with Hugging Face Hub
  • Export to ONNX/TorchScript
  • Gradio interface alternative
  • Automatic dataset balancing

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“œ License

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


๐Ÿ™ Acknowledgments

  • PyTorch team for excellent documentation
  • Streamlit for making ML UIs accessible
  • ImageNet for pretrained weights

๐Ÿ“ง Contact

Your Name
๐Ÿ“ง Email: princeverma2005@gmail.com
๐Ÿ™ GitHub: @TheGhostLoop
๐Ÿ’ผ LinkedIn: Prince Verma(https://www.linkedin.com/in/prince-verma-80a94b374?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)


โš–๏ธ Ethical Note

This project is intended for educational and research purposes. It is not designed for:

  • Medical diagnosis
  • Biometric identification
  • Surveillance systems
  • Safety-critical applications

Use responsibly and ensure compliance with relevant data protection regulations.


โญ If this project helped you, please star the repo!


๐Ÿ“ Additional Files to Add

.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
env/

# Dataset folders
datasets/
outputs/

# Streamlit
.streamlit/

# OS
.DS_Store
Thumbs.db

requirements.txt

streamlit==1.28.0
torch==2.0.1
torchvision==0.15.2
pandas==2.0.3
matplotlib==3.7.2
Pillow==10.0.0
requests==2.31.0

About

A configurable computer vision training pipeline that handles real-world ImageFolder datasets, automates transfer learning setup, and generates reproducible training and inference scripts for Colab.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages