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.
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.
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.pyandinference.pyscripts - โ๏ธ Colab-First Design โ Generated scripts work out-of-the-box on Google Colab (GPU-friendly)
- ๐ก๏ธ Robust Error Handling โ Handles messy real-world datasets gracefully
โโโโโโโโโโโโโโโโโโโ
โ 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
โโโโโโโโโโโโโโโโโโโ
- โ Automatic ImageFolder structure validation
- โ Support for single-folder and pre-split datasets
- โ
Smart detection of
train/val/testfolder aliases - โ Class distribution visualization with recommendations
- โ Upload via ZIP file or direct URL
- โ 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)
- โ Class distribution bar charts
- โ Dataset statistics (total images, classes, balance)
- โ Training curves (accuracy over epochs)
- โ Automatic hyperparameter recommendations
- โ
train.pyโ Fully configured training script - โ
inference.pyโ Interactive prediction script - โ Clean, well-commented, production-ready code
- โ Works seamlessly in Google Colab
# 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.txtstreamlit>=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.0streamlit run app.pyOption A: Upload ZIP file
- Drag & drop a ZIP containing your dataset
Option B: Provide URL
- Enter direct download link to dataset ZIP
The app will:
- Detect dataset structure
- Show class distribution
- Recommend model & training settings
Override recommendations:
- Model: ResNet18 vs MobileNetV2
- Training mode: Final Head vs Layer4 + Head
- Batch size: 16-64
- Epochs: 1-50
Click "Generate Scripts" to download:
train.pyโ Training scriptinference.pyโ Prediction script
# Upload train.py to Colab
!python train.py
# Follow prompts to load dataset
# Training begins automatically# After training completes
!python inference.py
# Predict on new imagesdataset/
โโโ class_1/
โ โโโ img1.jpg
โ โโโ img2.jpg
โโโ class_2/
โ โโโ img3.jpg
โโโ class_3/
โโโ img4.jpg
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
# 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 predictionsAfter training:
outputs/
โโโ best_model.pth # Trained model weights
โโโ class_mapping.json # Class index mapping
โโโ training_curves.png # Accuracy/loss plots
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
"""def get_recommended_details(df):
"""
Based on:
- Total images
- Number of classes
- Class balance
Returns:
- Model choice
- Training approach
- Batch size
- Epoch count
"""ResNet18:
- Final Head Only: Freeze all, train
fclayer - Layer4 + Head: Unfreeze
layer4+fc
MobileNetV2:
- Final Head Only: Train
classifieronly - Deep Finetune: Unfreeze last 6 feature layers
| 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 |
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.
- Simplicity > Complexity โ No unnecessary abstractions
- Robustness > Assumptions โ Handle messy real-world data
- Reproducibility > One-offs โ Generated scripts are version-controllable
- Education > Black Boxes โ Code is readable and well-commented
| Component | Technology |
|---|---|
| Backend | Python 3.8+ |
| ML Framework | PyTorch 2.0+ |
| Computer Vision | Torchvision |
| UI | Streamlit |
| Data Viz | Matplotlib, Pandas |
| Image Processing | Pillow |
- Support for multi-label classification
- Custom augmentation policies
- Integration with Hugging Face Hub
- Export to ONNX/TorchScript
- Gradio interface alternative
- Automatic dataset balancing
Contributions welcome! Please:
- Fork the repo
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
- PyTorch team for excellent documentation
- Streamlit for making ML UIs accessible
- ImageNet for pretrained weights
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)
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!
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
env/
# Dataset folders
datasets/
outputs/
# Streamlit
.streamlit/
# OS
.DS_Store
Thumbs.db
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