Educational & Experimental YOLO Training Framework with PyTorch Lightning
Features β’ Installation β’ Quick Start β’ Documentation β’ Contributing
Lightning-YOLOs is an educational framework for learning how to train YOLO models using PyTorch Lightning. This project demonstrates best practices in ML engineering, modular architecture design, and modern Python development workflows.
π Learning Goals: Ideal for students and developers who want to understand how to integrate YOLO models with PyTorch Lightning, implement both standard and oriented bounding box detection, and build production-ready ML codebases.
- π Educational Focus: Learn PyTorch Lightning patterns with real-world YOLO models
- π§ͺ Experimentation: Safe environment to test ideas and learn ML workflows
- π¨ Multiple Detection Modes: Explore both standard bounding boxes and Oriented Bounding Boxes (OBB)
- π Modern Practices: See how to integrate metrics, logging, and testing in ML projects
- βοΈ Clean Architecture: Study modular design with CLI, data modules, and training orchestration
- π οΈ Development Workflow: Experience pre-commit hooks, CI/CD, and code quality tools
| Feature | Description | Status |
|---|---|---|
| π― Standard Detection | Classic axis-aligned bounding boxes for general object detection | β |
| π OBB Detection | Rotated bounding boxes for aerial/satellite imagery and oriented objects | β |
| π Advanced Metrics | TorchMetrics mAP calculation for both training and validation | π |
| β‘ Mixed Precision | Various Precisions and Training strategies with PyTorch Lightning for faster training | β |
| π§ Auto Configuration | Automatic class detection from dataset | β |
| ποΈ Modular Design | Clean, extensible architecture with PyTorch Lightning | β |
| π§ͺ Synthetic Data | Built-in synthetic dataset generator for testing | β |
| ποΈ Visualization | Dataset visualization tools with bounding box annotations | β |
# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Quick install
pip install .
# Development install with all tools
pip install -e ".[dev]"
# Verify installation
lit-yolo --helpπ‘ Tip: Start with synthetic data to understand the workflow before using real datasets.
Train a YOLO model for standard object detection in just one command:
# Start training with default settings
lit-yolo train detect --data /path/to/dataset --model yolo11n.ptAdvance configuration (click to expand)
# Customize your training (experiment with parameters!)
lit-yolo train detect \
--data /path/to/dataset \
--model yolo11n.pt \
--epochs 100 \
--batch_size 16 \
--lr 0.001For aerial imagery or rotated objects:
# Train OBB model
lit-yolo train obb --data /path/to/data --model yolo11n-obb.ptPerfect for learning and validating your setup:
# Generate synthetic dataset (great for learning!)
lit-yolo create dataset --output ./test_data --num_samples 100
# Train on synthetic data (fast experimentation)
lit-yolo train detect --data ./test_data --model yolo11n.pt --epochs 10Preview your data before training:
# Visualize and save to file
lit-yolo show dataset --data /path/to/dataset --output preview.jpg
# Interactive visualization
lit-yolo show dataset --data /path/to/datasetπ Note: These examples show how to use the components programmatically.
from lit_yolo import LitYOLODet, DetDataModule
from pytorch_lightning import Trainer
# Or use components directly for more control (learn the architecture!)
dm = DetDataModule(data="/path/to/dataset", batch_size=8)
model = LitYOLODet(model_name="yolo11n.pt", num_classes=80)
trainer = Trainer(max_epochs=100, accelerator="gpu", devices=1)
trainer.fit(model, datamodule=dm)from lit_yolo import LitYOLOOBB, OBBDataModule
from pytorch_lightning import Trainer
# Granular control (understand how components interact)
dm = OBBDataModule(data="/path/to/data", batch_size=8)
model = LitYOLOOBB(model_name="yolo11n-obb.pt", num_classes=15)
trainer = Trainer(max_epochs=100, precision="16-mixed")
trainer.fit(model, datamodule=dm)π Explore: Check these modules to understand the architecture.
src/lit_yolo/
βββ __init__.py # π¦ Package exports
βββ __main__.py # πͺ CLI entry point
βββ data/ # π Data handling
β βββ datasets.py # - Dataset classes
β βββ data_modules.py # - Lightning DataModules
β βββ utils.py # - Data utilities
β βββ visual.py # - Visualization tools
βββ models.py # π§ Lightning modules
β # - BaseLitYOLO
β # - LitYOLODet
β # - LitYOLOOBB
βββ training.py # ποΈ Training orchestration
# Format: class_id x_center y_center width height
# All values normalized to [0, 1]
0 0.5 0.5 0.3 0.4
1 0.2 0.3 0.15 0.2
# Format: class_id x1 y1 x2 y2 x3 y3 x4 y4
# Four corner points, normalized to [0, 1]
0 0.1 0.1 0.9 0.1 0.9 0.9 0.1 0.9
π‘ Tip: The OBB loader automatically handles both formats! Standard format boxes are converted with rotation=0.
Perfect for testing, debugging, and learning without requiring real data:
# Generate with default settings (shape-based classes)
lit-yolo create dataset --output ./synthetic_dataWhat you get:
- β Three geometric shapes (square, triangle, circle)
- β Three colors (red, green, blue)
- β Valid YOLO format labels
- β Train/val splits
- β Perfect for learning and CI/CD testing
Customize Synthetic Data (click to expand)
# Customize your synthetic data (experiment with parameters!)
lit-yolo create dataset \
--output ./custom_synthetic \
--num_samples 200 \
--split_ratio 0.8 \
--img_size 640 \
--class_mode color \
--min_objects 2 \
--max_objects 5 \
--seed 42
# View all options
lit-yolo create dataset --help# Download and extract DATA dataset
wget https://www.ultralytics.com/assets/DOTAv1.5.zip
unzip -qq DOTAv1.5.zip
python -m py_tree DOTAv1.5 -d 1- π PyTorch Lightning Docs
- π Ultralytics YOLO Docs
- π Contributing Guide
- π Code of Conduct
π Welcome: Contributing is a great way to learn! We welcome educational contributions.
We welcome contributions, especially those that improve the educational value of this project!
- Fork the repository
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/lightning-YOLOs.git - Install dev dependencies:
pip install -e ".[dev]" - Create a branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run tests:
pytest . - Format code:
pre-commit run --all-files - Submit a pull request
See CONTRIBUTING.md for detailed guidelines.
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See LICENSE for details.
This is an experimental educational project for learning purposes:
- β Great for learning PyTorch Lightning + YOLO
- β Demonstrates modern ML engineering practices
- β Safe for experimentation and education
β οΈ Not battle-tested for production useβ οΈ May contain bugs and evolving features
Always validate results thoroughly if adapting for any application.
If you find this project helpful for learning, please consider giving it a star! β
Built with β€οΈ for learning PyTorch Lightning & YOLO
Report Issues β’ Ask Questions β’ Share Learning Experiences
