Use DINOv3’s powerful, self-supervised visual features + YOLOv12’s blazing-fast detection, all in one repo. Whether you have only a few hundred labeled images or a medium-sized dataset, DINOV3-YOLOV12 helps you get better detection accuracy — without sacrificing speed. Great for niche domains, small-data projects, or quick prototyping.
322
stars
339
commits
Python
primary language
Aug 16, 2026
updated
5 YOLOv12 sizes • Official DINOv3 models • 4 integration types • Input+Backbone enhancement • Single/Dual/Triple/DualP0P3 integration • 50+ model combinations
📖 Quick Start • 🎯 Model Zoo • 🛠️ Installation • 📊 Training • 🤝 Contributing
🎯 Why DINO Pre-training Matters:
📊 mAP@0.5 Performance Rankings:
| Rank | Model | Integration | DINO Variant | mAP@0.5 | Improvement | Performance Type |
|---|---|---|---|---|---|---|
| 🥇 | YOLOL-vitb16-p0p3 | dualp0p3 | vitb16 | 0.7206 | +88.6% | 🎯 Best Overall |
| 🥈 | YOLOM-vitl16-p0p3 | dualp0p3 | vitl16 | 0.6880 | +65.6% | 🚀 High Performance |
| �� | YOLOS-vitb16-triple | triple | vitb16 | 0.6816 | +68.5% | ⚡ Strong Triple |
| 4 | YOLOM-vitb16-p0p3 | dualp0p3 | vitb16 | 0.6789 | +63.4% | 🎪 Balanced |
| 5 | YOLOv12M | none | none | 0.4154 | Baseline | 📊 Base M |
| 6 | YOLOv12S | none | none | 0.4046 | Baseline | 📈 Base S |
| 7 | YOLOv12L | none | none | 0.3821 | Baseline | 📈 Base L |
| 8 | YOLOM-vitl16-single | single | vitl16 | 0.1953 | -53.0% | ⚠️ Single Only |
📈 Performance Visualization:

🎯 Key Performance Insights (KITTI Dataset):
💡 Model Selection Guide (KITTI Dataset):
🎯 Best Model Configuration for KITTI (Autonomous Driving):
# Optimal configuration for KITTI autonomous driving dataset
python train_yolov12_dino.py \
--data kitti.yaml \
--yolo-size l \
--dino-variant vitb16 \
--integration dualp0p3 \
--epochs 100 \
--batch-size 16 \
--imgsz 640 \
--name kitti_optimized
📈 KITTI Performance Analysis:
📊 mAP@0.5 Performance Rankings:
| Rank | Model | Integration | DINO Variant | mAP@0.5 | Performance Type |
|---|---|---|---|---|---|
| 🥇 | M-vitl16-dualp0p3 | dualp0p3 | vitl16 | 0.5577 | 🎯 Best Overall |
| 🥈 | S-vitb16-triple | triple | vitb16 | 0.5363 | 🚀 High Performance |
| 🥉 | M-vitb16-dualp0p3 | dualp0p3 | vitb16 | 0.5239 | ⚡ Optimal Balance |
| 4 | L-vitb16-dualp0p3 | dualp0p3 | vitb16 | 0.5308 | 🎪 Large Model |
| 5 | M-none-none | none | none | 0.5123 | 📊 Baseline M |
| 6 | S-vitb16-dual | dual | vitb16 | 0.5090 | 🔧 Stable |
| 7 | M-vitl16-single | single | vitl16 | 0.5051 | 🌟 Single Large |
| 8 | M-vitb16-single | single | vitb16 | 0.4978 | 🎯 Single Balanced |
| 9 | S-vitl16-single | single | vitl16 | 0.4965 | ⚡ Small Large |
| 10 | S-vitb16-single | single | vitb16 | 0.4920 | 🌟 Small Single |
| 12 | S-vitb16-single | single | vitb16 | 0.4914 | 🔧 Small Stable |
| 13 | YOLOv12M | none | none | 0.4904 | 📈 Standard M |
| 14 | YOLOv12S | none | none | 0.4854 | 📈 Standard S |
| 15 | S-vitl16-triple | triple | vitl16 | 0.4727 | 🎪 Small Triple |
| 16 | M-vitl16-single | single | vitl16 | 0.4645 | 🌟 Large Single |
| 17 | YOLOv12L | none | none | 0.4539 | 📈 Standard L |
📈 Performance Visualization:

🎯 Key Performance Insights (Construction PPE - Small Dataset):
💡 Model Selection Guide (Construction PPE Dataset):
🔥 Key Insights (Small Dataset Training):
🎯 Best Model Configuration for Construction PPE (Small Dataset Example):
📈 Performance Analysis:
🧠 Self-Supervised Learning Advantage:
📊 Small Dataset Training Strategy:
⚠️ Important Notes:
--integration single for datasets <2000 images--unfreeze-dino only after 20-30 epochs if performance plateaus📈 Performance Visualization:

🎯 Key Performance Insights (COCO Dataset):
💡 Model Selection Guide (COCO Dataset):
🔥 Dataset Size Impact Analysis:
| Dataset Type | Dataset Size | DINO Improvement | Best Integration | Recommendation |
|---|---|---|---|---|
| Complex (KITTI) | Medium (~7K images) | +60-88% | DualP0P3, Triple | DINO Essential |
| Small (PPE) | Small (<1K images) | +15-25% | Single, DualP0P3 | DINO Highly Recommended |
| Large (COCO) | Large (>100K images) | +2-5% | Single | DINO Optional |
💡 Key Insight:
Get started in 5 minutes! Choose your path:
# 1. Clone and setup
git clone https://github.com/Sompote/DINOV3-YOLOV12.git
cd DINOV3-YOLOV12
conda create -n dinov3-yolov12 python=3.11 -y
conda activate dinov3-yolov12
# 2. Install dependencies
pip install -r requirements.txt transformers
pip install -e .
# 3. Setup Hugging Face authentication (REQUIRED for DINOv3)
# Method 1: Environment variable (recommended)
export HUGGINGFACE_HUB_TOKEN="your_token_here"
# Get token: https://huggingface.co/settings/tokens
# Permissions: Read access to repos + public gated repos
# Method 2: Interactive login
huggingface-cli login
# Enter your token when prompted (input will be hidden)
# Token will be saved for future use
# Verify authentication
huggingface-cli whoami
# Should show your username if authenticated correctly
# 4. Quick test - Pure YOLOv12 (fastest, no DINO)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 5 \
--name quick_test
# Best for: Speed, production, baseline comparison
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 100 \
--name pure_yolov12
# Best for: Stable training, most balanced enhancement
# +3-8% mAP improvement with minimal overhead
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100 \
--name stable_enhancement
# Best for: Complex scenes, small objects
# +10-18% mAP improvement, 2x training time
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration dual \
--epochs 100 \
--batch-size 8 \
--name high_performance
# Launch web interface
python launch_streamlit.py
# Open browser: http://localhost:8501
# Upload images and pre-trained models for instant detection!
| Your Goal | Use This Command | Training Time | Memory |
|---|---|---|---|
| Fast baseline | Pure YOLOv12 (no --dino-variant) | 2hrs | 3GB |
| Balanced enhancement 🌟 | --integration single | 3hrs | 6GB |
| Maximum accuracy | --integration dual | 5hrs | 10GB |
Problem: "No validation data"
# Make sure your data.yaml has correct paths
val: valid/images # or ../valid/images
Problem: "HUGGINGFACE_HUB_TOKEN not found" or "401 Unauthorized"
# Solution 1: Environment variable
export HUGGINGFACE_HUB_TOKEN="hf_your_token_here"
# Solution 2: Interactive login (easier)
huggingface-cli login
# Enter your token and press Enter
# Verify it works
huggingface-cli whoami
# If still failing, get a new token:
# 1. Visit: https://huggingface.co/settings/tokens
# 2. Create new token with permissions:
# - Read access to repos
# - Read access to public gated repos
Problem: "NaN loss"
# Reduce batch size and learning rate
--batch-size 16 --lr 0.005
2025/10/13: NEW: --pretrainyolo option seeds dualp0p3 runs with YOLO backbone weights (P4+) while leaving the DINO P0–P3 pipeline fresh—ideal for quick starts on custom datasets.
2025/10/03: 🎯 MAJOR: EXACT Training State Restoration - Revolutionary enhancement to train_resume.py! Now provides perfect training continuity with exact state restoration. Training resumes with identical loss values (no more 4x spikes), exact learning rate (0.00012475 vs old 0.01 shock), and all 61 hyperparameters automatically extracted. Solves the "training starts from scratch" problem completely. Real-world tested: User's checkpoint resumed seamlessly with box_loss: 0.865870, cls_loss: 0.815450 - exactly as expected. Just run: python train_resume.py --checkpoint /path/to/checkpoint.pt --epochs 400
2025/09/29: 🎯 NEW: DualP0P3 Integration - Added new --integration dualp0p3 option combining P0 input preprocessing with P3 backbone enhancement! This optimized dual integration provides balanced performance with moderate computational cost (~6GB VRAM, 1.5x training time) while delivering +8-15% mAP improvement. Perfect for users who want enhanced performance without the full computational overhead of triple integration. Architecture: Input → DINO3Preprocessor → YOLOv12 → DINO3(P3) → Head.
2025/09/27: 🎉 BREAKTHROUGH: Local Weight File Support FULLY WORKING - Successfully implemented and tested --dino-input /path/to/weights.pth for loading custom DINO weight files! Major fixes: Fixed TypeError in config path resolution, proper YAML file path quoting, DetectionModel object handling, channel dimension compatibility, and A2C2f architecture support. Real-world tested with user's custom weight file - training starts successfully. Local .pth, .pt, and .safetensors files now fully supported with automatic architecture inference.
2025/09/26: 🔄 REVISED: Integration Logic & Enforcement - Updated --integration option meanings for better user understanding: single = P0 input preprocessing only, dual = P3+P4 backbone integration, triple = P0+P3+P4 all levels. IMPORTANT: --integration is now REQUIRED when using DINO enhancement. Pure YOLOv12 training requires no DINO arguments.
2025/09/14: 🚀 NEW: Complete DINOv3-YOLOv12 Integration - Added comprehensive integration with official DINOv3 models from Facebook Research! Features systematic architecture with 40+ model combinations, 3 integration approaches (Single P0, Dual P3+P4, Triple P0+P3+P4), and support for all model sizes (n,s,l,x). Now includes --dino-input parameter for custom models and 100% test success rate across all variants.
2025/02/19: arXiv version is public. Demo is available.
YOLOv12 surpasses all popular real-time object detectors in accuracy with competitive speed. For example, YOLOv12-N achieves 40.6% mAP with an inference latency of 1.64 ms on a T4 GPU, outperforming advanced YOLOv10-N / YOLOv11-N by 2.1%/1.2% mAP with a comparable speed. This advantage extends to other model scales. YOLOv12 also surpasses end-to-end real-time detectors that improve DETR, such as RT-DETR / RT-DETRv2: YOLOv12-S beats RT-DETR-R18 / RT-DETRv2-R18 while running 42% faster, using only 36% of the computation and 45% of the parameters.
🚀 Systematic Architecture
|
🌟 Advanced Features
|
| Category | Option | Type | Default | Description | Example |
|---|---|---|---|---|---|
| Core Model | --data | str | Required | Dataset YAML file | --data coco.yaml |
--yolo-size | str | Required | YOLOv12 size (n,s,m,l,x) | --yolo-size s | |
--epochs | int | None | Training epochs | --epochs 100 | |
--batch-size | int | None | Batch size | --batch-size 16 | |
--device | str | '0' | GPU device | --device cpu | |
| DINOv3 Integration | --dinoversion | str | '3' | DINO version (2,3) | --dinoversion 3 |
--dino-variant | str | None | DINO model variant | --dino-variant vitb16 | |
--integration | str | None | Integration type | --integration single | |
--dino-input | str | None | Custom DINO model path | --dino-input ./model.pth | |
--unfreeze-dino | flag | False | Make DINO weights trainable | --unfreeze-dino | |
| Pretraining | --pretrain | str | None | Resume full YOLO checkpoint (architecture + optimizer) | --pretrain runs/detect/exp/weights/last.pt |
--pretrainyolo | str | None | Seed dualp0p3 P4+ layers from a base YOLO weight file | --pretrainyolo yolov12l.pt | |
| Evaluation | --fitness | float | 0.1 | Weight on mAP@0.5 for best-model fitness (1-weight applied to mAP@0.5:0.95) | --fitness 0.5 |
| Training Control | --lr | float | 0.01 | Learning rate | --lr 0.005 |
--lrf | float | 0.01 | Final learning rate | --lrf 0.1 | |
--optimizer | str | 'SGD' | Optimizer (SGD,Adam,AdamW) | --optimizer AdamW | |
--patience | int | 100 | Early stopping patience | --patience 50 | |
--amp | flag | False | Automatic mixed precision | --amp | |
--cos-lr | flag | False | Cosine learning rate | --cos-lr | |
| Data Augmentation | --mosaic | float | 1.0 | Mosaic augmentation | --mosaic 0.8 |
--mixup | float | 0.05 | Mixup augmentation | --mixup 0.2 | |
--scale | float | 0.9 | Scale augmentation | --scale 0.8 | |
--degrees | float | 0.0 | Rotation degrees | --degrees 10 | |
--translate | float | 0.1 | Translation | --translate 0.2 | |
--fliplr | float | 0.5 | Horizontal flip | --fliplr 0.6 | |
| Evaluation & Results | --eval-test | flag | True | Evaluate on test data | --eval-test |
--eval-val | flag | True | Evaluate on validation data | --eval-val | |
--detailed-results | flag | True | Show detailed mAP summary | --detailed-results | |
--save-results-table | flag | False | Save results as markdown table | --save-results-table | |
| System & Output | --workers | int | 8 | Dataloader workers | --workers 16 |
--name | str | None | Experiment name | --name my_experiment | |
--project | str | 'runs/detect' | Project directory | --project results/ | |
--seed | int | 0 | Random seed | --seed 42 |
Pretrain Flags:
--pretrainresumes an existing YOLO/DINO checkpoint end‑to‑end, while--pretrainyologives new dualp0p3 runs a YOLO backbone head start without touching the DINO-enhanced front half. Fitness Flag:--fitnesscontrols how best-model selection balances mAP@0.5 vs. mAP@0.5:0.95 (e.g.,--fitness 0.5weights them equally).
The enhanced training system now provides comprehensive mAP results in a structured format:
================================================================================
📊 TRAINING COMPLETE - COMPREHENSIVE mAP RESULTS SUMMARY
================================================================================
🏆 BEST MODEL - VALIDATION DATA:
mAP@0.5 : 0.7250
mAP@0.75 : 0.4830
mAP@0.5:0.95 : 0.5120
🧪 BEST MODEL - TEST DATA:
mAP@0.5 : 0.7180
mAP@0.75 : 0.4750
mAP@0.5:0.95 : 0.5050
📋 COMPARISON SUMMARY:
Best mAP@0.5 : 0.7250 (Best Model on Validation Data)
Best mAP@0.5:0.95 : 0.5120 (Best Model on Validation Data)
================================================================================
| Integration Type | Architecture | DINO Enhancement Points | Memory | Speed | mAP Gain | Best For |
|---|---|---|---|---|---|---|
| None (Pure YOLOv12) | Standard CNN | None | 3GB | ⚡ Fastest | Baseline | Speed-critical apps |
| Single (P0 Input) | Input → DINO3 → YOLOv12 | P0 (input preprocessing) | 6GB | 🌟 Fast | +3-8% | Most stable, general use |
| Dual (P3+P4 Backbone) | YOLOv12 → DINO3(P3,P4) → Head | P3 (80×80) + P4 (40×40) | 10GB | ⚡ Medium | +10-18% | Complex scenes, small objects |
| DualP0P3 (Optimized) | DINO3(P0) → YOLOv12 → DINO3(P3) | P0 (input) + P3 (80×80) | 8GB | 🎯 Balanced | +8-15% | Balanced performance |
| Triple (All Levels) | DINO3(P0) → YOLOv12 → DINO3(P3,P4) | P0 + P3 (80×80) + P4 (40×40) | 12GB | 🚀 Slower | +15-25% | Maximum enhancement |
| DINO Variant | Parameters | Embed Dim | Memory | Speed | Architecture | Best For |
|---|---|---|---|---|---|---|
| vits16 | 21M | 384 | 4GB | ⚡ Fastest | ViT-Small/16 | Development, prototyping |
| vitb16 | 86M | 768 | 8GB | 🎯 Balanced | ViT-Base/16 | Recommended for production |
| vitl16 | 300M | 1024 | 14GB | 🏋️ Medium | ViT-Large/16 | High accuracy research |
| vith16_plus | 840M | 1280 | 32GB | 🐌 Slow | ViT-Huge+/16 Distilled | Enterprise, specialized |
| vit7b16 | 6.7B | 4096 | 100GB+ | ⚠️ Very Slow | ViT-7B/16 Ultra | Research only |
| convnext_tiny | 29M | 768 | 4GB | ⚡ Fast | CNN-ViT Hybrid | Lightweight hybrid |
| convnext_small | 50M | 768 | 6GB | 🎯 Balanced | CNN-ViT Hybrid | Hybrid choice |
| convnext_base | 89M | 1024 | 8GB | 🏋️ Medium | CNN-ViT Hybrid | Production hybrid |
| convnext_large | 198M | 1536 | 16GB | 🐌 Slow | CNN-ViT Hybrid | Maximum hybrid |
| Use Case | Integration | DINO Variant | Command Template | Memory | Time | Best For |
|---|---|---|---|---|---|---|
| Quick Test | None | None | --yolo-size s --epochs 5 --name test | 3GB | 10min | Development |
| Pure YOLOv12 | None | None | --yolo-size s --epochs 100 | 3GB | 2hrs | Baseline comparison |
| DINO Single ViT-B | single | vitb16 | --yolo-size s --dino-variant vitb16 --integration single --epochs 100 | 6GB | 3hrs | Most stable enhancement |
| DINO Single ViT-S | single | vits16 | --yolo-size s --dino-variant vits16 --integration single --epochs 100 | 4GB | 2.5hrs | Lightweight enhancement |
| DINO Dual ViT-B | dual | vitb16 | --yolo-size s --dino-variant vitb16 --integration dual --epochs 100 | 10GB | 5hrs | High performance |
| DINO DualP0P3 | dualp0p3 | vitb16 | --yolo-size m --dino-variant vitb16 --integration dualp0p3 --epochs 100 | 8GB | 4hrs | Balanced enhancement |
| DINO Triple | triple | vitb16 | --yolo-size l --dino-variant vitb16 --integration triple --epochs 100 | 12GB | 8hrs | Maximum enhancement |
| ConvNeXt Hybrid | single | convnext_base | --yolo-size s --dino-variant convnext_base --integration single --epochs 100 | 8GB | 3.5hrs | CNN-ViT hybrid |
| Enterprise ViT-H+ | dual | vith16_plus | --yolo-size l --dino-variant vith16_plus --integration dual --epochs 200 | 32GB | 20hrs | Enterprise grade |
| Research ViT-7B | single | vit7b16 | --yolo-size l --dino-variant vit7b16 --integration single --epochs 50 | 100GB+ | 40hrs+ | Research only |
| Custom Model | single | Custom | --yolo-size l --dino-input ./model.pth --integration single --epochs 100 | 8GB | 4hrs | Domain-specific |
| Production Large | dual | vitl16 | --yolo-size l --dino-variant vitl16 --integration dual --epochs 300 --amp | 16GB | 12hrs | Maximum quality |
Comprehensive technical architecture showing internal components, data flow, and feature processing pipeline for YOLOv12 + DINOv3 integration
YOLOv12 + DINOv3 Integration - Enhanced object detection with Vision Transformers. This implementation provides four distinct integration approaches for maximum flexibility:
Input Image → DINO3Preprocessor → Original YOLOv12 → Output
--dinoversion 3 --dino-variant vitb16 --integration singleInput → YOLOv12 → DINO3(P3) → YOLOv12 → DINO3(P4) → Head → Output
--dinoversion 3 --dino-variant vitb16 --integration dualInput → DINO3Preprocessor → YOLOv12 → DINO3(P3) → Head → Output
--dinoversion 3 --dino-variant vitb16 --integration dualp0p3Input → DINO3Preprocessor → YOLOv12 → DINO3(P3) → DINO3(P4) → Head → Output
--dinoversion 3 --dino-variant vitb16 --integration tripleOur systematic approach follows a clear pattern:
yolov12{size}-dino{version}-{variant}-{integration}.yaml
Components:
{size}: YOLOv12 size → n (nano), s (small), m (medium), l (large), x (extra large){version}: DINO version → 3 (DINOv3){variant}: DINO model variant → vitb16, convnext_base, vitl16, etc.{integration}: Integration type → single (P0 input), dual (P3+P4 backbone), dualp0p3 (P0+P3 optimized), triple (P0+P3+P4 all levels)| Model | YOLOv12 Size | DINO Backbone | Integration | Parameters | Speed | Use Case | Best For |
|---|---|---|---|---|---|---|---|
| 🚀 yolov12n | Nano | Standard CNN | None | 2.5M | ⚡ Fastest | Ultra-lightweight | Embedded systems |
| 🌟 yolov12s-dino3-vitb16-single | Small + ViT-B/16 | Single (P0 Input) | 95M | 🌟 Stable | Input Preprocessing | Most Stable | |
| ⚡ yolov12s-dino3-vitb16-dual | Small + ViT-B/16 | Dual (P3+P4) | 95M | ⚡ Efficient | Backbone Enhancement | High Performance | |
| 🎯 yolov12s-dino3-vitb16-dualp0p3 | Small + ViT-B/16 | DualP0P3 (P0+P3) | 95M | 🎯 Optimized | Targeted Enhancement | Balanced Performance | |
| 🚀 yolov12s-dino3-vitb16-triple | Small + ViT-B/16 | Triple (P0+P3+P4) | 95M | 🚀 Ultimate | Full Integration | Maximum Enhancement | |
| 🏋️ yolov12l | Large | Standard CNN | None | 26.5M | 🏋️ Medium | High accuracy CNN | Production systems |
| 🎯 yolov12l-dino3-vitl16-dual | Large + ViT-L/16 | Dual (P3+P4) | 327M | 🎯 Maximum | Complex scenes | Research/High-end |
--dinoversion 3 --dino-variant vitb16 --integration single--dinoversion 3 --dino-variant vitb16 --integration dual--dinoversion 3 --dino-variant vitb16 --integration dualp0p3--dinoversion 3 --dino-variant vitb16 --integration triple| Model | YOLOv12 Size | Parameters | Memory | Speed | mAP@0.5 | Status |
|---|---|---|---|---|---|---|
yolov12n | Nano | 2.5M | 2GB | ⚡ 1.60ms | 40.4% | ✅ Working |
yolov12s | Small | 9.1M | 3GB | ⚡ 2.42ms | 47.6% | ✅ Working |
yolov12m | Medium | 19.6M | 4GB | 🎯 4.27ms | 52.5% | ✅ Working |
yolov12l | Large | 26.5M | 5GB | 🏋️ 5.83ms | 53.8% | ✅ Working |
yolov12x | XLarge | 59.3M | 7GB | 🏆 10.38ms | 55.4% | ✅ Working |
| Systematic Name | YOLOv12 + DINOv3 | Parameters | Memory | mAP Improvement | Status |
|---|---|---|---|---|---|
yolov12n-dino3-vits16-single | Nano + ViT-S | 23M | 4GB | +5-8% | ✅ Working |
yolov12s-dino3-vitb16-single | Small + ViT-B | 95M | 8GB | +7-11% | ✅ Working |
yolov12l-dino3-vitl16-single | Large + ViT-L | 327M | 14GB | +8-13% | ✅ Working |
yolov12l-dino3-vitl16-dual | Large + ViT-L Dual | 327M | 16GB | +10-15% | ✅ Working |
yolov12x-dino3-vith16_plus-single | XLarge + ViT-H+ | 900M | 32GB | +12-18% | ✅ Working |
| Systematic Name | DINOv3 ConvNeXt | Parameters | Architecture | mAP Improvement |
|---|---|---|---|---|
yolov12s-dino3-convnext_small-single | ConvNeXt-Small | 59M | CNN-ViT Hybrid | +6-9% |
yolov12m-dino3-convnext_base-single | ConvNeXt-Base | 109M | CNN-ViT Hybrid | +7-11% |
yolov12l-dino3-convnext_large-single | ConvNeXt-Large | 225M | CNN-ViT Hybrid | +9-13% |
🔥 Key Advantage: Combines CNN efficiency with Vision Transformer representational power
| Variant | Parameters | Embed Dim | Memory | Speed | Use Case | Recommended For |
|---|---|---|---|---|---|---|
dinov3_vits16 | 21M | 384 | ~4GB | ⚡ Fastest | Development, mobile | Prototyping, edge devices |
dinov3_vitb16 | 86M | 768 | ~8GB | 🎯 Balanced | Recommended | General purpose, production |
dinov3_vitl16 | 300M | 1024 | ~14GB | 🏋️ Slower | High accuracy | Research, complex scenes |
dinov3_vith16_plus | 840M | 1280 | ~32GB | 🐌 Slowest | Maximum performance | Enterprise, specialized |
dinov3_vit7b16 | 6.7B | 4096 | >100GB | ⚠️ Experimental | Ultra-high-end | Research only |
ViT-H+/16 Distilled (840M Parameters)
--dino-variant vith16_plus --integration single/dual/tripleViT-7B/16 Ultra (6.7B Parameters)
--dino-variant vit7b16 --integration single/dual/triple| Variant | Parameters | Embed Dim | Memory | Speed | Use Case | Recommended For |
|---|---|---|---|---|---|---|
dinov3_convnext_tiny | 29M | 768 | ~4GB | ⚡ Fast | Lightweight hybrid | Efficient deployments |
dinov3_convnext_small | 50M | 768 | ~6GB | 🎯 Balanced | Hybrid choice | CNN+ViT benefits |
dinov3_convnext_base | 89M | 1024 | ~8GB | 🏋️ Medium | Robust hybrid | Production hybrid |
dinov3_convnext_large | 198M | 1536 | ~16GB | 🐌 Slower | Maximum hybrid | Research hybrid |
For Beginners:
dinov3_vitb16 (most balanced)dinov3_vits16 for faster developmentFor Production:
dinov3_vitb16 for general use (recommended)dinov3_convnext_base for CNN-ViT hybrid approachFor Research:
dinov3_vitl16 for maximum accuracy (14GB VRAM)dinov3_vith16_plus for cutting-edge performance (32GB VRAM)dinov3_vit7b16 for experimental ultra-high-end research (100GB+ VRAM)Memory Constraints:
dinov3_vits16, dinov3_convnext_tinydinov3_vitb16, dinov3_convnext_basedinov3_vitl16dinov3_vith16_plus (ViT-H+/16 Distilled 840M)100GB VRAM:
dinov3_vit7b16(ViT-7B/16 Ultra 6.7B)
# Lightweight development (4GB VRAM)
--dinoversion 3 --dino-variant vits16
# Recommended production (8GB VRAM)
--dinoversion 3 --dino-variant vitb16
# High accuracy research (14GB+ VRAM)
--dinoversion 3 --dino-variant vitl16
# Ultra-high performance (32GB+ VRAM) - ViT-H+/16 Distilled
--dinoversion 3 --dino-variant vith16_plus
# Experimental research (100GB+ VRAM) - ViT-7B/16 Ultra
--dinoversion 3 --dino-variant vit7b16
# Hybrid CNN-ViT approach (8GB VRAM)
--dinoversion 3 --dino-variant convnext_base
🔥 Most Popular Choices:
dinov3_vitb16 # ⭐ RECOMMENDED: Best balance (86M params, 8GB VRAM)
dinov3_vits16 # ⚡ FASTEST: Development & prototyping (21M params, 4GB VRAM)
dinov3_vitl16 # 🎯 HIGHEST ACCURACY: Research use (300M params, 14GB VRAM)
dinov3_convnext_base # 🧠 HYBRID: CNN+ViT fusion (89M params, 8GB VRAM)
💡 Pro Tip: Start with dinov3_vitb16 for best results, then scale up/down based on your needs!
--dinoversion Argument - DINOv3 is Default🔥 Important Update: The training script now uses --dinoversion instead of --dino-version:
# NEW ARGUMENT: --dinoversion with DINOv3 as DEFAULT
--dinoversion 3 # DINOv3 (DEFAULT) - Latest Vision Transformer models
--dinoversion 2 # DINOv2 (Legacy) - For backward compatibility
Key Features:
--dinoversion 3 if not specified--dino-version to --dinoversion--dinoversion 2# 🚀 PURE YOLOv12 (No DINO) - Fast & Lightweight
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 100 \
--name pure_yolov12
# 🌟 SINGLE INTEGRATION (P0 Input) - Most Stable & Recommended
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100 \
--batch-size 16 \
--name stable_p0_preprocessing
# 🎪 DUAL INTEGRATION (P3+P4 Backbone) - High Performance
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration dual \
--epochs 100 \
--batch-size 16 \
--name high_performance_p3p4
# 🎯 DUALP0P3 INTEGRATION (P0+P3 Optimized) - Balanced Performance
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size m \
--dino-variant vitb16 \
--integration dualp0p3 \
--epochs 100 \
--batch-size 12 \
--name optimized_p0p3
# 🚀 TRIPLE INTEGRATION (P0+P3+P4 All Levels) - Maximum Enhancement
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--dino-variant vitb16 \
--integration triple \
--epochs 100 \
--batch-size 8 \
--name ultimate_p0p3p4
# ❌ WRONG: DINO variant without integration (will fail)
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16
# ✅ CORRECT: DINO variant with integration
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration single
# ✅ CORRECT: Pure YOLOv12 (no DINO arguments needed)
python train_yolov12_dino.py --data data.yaml --yolo-size s
| Model Type | Command Parameters | DINO Version | Best For |
|---|---|---|---|
| Pure YOLOv12 🚀 | --yolo-size s (no DINO arguments) | None | Fast training, lightweight, production |
| Single (P0 Input) 🌟 | --dino-variant vitb16 --integration single | DINOv3 (auto) | Most stable, input preprocessing |
| Dual (P3+P4 Backbone) 🎪 | --dino-variant vitb16 --integration dual | DINOv3 (auto) | High performance, multi-scale backbone |
| DualP0P3 (P0+P3 Optimized) 🎯 | --dino-variant vitb16 --integration dualp0p3 | DINOv3 (auto) | Balanced performance, targeted enhancement |
| Triple (P0+P3+P4 All) 🚀 | --dino-variant vitb16 --integration triple | DINOv3 (auto) | Maximum enhancement, all levels |
| Legacy Support 🔄 | --dinoversion 2 --dino-variant vitb16 --integration single | DINOv2 (explicit) | Existing workflows |
--dino-input vs --pretrainClear distinction between DINO model loading and checkpoint resuming:
--dino-input: Custom DINO Models for EnhancementUse --dino-input to load custom DINO models for backbone enhancement. Supports two methods:
Download and use Meta's official DINOv3 pretrained weights:
| Model | Parameters | Download Link | File Size |
|---|---|---|---|
| ViT-S/16 | 21M | dinov3_vits16_pretrain.pth | ~84 MB |
| ViT-B/16 | 86M | dinov3_vitb16_pretrain.pth | ~343 MB |
| ViT-L/16 | 300M | dinov3_vitl16_pretrain.pth | ~1.2 GB |
| ViT-L/16 (SAT) | 300M | dinov3_vitl16_pretrain_sat493m.pth | ~1.2 GB |
Download and use:
# Download Meta's official weights
mkdir -p dinov3/weights && cd dinov3/weights
wget https://dl.fbaipublicfiles.com/dinov3/dinov3_vitb16_pretrain.pth
# 🏗️ Single Integration with Meta's Official Weights (P0 Input)
python train_yolov12_dino.py \
--data /path/to/your/data.yaml \
--yolo-size s \
--dino-input dinov3/weights/dinov3_vitb16_pretrain.pth \
--integration single \
--epochs 100 \
--name meta_weights_single
# 🎪 Dual Integration with Satellite-trained Weights (P3+P4 Backbone)
python train_yolov12_dino.py \
--data kitti.yaml \
--yolo-size l \
--dino-input dinov3/weights/dinov3_vitl16_pretrain_sat493m.pth \
--integration dual \
--epochs 200 \
--name satellite_weights_dual
Use your domain-specific fine-tuned DINOv3 models:
# Use custom fine-tuned DINO weights for medical imaging
python train_yolov12_dino.py \
--data medical_dataset.yaml \
--yolo-size m \
--dino-input /path/to/my_medical_finetuned_dinov3.pth \
--integration dualp0p3 \
--epochs 150 \
--name medical_custom_weights
# Use fine-tuned weights for aerial imagery
python train_yolov12_dino.py \
--data aerial_dataset.yaml \
--yolo-size l \
--dino-input /path/to/aerial_finetuned_dino.pt \
--integration triple \
--epochs 200 \
--name aerial_custom_weights
Supported file formats:
.pth - PyTorch checkpoint file.pt - PyTorch model file.safetensors - Safe tensors formatOr let the system auto-download from HuggingFace:
# Auto-download from HuggingFace using variant name
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100 \
--name huggingface_auto
💡 When to use each method:
--pretrain: Resume Training from YOLO CheckpointsUse --pretrain to load pretrained YOLO checkpoints for continuing training:
# ✅ Resume training from a YOLO checkpoint
python train_yolov12_dino.py \
--data /path/to/your/data.yaml \
--yolo-size l \
--pretrain /path/to/your/last.pt \
--integration triple \
--epochs 400 \
--name cont_training
# ✅ Continue training with different configuration
python train_yolov12_dino.py \
--data /path/to/your/data.yaml \
--yolo-size l \
--pretrain /Users/Downloads/checkpoint.pt \
--epochs 200 \
--batch-size 8 \
--name resumed_training
train_resume.pyUse the enhanced train_resume.py script for EXACT training state restoration - training continues exactly where it left off:
# ✅ RECOMMENDED: Perfect state restoration (resumes with exact same loss values)
python train_resume.py \
--checkpoint /path/to/your/checkpoint.pt \
--epochs 400 \
--device 0,1
# ✅ Resume with different dataset (keeps all other settings identical)
python train_resume.py \
--checkpoint /workspace/DINOV3-YOLOV12/runs/detect/high_performance_p3p46/weights/last.pt \
--data coco.yaml \
--epochs 200 \
--batch-size 32 \
--name resumed_training \
--device 0,1
# ✅ Resume for fine-tuning (only change specific parameters)
python train_resume.py \
--checkpoint /Users/model_weight/diloyolo12_coco/last-2.pt \
--epochs 100 \
--unfreeze-dino \
--name fine_tuned_training
🎯 ENHANCED Features of train_resume.py (v2.0):
For manual control, you can still use the main training script, but you MUST specify the same DINO configuration:
# ✅ Resume DINO training - specify DINO arguments to match checkpoint
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--pretrain /workspace/DINOV3-YOLOV12/runs/detect/high_performance_p3p46/weights/last.pt \
--dinoversion 3 \
--dino-variant vitb16 \
--integration triple \
--epochs 400 \
--batch-size 60 \
--name cont_p3p4 \
--device 0,1
# ❌ WRONG - will cause architecture mismatch
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--pretrain /path/to/dino_checkpoint.pt \
--epochs 400
# Missing DINO arguments causes pure YOLOv12 mode
⚠️ Important: When using the legacy method, always include the original DINO configuration (--dinoversion, --dino-variant, --integration) to prevent architecture conflicts.
The enhanced train_resume.py provides perfect training continuity by restoring the exact training state:
🎯 RESTORING EXACT TRAINING STATE
============================================================
📊 Complete Training State Extracted:
Last Epoch: 199
Best Fitness: 0.699
Training Updates: 50000
Final Learning Rate: 0.00012475
Expected Loss Values (training should start with these):
box_loss: 0.865870
cls_loss: 0.815450
dfl_loss: 1.100720
🔧 EXTRACTING ALL HYPERPARAMETERS FROM CHECKPOINT
✅ Extracted 61 hyperparameters from checkpoint
📈 EXACT LEARNING RATE RESTORATION:
Original lr0: 0.01
Final training LR: 0.00012475
Resume LR: 0.00012475 (EXACT same as last step)
🎯 Training will continue from EXACT same state!
| Aspect | ❌ Before (Problem) | ✅ After (Enhanced) |
|---|---|---|
| Loss Values | 4x higher (3.66 vs 0.866) | Identical (0.866 → 0.866) |
| Learning Rate | Reset to 0.01 (80x shock) | Exact (0.00012475) |
| Training State | "Starting from scratch" | Perfect continuity |
| Hyperparameters | Default values used | All 61 extracted |
| User Experience | Frustrating loss spikes | Seamless resumption |
| Method | Auto-Detection | State Restoration | Data Required | DINO Config Required | Best For |
|---|---|---|---|---|---|
train_resume.py ✅ | Full auto | EXACT | ❌ No | ❌ No | Recommended - Perfect Continuity |
train_yolov12_dino.py --pretrain | Manual | Partial | ✅ Yes | ✅ Yes | Manual control & custom settings |
# Just provide checkpoint - everything else is automatic!
python train_resume.py --checkpoint /path/to/checkpoint.pt --epochs 400 --device 0,1
🎯 EXACT STATE RESTORATION:
Final Learning Rate: 0.00012475
Expected Loss Values:
box_loss: 0.865870 ← Training starts HERE (not 4x higher!)
cls_loss: 0.815450
dfl_loss: 1.100720
✅ Extracted 61 hyperparameters from checkpoint
🎯 Training will continue from EXACT same state!
| Parameter | Purpose | Input Type | Use Case |
|---|---|---|---|
--dino-input | Load custom DINO models | DINO backbone weights (.pth, .pt) | Enhanced vision features |
--pretrain | Resume YOLO training | YOLO checkpoint (.pt) | Continue training from checkpoint |
--pretrainyolo | Inject base YOLO weights into dualp0p3 models | YOLO backbone weights (.pt) | Start dualp0p3 runs with P4+ YOLO initialization |
Note:
--pretrainyolois optimized for thedualp0p3integration (YOLOv12-L). The script automatically copies weights from layer P4 onward while keeping the DINO-enhanced P0–P3 pipeline untouched. It’s ideal when you want a YOLO foundation but still train the DINO front end from scratch.
# DualP0P3 with partial YOLO pretraining (recommended for crack datasets)
python train_yolov12_dino.py \
--data crack.yaml \
--yolo-size l \
--dinoversion 3 \
--dino-variant vitb16 \
--integration dualp0p3 \
--pretrainyolo yolov12l.pt \
--epochs 200 \
--batch-size 8
# Standard ViT models with --dino-variant (alternative to --dino-input)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dinoversion 3 \
--dino-variant vitb16 \
--integration single \
--epochs 100
# PyTorch checkpoint files
--dino-input /path/to/your/custom_dino_model.pth
--dino-input ./fine_tuned_dino.pt
--dino-input /models/specialized_dino.safetensors
--dino-input ~/Downloads/pretrained_dino_weights.pth
# Official Facebook Research models
--dino-input facebook/dinov3-vitb16-pretrain-lvd1689m
--dino-input facebook/dinov2-base
--dino-input facebook/dinov3-vit7b16-pretrain-lvd1689m
# Custom organization models
--dino-input your-org/custom-dino-variant
--dino-input company/domain-specific-dino
# Simplified shortcuts (auto-converted)
--dino-input vitb16 # → dinov3_vitb16
--dino-input convnext_base # → dinov3_convnext_base
--dino-input vith16_plus # → dinov3_vith16_plus
--dino-input vit7b16 # → dinov3_vit7b16
✅ Smart Format Detection:
.pth, .pt, .safetensors formatsstate_dict, model, model_state_dict)✅ Architecture Inference:
✅ Channel Compatibility:
✅ Robust Error Handling:
# Example 1: Domain-specific trained DINO for crack detection
python train_yolov12_dino.py \
--data crack_dataset.yaml \
--yolo-size l \
--dino-input /models/crack_detection_dino.pth \
--integration dual \
--epochs 200 \
--name crack_dino_yolo
# Example 2: Medical imaging DINO with triple integration
python train_yolov12_dino.py \
--data medical_scans.yaml \
--yolo-size x \
--dino-input ./medical_dino_weights.safetensors \
--integration triple \
--epochs 300 \
--name medical_triple_dino
# Example 3: Industrial defect detection with custom model
python train_yolov12_dino.py \
--data defect_data.yaml \
--yolo-size l \
--dino-input /weights/defect_specialized_dino.pt \
--integration dual \
--epochs 150 \
--unfreeze-dino \
--name industrial_defect_detection
| Feature | Status | Description |
|---|---|---|
| Local .pth files | ✅ WORKING | Tested with real user weight files |
| Local .pt files | ✅ WORKING | Full PyTorch checkpoint support |
| Local .safetensors | ✅ WORKING | HuggingFace safetensors format |
| YAML config generation | ✅ FIXED | Properly quoted file paths |
| Channel dimension matching | ✅ FIXED | Automatic YOLOv12 compatibility |
| DetectionModel handling | ✅ FIXED | Handles full model objects |
| Architecture inference | ✅ WORKING | Auto-detects embedding dimensions |
| All integration types | ✅ TESTED | Single, dual, triple all working |
✅ Tested & Confirmed:
📖 Complete Guide: See Custom Input Documentation for detailed examples and troubleshooting.
# 1. Clone the repository
git clone https://github.com/Sompote/DINOV3-YOLOV12.git
cd DINOV3-YOLOV12
# 2. Create conda environment
conda create -n dinov3-yolov12 python=3.11
conda activate dinov3-yolov12
# 3. Install dependencies
pip install -r requirements.txt
pip install transformers # For DINOv3 models
pip install -r requirements_streamlit.txt # For Streamlit web interface
pip install -e .
# 4. Setup Hugging Face authentication (REQUIRED for DINOv3 models)
export HUGGINGFACE_HUB_TOKEN="your_token_here"
# Get your token from: https://huggingface.co/settings/tokens
# Required permissions when creating token:
# - Read access to contents of all repos under your personal namespace
# - Read access to contents of all public gated repos you can access
# Alternative: hf auth login
# 5. Verify installation
python -c "from ultralytics.nn.modules.block import DINO3Backbone; print('✅ DINOv3-YOLOv12 ready!')"
# 6. Quick test (recommended)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-input dinov3_vitb16 \
--integration single \
--epochs 1 \
--name quick_test
# 7. Test Streamlit web interface (optional)
python launch_streamlit.py
# 8. Try pre-trained Construction-PPE model (optional)
wget https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r -O construction_ppe_best.pt
python inference.py --weights construction_ppe_best.pt --source your_image.jpg --save
# For experienced users - complete setup and test in one go
git clone https://github.com/Sompote/DINOV3-YOLOV12.git && \
cd DINOV3-YOLOV12 && \
conda create -n dinov3-yolov12 python=3.11 -y && \
conda activate dinov3-yolov12 && \
pip install -r requirements.txt transformers && \
pip install -e . && \
echo "⚠️ IMPORTANT: Set your Hugging Face token before training:" && \
echo "export HUGGINGFACE_HUB_TOKEN=\"your_token_here\"" && \
echo "Get token from: https://huggingface.co/settings/tokens" && \
echo "Required permissions: Read access to repos + public gated repos" && \
echo "✅ Setup complete! Run: python train_yolov12_dino.py --help"
DINOv3 models from Facebook Research are hosted on Hugging Face as gated repositories, requiring authentication to access.
Create Hugging Face Account: Visit huggingface.co and sign up
Generate Access Token:
Set Required Permissions:
Repositories:
✅ Read access to contents of all repos under your personal namespace
✅ Read access to contents of all public gated repos you can access
Apply Token:
# Method 1: Environment variable (recommended) ✅ FULLY SUPPORTED
export HUGGINGFACE_HUB_TOKEN="hf_your_token_here"
# The training script automatically detects and uses this token
# Method 2: Login command (interactive)
hf auth login
# Follow the interactive prompts:
# - Enter your token (input will not be visible)
# - Choose to add token as git credential (Y/n)
# - Token validation will be confirmed
✅ Token Detection: The training script will show:
Using HUGGINGFACE_HUB_TOKEN: hf_xxxx...
If your token is properly detected.
Verify Access:
hf whoami
# Should show your username if authenticated correctly
wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.3/flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
conda create -n yolov12 python=3.11
conda activate yolov12
pip install -r requirements.txt
pip install transformers # For DINOv3 models
pip install -e .
# Test DINOv3 integration
python -c "from ultralytics.nn.modules.block import DINO3Backbone; print('✅ DINOv3 ready!')"
# Test training script
python train_yolov12_dino.py --help
# Quick functionality test
python test_yolov12l_dual.py
If you have an RTX 5090 GPU, you may encounter CUDA compatibility issues. See RTX 5090 Compatibility Guide for solutions.
Quick Fix for RTX 5090:
# Install PyTorch nightly with RTX 5090 support
pip uninstall torch torchvision -y
pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu121
# Verify RTX 5090 compatibility
python -c "import torch; print(f'✅ GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"No CUDA\"}')"
We provide a specialized YOLOv12-DINO model trained on the Construction-PPE dataset from Ultralytics 8.3.197, optimized for detecting safety equipment on construction sites. This model demonstrates the power of DINO pre-training for small datasets, achieving 35.9% better performance than base YOLOv12.
📊 Model Performance:
🎯 Why This Model Excels:
🔗 Download Trained Weights:
# Download pre-trained Construction-PPE model (mAP@50: 51.9%)
wget https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r -O construction_ppe_best.pt
# Or use direct link
curl -L "https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r" -o construction_ppe_best.pt
🚀 Quick Start with Pre-trained Model:
# Download pre-trained Construction-PPE model (mAP@50: 51.9%)
wget https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r -O construction_ppe_best.pt
# Command-line inference
python inference.py \
--weights construction_ppe_best.pt \
--source your_construction_images/ \
--conf 0.25 \
--save
# Streamlit web interface
python launch_streamlit.py
# Upload construction_ppe_best.pt in the interface
🎯 Perfect for:
💡 Pro Tips for Best Results:
--stream mode for real-time detection🔬 Technical Details:
yolov12n
yolov12s
yolov12m
yolov12l
yolov12x
from ultralytics import YOLO
model = YOLO('yolov12{n/s/m/l/x}.pt')
model.val(data='coco.yaml', save_json=True)
from ultralytics import YOLO
model = YOLO('yolov12n.yaml')
# Train the model
results = model.train(
data='coco.yaml',
epochs=600,
batch=256,
imgsz=640,
scale=0.5, # S:0.9; M:0.9; L:0.9; X:0.9
mosaic=1.0,
mixup=0.0, # S:0.05; M:0.15; L:0.15; X:0.2
copy_paste=0.1, # S:0.15; M:0.4; L:0.5; X:0.6
device="0,1,2,3",
)
# Evaluate model performance on the validation set
metrics = model.val()
# Perform object detection on an image
results = model("path/to/image.jpg")
results[0].show()
from ultralytics import YOLO
# Load YOLOv12 + DINOv3 enhanced model
model = YOLO('ultralytics/cfg/models/v12/yolov12-dino3.yaml')
# Train with Vision Transformer enhancement
results = model.train(
data='coco.yaml',
epochs=100, # Reduced epochs due to enhanced features
batch=16, # Adjusted for DINOv3 memory usage
imgsz=640,
device=0,
)
# Available DINOv3 configurations:
# - yolov12-dino3-small.yaml (fastest, +2.5% mAP)
# - yolov12-dino3.yaml (balanced, +5.0% mAP)
# - yolov12-dino3-large.yaml (best accuracy, +5.5% mAP)
# - yolov12-dino3-convnext.yaml (hybrid, +4.5% mAP)
Launch the professional Streamlit interface with advanced analytics and large file support:
# Method 1: Interactive launcher (recommended)
python launch_streamlit.py
# Method 2: Direct launch
streamlit run simple_streamlit_app.py --server.maxUploadSize=5000
Streamlit Features:
Access: http://localhost:8501

Professional Streamlit interface showing PPE detection with confidence scores, class distribution, and detailed analytics
| Feature | Streamlit App | Command Line |
|---|---|---|
| File Upload Limit | 5GB ✅ | Unlimited ✅ |
| Analytics & Charts | Advanced ✅ | Text only 📝 |
| Data Export | CSV/JSON ✅ | Files ✅ |
| UI Style | Professional 🎯 | Terminal 💻 |
| Best For | Production, Analysis | Automation, Batch |
| Model Support | All sizes ✅ | All sizes ✅ |
| Visualization | Interactive charts 📈 | Text summaries 📄 |
| Deployment | Web-based 🌐 | Script-based 🖥️ |
Use the powerful command-line interface for batch processing and automation:
# Single image inference
python inference.py --weights best.pt --source image.jpg --save --show
# Batch inference on directory
python inference.py --weights runs/detect/train/weights/best.pt --source test_images/ --output results/
# Custom thresholds and options
python inference.py --weights model.pt --source images/ --conf 0.5 --iou 0.7 --save-txt --save-crop
# DINOv3-enhanced model inference
python inference.py --weights runs/detect/high_performance_dual/weights/best.pt --source data/ --conf 0.3
Command Options:
--weights: Path to trained model weights (.pt file)--source: Image file, directory, or list of images--conf: Confidence threshold (0.01-1.0, default: 0.25)--iou: IoU threshold for NMS (0.01-1.0, default: 0.7)--save: Save annotated images--save-txt: Save detection results to txt files--save-crop: Save cropped detection images--device: Device to run on (cpu, cuda, mps)Direct integration into your Python applications:
from ultralytics import YOLO
from inference import YOLOInference
# Method 1: Standard YOLO API
model = YOLO('yolov12{n/s/m/l/x}.pt')
results = model.predict('image.jpg', conf=0.25, iou=0.7)
# Method 2: Enhanced Inference Class
inference = YOLOInference(
weights='runs/detect/train/weights/best.pt',
conf=0.25,
iou=0.7,
device='cuda'
)
# Single image
results = inference.predict_single('image.jpg', save=True)
# Batch processing
results = inference.predict_batch('images_folder/', save=True)
# From image list
image_list = ['img1.jpg', 'img2.jpg', 'img3.jpg']
results = inference.predict_from_list(image_list, save=True)
# Print detailed results
inference.print_results_summary(results, "test_images")
Use your trained DINOv3-YOLOv12 models for enhanced object detection:
# DINOv3 single-scale model
python inference.py \
--weights runs/detect/efficient_single/weights/best.pt \
--source test_images/ \
--conf 0.25 \
--save
# DINOv3 dual-scale model (highest performance)
python inference.py \
--weights runs/detect/high_performance_dual/weights/best.pt \
--source complex_scene.jpg \
--conf 0.3 \
--iou 0.6 \
--save --show
# Input preprocessing model
python inference.py \
--weights runs/detect/stable_preprocessing/weights/best.pt \
--source video.mp4 \
--save
| Model Type | Speed | Memory | Best For | Confidence Threshold |
|---|---|---|---|---|
| YOLOv12n | ⚡ Fastest | 2GB | Embedded systems | 0.4-0.6 |
| YOLOv12s | ⚡ Fast | 3GB | General purpose | 0.3-0.5 |
| YOLOv12s-dino3-single | 🎯 Balanced | 4GB | Medium objects | 0.25-0.4 |
| YOLOv12s-dino3-dual | 🎪 Accurate | 8GB | Complex scenes | 0.2-0.35 |
| YOLOv12l-dino3-vitl16 | 🏆 Maximum | 16GB | Research/High-end | 0.15-0.3 |
Real timings for yolov12m-dualp0p3-dino3-vitb16 (107.3 M params), 640×640, batch 1, on an RTX 5080 — torch 2.12.0+cu130, TensorRT 10.16.1.11, 30 warm-up + 200 timed iterations, CUDA-event timed.
| Runtime | Forward only | End-to-end predict() | FPS | Speedup |
|---|---|---|---|---|
| TensorRT FP16 | 2.72 ms (p99 2.89) | 4.18 ms | 367 | 9.6× |
| PyTorch FP16 | 26.18 ms (p99 26.85) | 27.14 ms | 38 | 1.0× |
| PyTorch FP32 | 26.61 ms (p99 29.99) | 27.99 ms | 38 | 1.0× |
Engine stage breakdown: 1.03 pre + 2.63 infer + 0.39 post ms. Reproduce with:
python benchmark_latency.py --engine best.engine --pt best.pt --imgsz 640
Two things worth noting before quoting these numbers:
.pt with half=True alone buys you almost nothing.See the TensorRT Conversion section under Export for how to build the engine, and for two failure modes that silently produce wrong output.
# Custom preprocessing and postprocessing
from inference import YOLOInference
import cv2
inference = YOLOInference('model.pt')
# Load and preprocess image
image = cv2.imread('image.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Run inference with custom parameters
results = inference.predict_single(
source='preprocessed_image.jpg',
save=True,
show=False,
save_txt=True,
save_conf=True,
save_crop=True,
output_dir='custom_results/'
)
# Access detailed results
for result in results:
boxes = result.boxes.xyxy.cpu().numpy() # Bounding boxes
confs = result.boxes.conf.cpu().numpy() # Confidence scores
classes = result.boxes.cls.cpu().numpy() # Class IDs
names = result.names # Class names dictionary
print(f"Detected {len(boxes)} objects")
for box, conf, cls in zip(boxes, confs, classes):
print(f"Class: {names[int(cls)]}, Confidence: {conf:.3f}")
from ultralytics import YOLO
model = YOLO('yolov12{n/s/m/l/x}.pt')
model.export(format="engine", half=True) # or format="onnx"
Trained DINO-YOLO checkpoints (including the DINOv3 weights baked inside the .pt) convert to TensorRT via a two-stage flow:
best.pt ──► ONNX (portable, any machine) ──► TensorRT engine (NVIDIA GPU only)
The DINOv3 ViT is part of the same graph as YOLOv12, so its weights are exported automatically — no separate conversion of the DINO weights is needed.
# Stage 0 — Export dependencies (not covered by requirements.txt):
pip install onnx onnxslim onnxscript "transformers>=4.56,<4.57"
# Stage 1 — Export ONNX (works on any machine, even without a GPU):
python export_tensorrt.py --weights runs/detect/train/weights/best.pt --format onnx
# Stage 2 — Build the TensorRT engine (run on the NVIDIA GPU machine):
python export_tensorrt.py --weights best.pt --format engine --half
# Alternative: build the engine from the ONNX with trtexec:
trtexec --onnx=best.onnx --saveEngine=best.engine --fp16
| Flag | Default | Description |
|---|---|---|
--weights | (required) | Path to trained .pt checkpoint |
--format | onnx | onnx or engine (TensorRT) |
--imgsz | 640 | Fixed inference image size (see caveats) |
--half | off | FP16 export — recommended for TensorRT (~2× faster) |
--batch | 1 | Fixed batch size |
--workspace | 4 | TensorRT builder workspace in GB |
Fixed input size is required (dynamic=False, enforced by the script). The DINO backbone/preprocessor contains shape-dependent Python branching (patch-grid fitting, padding/truncation) that resolves to constants at trace time only when the input shape is fixed. Pick --imgsz to match your deployment resolution.
SDPA export bug on torch < 2.4. Exporting the ViT's scaled_dot_product_attention fails with TypeError: z_(): incompatible function arguments ... 0.125. The script automatically switches the HuggingFace DINOv3 submodules to eager attention for export — identical outputs, and harmless on newer torch versions.
Warm-up forward pass. DINO projection layers can be created lazily on the first forward; the script runs a dummy pass before tracing so the exported graph is complete.
Expect large artifacts. A ViT-B variant produces a ~385 MB ONNX (fp32) / ~200 MB engine (fp16) and longer TensorRT build times than plain YOLOv12. Raise --workspace if the builder runs out of memory.
NMS stays outside the engine — postprocess exactly as with .pt inference.
transformers must match the version that trained the checkpoint. The DINOv3 ViT is pickled inside the .pt, so its module layout is frozen at training time while its forward() code comes from whatever transformers is installed. Checkpoints trained with 4.56.x carry the layout embeddings / rope_embeddings / layer / norm; loading them under transformers 5.x fails with:
AttributeError: 'DINOv3ViTModel' object has no attribute 'model'
Pin transformers>=4.56,<4.57. Check what a checkpoint expects with:
import torch
ck = torch.load("best.pt", map_location="cpu", weights_only=False)
m = ck.get("ema") or ck["model"]
d = next(x.dino_model for x in m.modules() if hasattr(x, "dino_model"))
print(d.config.transformers_version, [n for n, _ in d.named_children()])
The FP16 engine has FP32 input/output bindings — never feed it half tensors. --half makes TensorRT compute in FP16, but the network I/O stays FP32 (the build log confirms: input "images" ... DataType.FLOAT). Ultralytics binds the input by raw pointer without converting, so a half tensor makes TensorRT read 4 bytes per element out of a 2-byte-per-element buffer. It reads past the end of the buffer, runs at full speed, and silently returns garbage or NaN — there is no error. The failure is nondeterministic, which makes it easy to mistake for a numerical problem.
model = YOLO("best.engine", task="detect")
model.predict(src, imgsz=640) # correct — dtype is auto-detected
model.predict(src, imgsz=640, half=True) # WRONG — silent garbage/NaN
The same applies to AutoBackend: pass fp16=False and let it read the real dtypes off the engine bindings. Verify with AutoBackend("best.engine", ...).fp16, which should report False.
Numerical parity between .pt and ONNX has been validated (max abs diff ~1.5e-4, ordinary fp32 noise). Still, sanity-check your own checkpoint before building the engine:
yolo predict model=best.onnx imgsz=640 source=path/to/test_image.jpg
Compare a few detections against the original .pt — they should match.
Benchmarked with benchmark_latency.py (in the repo root):
python benchmark_latency.py --engine best.engine --pt best.pt --imgsz 640
Setup. yolov12m-dualp0p3-dino3-vitb16 (107.3 M params, 14,100 GFLOPs as reported by Ultralytics), 640×640, batch 1, RTX 5080 (16 GB), torch 2.12.0+cu130, TensorRT 10.16.1.11. 30 warm-up + 200 timed iterations, CUDA-event timed with a per-iteration synchronize().
| forward only | end-to-end predict() | FPS (forward) | |
|---|---|---|---|
| TensorRT FP16 | 2.72 ms (p99 2.89) | 4.18 ms | 367 |
| PyTorch FP16 | 26.18 ms (p99 26.85) | 27.14 ms | 38 |
| PyTorch FP32 | 26.61 ms (p99 29.99) | 27.99 ms | 38 |
≈9.6× faster on the forward pass and ≈6.5× end-to-end. Stage breakdown for the engine: 1.03 pre + 2.63 infer + 0.39 post ms — once the backbone drops to 2.6 ms, letterboxing becomes ~25% of the per-image cost.
Note that PyTorch FP16 and FP32 are within noise of each other (26.2 vs 26.6 ms): in eager mode this model is not tensor-core bound, so essentially the entire speedup comes from TensorRT's kernel fusion and scheduling rather than from reduced precision.
Two numbers, not one. Forward only is the network in isolation — the honest "the engine is X ms" figure. End-to-end is Ultralytics' full path including letterbox and NMS, which is what you actually pay per image in a pipeline. Quote whichever matches your claim.
Build cost. 104 s total on the RTX 5080 (65 s of it TensorRT engine generation), producing a 209 MB engine from a 430 MB intermediate ONNX.
Numerical parity between .pt (FP32) and the FP16 engine on identical input:
| metric | value |
|---|---|
| cosine similarity (full output tensor) | 0.99988 |
| confidence correlation across 8400 anchors | 0.972 |
| box max diff, top-20 anchors by confidence | 3.6 px |
Consistent with ordinary FP16 accumulation error in the ViT. Large box differences do appear on low-confidence background anchors, but those are unconstrained during training and get discarded by NMS — compare only anchors that survive your confidence threshold, or the numbers will look alarming for no reason.
Caveat on these parity figures. They were measured on an image containing no positive detections, so they compare the two models near the noise floor rather than on confident boxes. They show the graph was exported correctly, but they are not a substitute for validating mAP on your own dataset. Before deploying, run
yolo val model=best.engine data=your_data.yaml imgsz=640and compare against the.pt.
Launch the professional Streamlit interface with advanced analytics:
# Interactive launcher with app selection
python launch_streamlit.py
# Or direct launch
streamlit run simple_streamlit_app.py --server.maxUploadSize=5000
# Open your browser and visit: http://localhost:8501
Professional Features:
Choose Streamlit Interface for:
Choose Command Line for:
This repository includes official DINOv3 integration directly from Facebook Research with advanced custom model support:
--dinoversion argument: DINOv3 is default (version=3), DINOv2 support (version=2)--dino-input parameter for ANY custom DINO model--dino-input parameter documentation--unfreeze-dinoBy default, DINO weights are FROZEN ❄️ for optimal training efficiency. Use --unfreeze-dino to make DINO weights trainable for advanced fine-tuning:
# Default behavior (Recommended) - DINO weights are FROZEN
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100
# Advanced: Make DINO weights TRAINABLE for fine-tuning
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--unfreeze-dino \
--epochs 100
| Configuration | DINO Weights | VRAM Usage | Training Speed | Best For |
|---|---|---|---|---|
| Default (Frozen) ❄️ | Fixed | 🟢 Lower | ⚡ Faster | Production, general use |
--unfreeze-dino 🔥 | Trainable | 🔴 Higher | 🐌 Slower | Research, specialized domains |
✅ Use Default (Frozen) when:
🔥 Use --unfreeze-dino when:
# 1️⃣ Single P0 Input Integration
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration single
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration single --unfreeze-dino
# 2️⃣ Dual P3+P4 Backbone Integration
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dual
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dual --unfreeze-dino
# 3️⃣ DualP0P3 P0+P3 Optimized Integration (Balanced)
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dualp0p3
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dualp0p3 --unfreeze-dino
# 4️⃣ Triple P0+P3+P4 All Levels Integration (Ultimate)
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration triple
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration triple --unfreeze-dino
# Test pure YOLOv12 (no DINO)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 5 \
--name test_pure_yolov12
# Test official DINOv3 integration
python validate_dinov3.py --test-all
# Test custom input support
python test_custom_dino_input.py
# Test local weight file loading
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-input ./my_custom_dino.pth \
--integration single \
--epochs 5 \
--name test_local_weights
# Example training with official DINOv3 single integration
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 10 \
--name test_dinov3_single
# Example training with DINOv3 dual integration
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration dual \
--epochs 10 \
--name test_dinov3_dual
# Test ViT-H+/16 distilled (840M) - Enterprise grade
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--dino-variant vith16_plus \
--integration dual \
--epochs 10 \
--batch-size 4 \
--name test_vith16_plus_enterprise
# Test ViT-7B/16 ultra (6.7B) - Research only
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--dino-variant vit7b16 \
--integration single \
--epochs 5 \
--batch-size 1 \
--name test_vit7b16_research
# Test backward compatibility with DINOv2
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dinoversion 2 \
--dino-variant vitb16 \
--integration single \
--epochs 5 \
--name test_dinov2_compatibility
Quick Fix - Choose One:
Option 1: Reduce Batch Size
# If using batch 90 → try 45
--batch-size 45
# Still NaN? → try 24
--batch-size 24
# Still NaN? → try 16
--batch-size 16
Option 2: Reduce Learning Rate
# If using lr 0.01 → try 0.005
--lr 0.005
# Still NaN? → try 0.003
--lr 0.003
# Still NaN? → try 0.001
--lr 0.001
Option 3: Both (Most Reliable)
--batch-size 24 --lr 0.005
NaN Loss = Reduce batch size by half OR reduce learning rate by half (or both)
YOLOv12-DINO3 now supports OBB detection for rotated objects - ideal for aerial imagery, document analysis, and applications where object orientation matters.
Example: OBB detection on aerial imagery showing rotated bounding boxes for ships and other objects
# Train OBB model
python trainobb.py --model yolov12m-dualp0p3 --data dota.yaml --epochs 100 --imgsz 1024
# Run inference
python inferobb.py --weights best.pt --source images/ --conf 0.25 --save-txt
| Model | CLI Name | Description |
|---|---|---|
| YOLOv12s-P0only-OBB | yolov12s-p0only | Small, P0 preprocessing |
| YOLOv12m-DualP0P3-OBB | yolov12m-dualp0p3 | Medium, balanced |
| YOLOv12l-DualP0P3-OBB | yolov12l-dualp0p3 | Large, high accuracy |
For complete OBB documentation including:
See: README_OBB.md
Made by AI Research Group, Department of Civil Engineering, KMUTT 🏛️
The code is based on ultralytics. Thanks for their excellent work!
Official DINOv3 Integration: This implementation uses official DINOv3 models directly from Meta's Facebook Research repository: facebookresearch/dinov3. The integration includes comprehensive support for all official DINOv3 variants and the innovative --dino-input parameter for custom model loading.
YOLOv12: Based on the official YOLOv12 implementation with attention-centric architecture from sunsmarterjie/yolov12.
@article{tian2025yolov12,
title={YOLOv12: Attention-Centric Real-Time Object Detectors},
author={Tian, Yunjie and Ye, Qixiang and Doermann, David},
journal={arXiv preprint arXiv:2502.12524},
year={2025}
}
@article{dinov3_yolov12_2025
title={DINOv3-YOLOv12: Systematic Vision Transformer Integration for Enhanced Object Detection},
author={AI Research Group, Department of Civil Engineering, KMUTT},
journal={GitHub Repository},
year={2024},
url={https://github.com/Sompote/DINOV3-YOLOV12}
}
@article{yolo_dino_paper_2025,
title={YOLO-DINO: YOLOv12-DINOv3 Hybrid Architecture for Data-Efficient Object Detection},
author={AI Research Group, Department of Civil Engineering, KMUTT},
journal={arXiv preprint arXiv:2510.25140},
year={2024},
url={https://arxiv.org/abs/2510.25140}
}
🚀 Revolutionizing Object Detection with Systematic Vision Transformer Integration
Made with ❤️ by the AI Research Group, Department of Civil Engineering King Mongkut's University of Technology Thonburi (KMUTT)
Python
99.5%
Use DINOv3’s powerful, self-supervised visual features + YOLOv12’s blazing-fast detection, all in one repo. Whether you have only a few hundred labeled images or a medium-sized dataset, DINOV3-YOLOV12 helps you get better detection accuracy — without sacrificing speed. Great for niche domains, small-data projects, or quick prototyping.
322
stars
339
commits
Python
primary language
Aug 16, 2026
updated
5 YOLOv12 sizes • Official DINOv3 models • 4 integration types • Input+Backbone enhancement • Single/Dual/Triple/DualP0P3 integration • 50+ model combinations
📖 Quick Start • 🎯 Model Zoo • 🛠️ Installation • 📊 Training • 🤝 Contributing
🎯 Why DINO Pre-training Matters:
📊 mAP@0.5 Performance Rankings:
| Rank | Model | Integration | DINO Variant | mAP@0.5 | Improvement | Performance Type |
|---|---|---|---|---|---|---|
| 🥇 | YOLOL-vitb16-p0p3 | dualp0p3 | vitb16 | 0.7206 | +88.6% | 🎯 Best Overall |
| 🥈 | YOLOM-vitl16-p0p3 | dualp0p3 | vitl16 | 0.6880 | +65.6% | 🚀 High Performance |
| �� | YOLOS-vitb16-triple | triple | vitb16 | 0.6816 | +68.5% | ⚡ Strong Triple |
| 4 | YOLOM-vitb16-p0p3 | dualp0p3 | vitb16 | 0.6789 | +63.4% | 🎪 Balanced |
| 5 | YOLOv12M | none | none | 0.4154 | Baseline | 📊 Base M |
| 6 | YOLOv12S | none | none | 0.4046 | Baseline | 📈 Base S |
| 7 | YOLOv12L | none | none | 0.3821 | Baseline | 📈 Base L |
| 8 | YOLOM-vitl16-single | single | vitl16 | 0.1953 | -53.0% | ⚠️ Single Only |
📈 Performance Visualization:

🎯 Key Performance Insights (KITTI Dataset):
💡 Model Selection Guide (KITTI Dataset):
🎯 Best Model Configuration for KITTI (Autonomous Driving):
# Optimal configuration for KITTI autonomous driving dataset
python train_yolov12_dino.py \
--data kitti.yaml \
--yolo-size l \
--dino-variant vitb16 \
--integration dualp0p3 \
--epochs 100 \
--batch-size 16 \
--imgsz 640 \
--name kitti_optimized
📈 KITTI Performance Analysis:
📊 mAP@0.5 Performance Rankings:
| Rank | Model | Integration | DINO Variant | mAP@0.5 | Performance Type |
|---|---|---|---|---|---|
| 🥇 | M-vitl16-dualp0p3 | dualp0p3 | vitl16 | 0.5577 | 🎯 Best Overall |
| 🥈 | S-vitb16-triple | triple | vitb16 | 0.5363 | 🚀 High Performance |
| 🥉 | M-vitb16-dualp0p3 | dualp0p3 | vitb16 | 0.5239 | ⚡ Optimal Balance |
| 4 | L-vitb16-dualp0p3 | dualp0p3 | vitb16 | 0.5308 | 🎪 Large Model |
| 5 | M-none-none | none | none | 0.5123 | 📊 Baseline M |
| 6 | S-vitb16-dual | dual | vitb16 | 0.5090 | 🔧 Stable |
| 7 | M-vitl16-single | single | vitl16 | 0.5051 | 🌟 Single Large |
| 8 | M-vitb16-single | single | vitb16 | 0.4978 | 🎯 Single Balanced |
| 9 | S-vitl16-single | single | vitl16 | 0.4965 | ⚡ Small Large |
| 10 | S-vitb16-single | single | vitb16 | 0.4920 | 🌟 Small Single |
| 12 | S-vitb16-single | single | vitb16 | 0.4914 | 🔧 Small Stable |
| 13 | YOLOv12M | none | none | 0.4904 | 📈 Standard M |
| 14 | YOLOv12S | none | none | 0.4854 | 📈 Standard S |
| 15 | S-vitl16-triple | triple | vitl16 | 0.4727 | 🎪 Small Triple |
| 16 | M-vitl16-single | single | vitl16 | 0.4645 | 🌟 Large Single |
| 17 | YOLOv12L | none | none | 0.4539 | 📈 Standard L |
📈 Performance Visualization:

🎯 Key Performance Insights (Construction PPE - Small Dataset):
💡 Model Selection Guide (Construction PPE Dataset):
🔥 Key Insights (Small Dataset Training):
🎯 Best Model Configuration for Construction PPE (Small Dataset Example):
📈 Performance Analysis:
🧠 Self-Supervised Learning Advantage:
📊 Small Dataset Training Strategy:
⚠️ Important Notes:
--integration single for datasets <2000 images--unfreeze-dino only after 20-30 epochs if performance plateaus📈 Performance Visualization:

🎯 Key Performance Insights (COCO Dataset):
💡 Model Selection Guide (COCO Dataset):
🔥 Dataset Size Impact Analysis:
| Dataset Type | Dataset Size | DINO Improvement | Best Integration | Recommendation |
|---|---|---|---|---|
| Complex (KITTI) | Medium (~7K images) | +60-88% | DualP0P3, Triple | DINO Essential |
| Small (PPE) | Small (<1K images) | +15-25% | Single, DualP0P3 | DINO Highly Recommended |
| Large (COCO) | Large (>100K images) | +2-5% | Single | DINO Optional |
💡 Key Insight:
Get started in 5 minutes! Choose your path:
# 1. Clone and setup
git clone https://github.com/Sompote/DINOV3-YOLOV12.git
cd DINOV3-YOLOV12
conda create -n dinov3-yolov12 python=3.11 -y
conda activate dinov3-yolov12
# 2. Install dependencies
pip install -r requirements.txt transformers
pip install -e .
# 3. Setup Hugging Face authentication (REQUIRED for DINOv3)
# Method 1: Environment variable (recommended)
export HUGGINGFACE_HUB_TOKEN="your_token_here"
# Get token: https://huggingface.co/settings/tokens
# Permissions: Read access to repos + public gated repos
# Method 2: Interactive login
huggingface-cli login
# Enter your token when prompted (input will be hidden)
# Token will be saved for future use
# Verify authentication
huggingface-cli whoami
# Should show your username if authenticated correctly
# 4. Quick test - Pure YOLOv12 (fastest, no DINO)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 5 \
--name quick_test
# Best for: Speed, production, baseline comparison
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 100 \
--name pure_yolov12
# Best for: Stable training, most balanced enhancement
# +3-8% mAP improvement with minimal overhead
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100 \
--name stable_enhancement
# Best for: Complex scenes, small objects
# +10-18% mAP improvement, 2x training time
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration dual \
--epochs 100 \
--batch-size 8 \
--name high_performance
# Launch web interface
python launch_streamlit.py
# Open browser: http://localhost:8501
# Upload images and pre-trained models for instant detection!
| Your Goal | Use This Command | Training Time | Memory |
|---|---|---|---|
| Fast baseline | Pure YOLOv12 (no --dino-variant) | 2hrs | 3GB |
| Balanced enhancement 🌟 | --integration single | 3hrs | 6GB |
| Maximum accuracy | --integration dual | 5hrs | 10GB |
Problem: "No validation data"
# Make sure your data.yaml has correct paths
val: valid/images # or ../valid/images
Problem: "HUGGINGFACE_HUB_TOKEN not found" or "401 Unauthorized"
# Solution 1: Environment variable
export HUGGINGFACE_HUB_TOKEN="hf_your_token_here"
# Solution 2: Interactive login (easier)
huggingface-cli login
# Enter your token and press Enter
# Verify it works
huggingface-cli whoami
# If still failing, get a new token:
# 1. Visit: https://huggingface.co/settings/tokens
# 2. Create new token with permissions:
# - Read access to repos
# - Read access to public gated repos
Problem: "NaN loss"
# Reduce batch size and learning rate
--batch-size 16 --lr 0.005
2025/10/13: NEW: --pretrainyolo option seeds dualp0p3 runs with YOLO backbone weights (P4+) while leaving the DINO P0–P3 pipeline fresh—ideal for quick starts on custom datasets.
2025/10/03: 🎯 MAJOR: EXACT Training State Restoration - Revolutionary enhancement to train_resume.py! Now provides perfect training continuity with exact state restoration. Training resumes with identical loss values (no more 4x spikes), exact learning rate (0.00012475 vs old 0.01 shock), and all 61 hyperparameters automatically extracted. Solves the "training starts from scratch" problem completely. Real-world tested: User's checkpoint resumed seamlessly with box_loss: 0.865870, cls_loss: 0.815450 - exactly as expected. Just run: python train_resume.py --checkpoint /path/to/checkpoint.pt --epochs 400
2025/09/29: 🎯 NEW: DualP0P3 Integration - Added new --integration dualp0p3 option combining P0 input preprocessing with P3 backbone enhancement! This optimized dual integration provides balanced performance with moderate computational cost (~6GB VRAM, 1.5x training time) while delivering +8-15% mAP improvement. Perfect for users who want enhanced performance without the full computational overhead of triple integration. Architecture: Input → DINO3Preprocessor → YOLOv12 → DINO3(P3) → Head.
2025/09/27: 🎉 BREAKTHROUGH: Local Weight File Support FULLY WORKING - Successfully implemented and tested --dino-input /path/to/weights.pth for loading custom DINO weight files! Major fixes: Fixed TypeError in config path resolution, proper YAML file path quoting, DetectionModel object handling, channel dimension compatibility, and A2C2f architecture support. Real-world tested with user's custom weight file - training starts successfully. Local .pth, .pt, and .safetensors files now fully supported with automatic architecture inference.
2025/09/26: 🔄 REVISED: Integration Logic & Enforcement - Updated --integration option meanings for better user understanding: single = P0 input preprocessing only, dual = P3+P4 backbone integration, triple = P0+P3+P4 all levels. IMPORTANT: --integration is now REQUIRED when using DINO enhancement. Pure YOLOv12 training requires no DINO arguments.
2025/09/14: 🚀 NEW: Complete DINOv3-YOLOv12 Integration - Added comprehensive integration with official DINOv3 models from Facebook Research! Features systematic architecture with 40+ model combinations, 3 integration approaches (Single P0, Dual P3+P4, Triple P0+P3+P4), and support for all model sizes (n,s,l,x). Now includes --dino-input parameter for custom models and 100% test success rate across all variants.
2025/02/19: arXiv version is public. Demo is available.
YOLOv12 surpasses all popular real-time object detectors in accuracy with competitive speed. For example, YOLOv12-N achieves 40.6% mAP with an inference latency of 1.64 ms on a T4 GPU, outperforming advanced YOLOv10-N / YOLOv11-N by 2.1%/1.2% mAP with a comparable speed. This advantage extends to other model scales. YOLOv12 also surpasses end-to-end real-time detectors that improve DETR, such as RT-DETR / RT-DETRv2: YOLOv12-S beats RT-DETR-R18 / RT-DETRv2-R18 while running 42% faster, using only 36% of the computation and 45% of the parameters.
🚀 Systematic Architecture
|
🌟 Advanced Features
|
| Category | Option | Type | Default | Description | Example |
|---|---|---|---|---|---|
| Core Model | --data | str | Required | Dataset YAML file | --data coco.yaml |
--yolo-size | str | Required | YOLOv12 size (n,s,m,l,x) | --yolo-size s | |
--epochs | int | None | Training epochs | --epochs 100 | |
--batch-size | int | None | Batch size | --batch-size 16 | |
--device | str | '0' | GPU device | --device cpu | |
| DINOv3 Integration | --dinoversion | str | '3' | DINO version (2,3) | --dinoversion 3 |
--dino-variant | str | None | DINO model variant | --dino-variant vitb16 | |
--integration | str | None | Integration type | --integration single | |
--dino-input | str | None | Custom DINO model path | --dino-input ./model.pth | |
--unfreeze-dino | flag | False | Make DINO weights trainable | --unfreeze-dino | |
| Pretraining | --pretrain | str | None | Resume full YOLO checkpoint (architecture + optimizer) | --pretrain runs/detect/exp/weights/last.pt |
--pretrainyolo | str | None | Seed dualp0p3 P4+ layers from a base YOLO weight file | --pretrainyolo yolov12l.pt | |
| Evaluation | --fitness | float | 0.1 | Weight on mAP@0.5 for best-model fitness (1-weight applied to mAP@0.5:0.95) | --fitness 0.5 |
| Training Control | --lr | float | 0.01 | Learning rate | --lr 0.005 |
--lrf | float | 0.01 | Final learning rate | --lrf 0.1 | |
--optimizer | str | 'SGD' | Optimizer (SGD,Adam,AdamW) | --optimizer AdamW | |
--patience | int | 100 | Early stopping patience | --patience 50 | |
--amp | flag | False | Automatic mixed precision | --amp | |
--cos-lr | flag | False | Cosine learning rate | --cos-lr | |
| Data Augmentation | --mosaic | float | 1.0 | Mosaic augmentation | --mosaic 0.8 |
--mixup | float | 0.05 | Mixup augmentation | --mixup 0.2 | |
--scale | float | 0.9 | Scale augmentation | --scale 0.8 | |
--degrees | float | 0.0 | Rotation degrees | --degrees 10 | |
--translate | float | 0.1 | Translation | --translate 0.2 | |
--fliplr | float | 0.5 | Horizontal flip | --fliplr 0.6 | |
| Evaluation & Results | --eval-test | flag | True | Evaluate on test data | --eval-test |
--eval-val | flag | True | Evaluate on validation data | --eval-val | |
--detailed-results | flag | True | Show detailed mAP summary | --detailed-results | |
--save-results-table | flag | False | Save results as markdown table | --save-results-table | |
| System & Output | --workers | int | 8 | Dataloader workers | --workers 16 |
--name | str | None | Experiment name | --name my_experiment | |
--project | str | 'runs/detect' | Project directory | --project results/ | |
--seed | int | 0 | Random seed | --seed 42 |
Pretrain Flags:
--pretrainresumes an existing YOLO/DINO checkpoint end‑to‑end, while--pretrainyologives new dualp0p3 runs a YOLO backbone head start without touching the DINO-enhanced front half. Fitness Flag:--fitnesscontrols how best-model selection balances mAP@0.5 vs. mAP@0.5:0.95 (e.g.,--fitness 0.5weights them equally).
The enhanced training system now provides comprehensive mAP results in a structured format:
================================================================================
📊 TRAINING COMPLETE - COMPREHENSIVE mAP RESULTS SUMMARY
================================================================================
🏆 BEST MODEL - VALIDATION DATA:
mAP@0.5 : 0.7250
mAP@0.75 : 0.4830
mAP@0.5:0.95 : 0.5120
🧪 BEST MODEL - TEST DATA:
mAP@0.5 : 0.7180
mAP@0.75 : 0.4750
mAP@0.5:0.95 : 0.5050
📋 COMPARISON SUMMARY:
Best mAP@0.5 : 0.7250 (Best Model on Validation Data)
Best mAP@0.5:0.95 : 0.5120 (Best Model on Validation Data)
================================================================================
| Integration Type | Architecture | DINO Enhancement Points | Memory | Speed | mAP Gain | Best For |
|---|---|---|---|---|---|---|
| None (Pure YOLOv12) | Standard CNN | None | 3GB | ⚡ Fastest | Baseline | Speed-critical apps |
| Single (P0 Input) | Input → DINO3 → YOLOv12 | P0 (input preprocessing) | 6GB | 🌟 Fast | +3-8% | Most stable, general use |
| Dual (P3+P4 Backbone) | YOLOv12 → DINO3(P3,P4) → Head | P3 (80×80) + P4 (40×40) | 10GB | ⚡ Medium | +10-18% | Complex scenes, small objects |
| DualP0P3 (Optimized) | DINO3(P0) → YOLOv12 → DINO3(P3) | P0 (input) + P3 (80×80) | 8GB | 🎯 Balanced | +8-15% | Balanced performance |
| Triple (All Levels) | DINO3(P0) → YOLOv12 → DINO3(P3,P4) | P0 + P3 (80×80) + P4 (40×40) | 12GB | 🚀 Slower | +15-25% | Maximum enhancement |
| DINO Variant | Parameters | Embed Dim | Memory | Speed | Architecture | Best For |
|---|---|---|---|---|---|---|
| vits16 | 21M | 384 | 4GB | ⚡ Fastest | ViT-Small/16 | Development, prototyping |
| vitb16 | 86M | 768 | 8GB | 🎯 Balanced | ViT-Base/16 | Recommended for production |
| vitl16 | 300M | 1024 | 14GB | 🏋️ Medium | ViT-Large/16 | High accuracy research |
| vith16_plus | 840M | 1280 | 32GB | 🐌 Slow | ViT-Huge+/16 Distilled | Enterprise, specialized |
| vit7b16 | 6.7B | 4096 | 100GB+ | ⚠️ Very Slow | ViT-7B/16 Ultra | Research only |
| convnext_tiny | 29M | 768 | 4GB | ⚡ Fast | CNN-ViT Hybrid | Lightweight hybrid |
| convnext_small | 50M | 768 | 6GB | 🎯 Balanced | CNN-ViT Hybrid | Hybrid choice |
| convnext_base | 89M | 1024 | 8GB | 🏋️ Medium | CNN-ViT Hybrid | Production hybrid |
| convnext_large | 198M | 1536 | 16GB | 🐌 Slow | CNN-ViT Hybrid | Maximum hybrid |
| Use Case | Integration | DINO Variant | Command Template | Memory | Time | Best For |
|---|---|---|---|---|---|---|
| Quick Test | None | None | --yolo-size s --epochs 5 --name test | 3GB | 10min | Development |
| Pure YOLOv12 | None | None | --yolo-size s --epochs 100 | 3GB | 2hrs | Baseline comparison |
| DINO Single ViT-B | single | vitb16 | --yolo-size s --dino-variant vitb16 --integration single --epochs 100 | 6GB | 3hrs | Most stable enhancement |
| DINO Single ViT-S | single | vits16 | --yolo-size s --dino-variant vits16 --integration single --epochs 100 | 4GB | 2.5hrs | Lightweight enhancement |
| DINO Dual ViT-B | dual | vitb16 | --yolo-size s --dino-variant vitb16 --integration dual --epochs 100 | 10GB | 5hrs | High performance |
| DINO DualP0P3 | dualp0p3 | vitb16 | --yolo-size m --dino-variant vitb16 --integration dualp0p3 --epochs 100 | 8GB | 4hrs | Balanced enhancement |
| DINO Triple | triple | vitb16 | --yolo-size l --dino-variant vitb16 --integration triple --epochs 100 | 12GB | 8hrs | Maximum enhancement |
| ConvNeXt Hybrid | single | convnext_base | --yolo-size s --dino-variant convnext_base --integration single --epochs 100 | 8GB | 3.5hrs | CNN-ViT hybrid |
| Enterprise ViT-H+ | dual | vith16_plus | --yolo-size l --dino-variant vith16_plus --integration dual --epochs 200 | 32GB | 20hrs | Enterprise grade |
| Research ViT-7B | single | vit7b16 | --yolo-size l --dino-variant vit7b16 --integration single --epochs 50 | 100GB+ | 40hrs+ | Research only |
| Custom Model | single | Custom | --yolo-size l --dino-input ./model.pth --integration single --epochs 100 | 8GB | 4hrs | Domain-specific |
| Production Large | dual | vitl16 | --yolo-size l --dino-variant vitl16 --integration dual --epochs 300 --amp | 16GB | 12hrs | Maximum quality |
Comprehensive technical architecture showing internal components, data flow, and feature processing pipeline for YOLOv12 + DINOv3 integration
YOLOv12 + DINOv3 Integration - Enhanced object detection with Vision Transformers. This implementation provides four distinct integration approaches for maximum flexibility:
Input Image → DINO3Preprocessor → Original YOLOv12 → Output
--dinoversion 3 --dino-variant vitb16 --integration singleInput → YOLOv12 → DINO3(P3) → YOLOv12 → DINO3(P4) → Head → Output
--dinoversion 3 --dino-variant vitb16 --integration dualInput → DINO3Preprocessor → YOLOv12 → DINO3(P3) → Head → Output
--dinoversion 3 --dino-variant vitb16 --integration dualp0p3Input → DINO3Preprocessor → YOLOv12 → DINO3(P3) → DINO3(P4) → Head → Output
--dinoversion 3 --dino-variant vitb16 --integration tripleOur systematic approach follows a clear pattern:
yolov12{size}-dino{version}-{variant}-{integration}.yaml
Components:
{size}: YOLOv12 size → n (nano), s (small), m (medium), l (large), x (extra large){version}: DINO version → 3 (DINOv3){variant}: DINO model variant → vitb16, convnext_base, vitl16, etc.{integration}: Integration type → single (P0 input), dual (P3+P4 backbone), dualp0p3 (P0+P3 optimized), triple (P0+P3+P4 all levels)| Model | YOLOv12 Size | DINO Backbone | Integration | Parameters | Speed | Use Case | Best For |
|---|---|---|---|---|---|---|---|
| 🚀 yolov12n | Nano | Standard CNN | None | 2.5M | ⚡ Fastest | Ultra-lightweight | Embedded systems |
| 🌟 yolov12s-dino3-vitb16-single | Small + ViT-B/16 | Single (P0 Input) | 95M | 🌟 Stable | Input Preprocessing | Most Stable | |
| ⚡ yolov12s-dino3-vitb16-dual | Small + ViT-B/16 | Dual (P3+P4) | 95M | ⚡ Efficient | Backbone Enhancement | High Performance | |
| 🎯 yolov12s-dino3-vitb16-dualp0p3 | Small + ViT-B/16 | DualP0P3 (P0+P3) | 95M | 🎯 Optimized | Targeted Enhancement | Balanced Performance | |
| 🚀 yolov12s-dino3-vitb16-triple | Small + ViT-B/16 | Triple (P0+P3+P4) | 95M | 🚀 Ultimate | Full Integration | Maximum Enhancement | |
| 🏋️ yolov12l | Large | Standard CNN | None | 26.5M | 🏋️ Medium | High accuracy CNN | Production systems |
| 🎯 yolov12l-dino3-vitl16-dual | Large + ViT-L/16 | Dual (P3+P4) | 327M | 🎯 Maximum | Complex scenes | Research/High-end |
--dinoversion 3 --dino-variant vitb16 --integration single--dinoversion 3 --dino-variant vitb16 --integration dual--dinoversion 3 --dino-variant vitb16 --integration dualp0p3--dinoversion 3 --dino-variant vitb16 --integration triple| Model | YOLOv12 Size | Parameters | Memory | Speed | mAP@0.5 | Status |
|---|---|---|---|---|---|---|
yolov12n | Nano | 2.5M | 2GB | ⚡ 1.60ms | 40.4% | ✅ Working |
yolov12s | Small | 9.1M | 3GB | ⚡ 2.42ms | 47.6% | ✅ Working |
yolov12m | Medium | 19.6M | 4GB | 🎯 4.27ms | 52.5% | ✅ Working |
yolov12l | Large | 26.5M | 5GB | 🏋️ 5.83ms | 53.8% | ✅ Working |
yolov12x | XLarge | 59.3M | 7GB | 🏆 10.38ms | 55.4% | ✅ Working |
| Systematic Name | YOLOv12 + DINOv3 | Parameters | Memory | mAP Improvement | Status |
|---|---|---|---|---|---|
yolov12n-dino3-vits16-single | Nano + ViT-S | 23M | 4GB | +5-8% | ✅ Working |
yolov12s-dino3-vitb16-single | Small + ViT-B | 95M | 8GB | +7-11% | ✅ Working |
yolov12l-dino3-vitl16-single | Large + ViT-L | 327M | 14GB | +8-13% | ✅ Working |
yolov12l-dino3-vitl16-dual | Large + ViT-L Dual | 327M | 16GB | +10-15% | ✅ Working |
yolov12x-dino3-vith16_plus-single | XLarge + ViT-H+ | 900M | 32GB | +12-18% | ✅ Working |
| Systematic Name | DINOv3 ConvNeXt | Parameters | Architecture | mAP Improvement |
|---|---|---|---|---|
yolov12s-dino3-convnext_small-single | ConvNeXt-Small | 59M | CNN-ViT Hybrid | +6-9% |
yolov12m-dino3-convnext_base-single | ConvNeXt-Base | 109M | CNN-ViT Hybrid | +7-11% |
yolov12l-dino3-convnext_large-single | ConvNeXt-Large | 225M | CNN-ViT Hybrid | +9-13% |
🔥 Key Advantage: Combines CNN efficiency with Vision Transformer representational power
| Variant | Parameters | Embed Dim | Memory | Speed | Use Case | Recommended For |
|---|---|---|---|---|---|---|
dinov3_vits16 | 21M | 384 | ~4GB | ⚡ Fastest | Development, mobile | Prototyping, edge devices |
dinov3_vitb16 | 86M | 768 | ~8GB | 🎯 Balanced | Recommended | General purpose, production |
dinov3_vitl16 | 300M | 1024 | ~14GB | 🏋️ Slower | High accuracy | Research, complex scenes |
dinov3_vith16_plus | 840M | 1280 | ~32GB | 🐌 Slowest | Maximum performance | Enterprise, specialized |
dinov3_vit7b16 | 6.7B | 4096 | >100GB | ⚠️ Experimental | Ultra-high-end | Research only |
ViT-H+/16 Distilled (840M Parameters)
--dino-variant vith16_plus --integration single/dual/tripleViT-7B/16 Ultra (6.7B Parameters)
--dino-variant vit7b16 --integration single/dual/triple| Variant | Parameters | Embed Dim | Memory | Speed | Use Case | Recommended For |
|---|---|---|---|---|---|---|
dinov3_convnext_tiny | 29M | 768 | ~4GB | ⚡ Fast | Lightweight hybrid | Efficient deployments |
dinov3_convnext_small | 50M | 768 | ~6GB | 🎯 Balanced | Hybrid choice | CNN+ViT benefits |
dinov3_convnext_base | 89M | 1024 | ~8GB | 🏋️ Medium | Robust hybrid | Production hybrid |
dinov3_convnext_large | 198M | 1536 | ~16GB | 🐌 Slower | Maximum hybrid | Research hybrid |
For Beginners:
dinov3_vitb16 (most balanced)dinov3_vits16 for faster developmentFor Production:
dinov3_vitb16 for general use (recommended)dinov3_convnext_base for CNN-ViT hybrid approachFor Research:
dinov3_vitl16 for maximum accuracy (14GB VRAM)dinov3_vith16_plus for cutting-edge performance (32GB VRAM)dinov3_vit7b16 for experimental ultra-high-end research (100GB+ VRAM)Memory Constraints:
dinov3_vits16, dinov3_convnext_tinydinov3_vitb16, dinov3_convnext_basedinov3_vitl16dinov3_vith16_plus (ViT-H+/16 Distilled 840M)100GB VRAM:
dinov3_vit7b16(ViT-7B/16 Ultra 6.7B)
# Lightweight development (4GB VRAM)
--dinoversion 3 --dino-variant vits16
# Recommended production (8GB VRAM)
--dinoversion 3 --dino-variant vitb16
# High accuracy research (14GB+ VRAM)
--dinoversion 3 --dino-variant vitl16
# Ultra-high performance (32GB+ VRAM) - ViT-H+/16 Distilled
--dinoversion 3 --dino-variant vith16_plus
# Experimental research (100GB+ VRAM) - ViT-7B/16 Ultra
--dinoversion 3 --dino-variant vit7b16
# Hybrid CNN-ViT approach (8GB VRAM)
--dinoversion 3 --dino-variant convnext_base
🔥 Most Popular Choices:
dinov3_vitb16 # ⭐ RECOMMENDED: Best balance (86M params, 8GB VRAM)
dinov3_vits16 # ⚡ FASTEST: Development & prototyping (21M params, 4GB VRAM)
dinov3_vitl16 # 🎯 HIGHEST ACCURACY: Research use (300M params, 14GB VRAM)
dinov3_convnext_base # 🧠 HYBRID: CNN+ViT fusion (89M params, 8GB VRAM)
💡 Pro Tip: Start with dinov3_vitb16 for best results, then scale up/down based on your needs!
--dinoversion Argument - DINOv3 is Default🔥 Important Update: The training script now uses --dinoversion instead of --dino-version:
# NEW ARGUMENT: --dinoversion with DINOv3 as DEFAULT
--dinoversion 3 # DINOv3 (DEFAULT) - Latest Vision Transformer models
--dinoversion 2 # DINOv2 (Legacy) - For backward compatibility
Key Features:
--dinoversion 3 if not specified--dino-version to --dinoversion--dinoversion 2# 🚀 PURE YOLOv12 (No DINO) - Fast & Lightweight
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 100 \
--name pure_yolov12
# 🌟 SINGLE INTEGRATION (P0 Input) - Most Stable & Recommended
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100 \
--batch-size 16 \
--name stable_p0_preprocessing
# 🎪 DUAL INTEGRATION (P3+P4 Backbone) - High Performance
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration dual \
--epochs 100 \
--batch-size 16 \
--name high_performance_p3p4
# 🎯 DUALP0P3 INTEGRATION (P0+P3 Optimized) - Balanced Performance
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size m \
--dino-variant vitb16 \
--integration dualp0p3 \
--epochs 100 \
--batch-size 12 \
--name optimized_p0p3
# 🚀 TRIPLE INTEGRATION (P0+P3+P4 All Levels) - Maximum Enhancement
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--dino-variant vitb16 \
--integration triple \
--epochs 100 \
--batch-size 8 \
--name ultimate_p0p3p4
# ❌ WRONG: DINO variant without integration (will fail)
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16
# ✅ CORRECT: DINO variant with integration
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration single
# ✅ CORRECT: Pure YOLOv12 (no DINO arguments needed)
python train_yolov12_dino.py --data data.yaml --yolo-size s
| Model Type | Command Parameters | DINO Version | Best For |
|---|---|---|---|
| Pure YOLOv12 🚀 | --yolo-size s (no DINO arguments) | None | Fast training, lightweight, production |
| Single (P0 Input) 🌟 | --dino-variant vitb16 --integration single | DINOv3 (auto) | Most stable, input preprocessing |
| Dual (P3+P4 Backbone) 🎪 | --dino-variant vitb16 --integration dual | DINOv3 (auto) | High performance, multi-scale backbone |
| DualP0P3 (P0+P3 Optimized) 🎯 | --dino-variant vitb16 --integration dualp0p3 | DINOv3 (auto) | Balanced performance, targeted enhancement |
| Triple (P0+P3+P4 All) 🚀 | --dino-variant vitb16 --integration triple | DINOv3 (auto) | Maximum enhancement, all levels |
| Legacy Support 🔄 | --dinoversion 2 --dino-variant vitb16 --integration single | DINOv2 (explicit) | Existing workflows |
--dino-input vs --pretrainClear distinction between DINO model loading and checkpoint resuming:
--dino-input: Custom DINO Models for EnhancementUse --dino-input to load custom DINO models for backbone enhancement. Supports two methods:
Download and use Meta's official DINOv3 pretrained weights:
| Model | Parameters | Download Link | File Size |
|---|---|---|---|
| ViT-S/16 | 21M | dinov3_vits16_pretrain.pth | ~84 MB |
| ViT-B/16 | 86M | dinov3_vitb16_pretrain.pth | ~343 MB |
| ViT-L/16 | 300M | dinov3_vitl16_pretrain.pth | ~1.2 GB |
| ViT-L/16 (SAT) | 300M | dinov3_vitl16_pretrain_sat493m.pth | ~1.2 GB |
Download and use:
# Download Meta's official weights
mkdir -p dinov3/weights && cd dinov3/weights
wget https://dl.fbaipublicfiles.com/dinov3/dinov3_vitb16_pretrain.pth
# 🏗️ Single Integration with Meta's Official Weights (P0 Input)
python train_yolov12_dino.py \
--data /path/to/your/data.yaml \
--yolo-size s \
--dino-input dinov3/weights/dinov3_vitb16_pretrain.pth \
--integration single \
--epochs 100 \
--name meta_weights_single
# 🎪 Dual Integration with Satellite-trained Weights (P3+P4 Backbone)
python train_yolov12_dino.py \
--data kitti.yaml \
--yolo-size l \
--dino-input dinov3/weights/dinov3_vitl16_pretrain_sat493m.pth \
--integration dual \
--epochs 200 \
--name satellite_weights_dual
Use your domain-specific fine-tuned DINOv3 models:
# Use custom fine-tuned DINO weights for medical imaging
python train_yolov12_dino.py \
--data medical_dataset.yaml \
--yolo-size m \
--dino-input /path/to/my_medical_finetuned_dinov3.pth \
--integration dualp0p3 \
--epochs 150 \
--name medical_custom_weights
# Use fine-tuned weights for aerial imagery
python train_yolov12_dino.py \
--data aerial_dataset.yaml \
--yolo-size l \
--dino-input /path/to/aerial_finetuned_dino.pt \
--integration triple \
--epochs 200 \
--name aerial_custom_weights
Supported file formats:
.pth - PyTorch checkpoint file.pt - PyTorch model file.safetensors - Safe tensors formatOr let the system auto-download from HuggingFace:
# Auto-download from HuggingFace using variant name
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100 \
--name huggingface_auto
💡 When to use each method:
--pretrain: Resume Training from YOLO CheckpointsUse --pretrain to load pretrained YOLO checkpoints for continuing training:
# ✅ Resume training from a YOLO checkpoint
python train_yolov12_dino.py \
--data /path/to/your/data.yaml \
--yolo-size l \
--pretrain /path/to/your/last.pt \
--integration triple \
--epochs 400 \
--name cont_training
# ✅ Continue training with different configuration
python train_yolov12_dino.py \
--data /path/to/your/data.yaml \
--yolo-size l \
--pretrain /Users/Downloads/checkpoint.pt \
--epochs 200 \
--batch-size 8 \
--name resumed_training
train_resume.pyUse the enhanced train_resume.py script for EXACT training state restoration - training continues exactly where it left off:
# ✅ RECOMMENDED: Perfect state restoration (resumes with exact same loss values)
python train_resume.py \
--checkpoint /path/to/your/checkpoint.pt \
--epochs 400 \
--device 0,1
# ✅ Resume with different dataset (keeps all other settings identical)
python train_resume.py \
--checkpoint /workspace/DINOV3-YOLOV12/runs/detect/high_performance_p3p46/weights/last.pt \
--data coco.yaml \
--epochs 200 \
--batch-size 32 \
--name resumed_training \
--device 0,1
# ✅ Resume for fine-tuning (only change specific parameters)
python train_resume.py \
--checkpoint /Users/model_weight/diloyolo12_coco/last-2.pt \
--epochs 100 \
--unfreeze-dino \
--name fine_tuned_training
🎯 ENHANCED Features of train_resume.py (v2.0):
For manual control, you can still use the main training script, but you MUST specify the same DINO configuration:
# ✅ Resume DINO training - specify DINO arguments to match checkpoint
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--pretrain /workspace/DINOV3-YOLOV12/runs/detect/high_performance_p3p46/weights/last.pt \
--dinoversion 3 \
--dino-variant vitb16 \
--integration triple \
--epochs 400 \
--batch-size 60 \
--name cont_p3p4 \
--device 0,1
# ❌ WRONG - will cause architecture mismatch
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--pretrain /path/to/dino_checkpoint.pt \
--epochs 400
# Missing DINO arguments causes pure YOLOv12 mode
⚠️ Important: When using the legacy method, always include the original DINO configuration (--dinoversion, --dino-variant, --integration) to prevent architecture conflicts.
The enhanced train_resume.py provides perfect training continuity by restoring the exact training state:
🎯 RESTORING EXACT TRAINING STATE
============================================================
📊 Complete Training State Extracted:
Last Epoch: 199
Best Fitness: 0.699
Training Updates: 50000
Final Learning Rate: 0.00012475
Expected Loss Values (training should start with these):
box_loss: 0.865870
cls_loss: 0.815450
dfl_loss: 1.100720
🔧 EXTRACTING ALL HYPERPARAMETERS FROM CHECKPOINT
✅ Extracted 61 hyperparameters from checkpoint
📈 EXACT LEARNING RATE RESTORATION:
Original lr0: 0.01
Final training LR: 0.00012475
Resume LR: 0.00012475 (EXACT same as last step)
🎯 Training will continue from EXACT same state!
| Aspect | ❌ Before (Problem) | ✅ After (Enhanced) |
|---|---|---|
| Loss Values | 4x higher (3.66 vs 0.866) | Identical (0.866 → 0.866) |
| Learning Rate | Reset to 0.01 (80x shock) | Exact (0.00012475) |
| Training State | "Starting from scratch" | Perfect continuity |
| Hyperparameters | Default values used | All 61 extracted |
| User Experience | Frustrating loss spikes | Seamless resumption |
| Method | Auto-Detection | State Restoration | Data Required | DINO Config Required | Best For |
|---|---|---|---|---|---|
train_resume.py ✅ | Full auto | EXACT | ❌ No | ❌ No | Recommended - Perfect Continuity |
train_yolov12_dino.py --pretrain | Manual | Partial | ✅ Yes | ✅ Yes | Manual control & custom settings |
# Just provide checkpoint - everything else is automatic!
python train_resume.py --checkpoint /path/to/checkpoint.pt --epochs 400 --device 0,1
🎯 EXACT STATE RESTORATION:
Final Learning Rate: 0.00012475
Expected Loss Values:
box_loss: 0.865870 ← Training starts HERE (not 4x higher!)
cls_loss: 0.815450
dfl_loss: 1.100720
✅ Extracted 61 hyperparameters from checkpoint
🎯 Training will continue from EXACT same state!
| Parameter | Purpose | Input Type | Use Case |
|---|---|---|---|
--dino-input | Load custom DINO models | DINO backbone weights (.pth, .pt) | Enhanced vision features |
--pretrain | Resume YOLO training | YOLO checkpoint (.pt) | Continue training from checkpoint |
--pretrainyolo | Inject base YOLO weights into dualp0p3 models | YOLO backbone weights (.pt) | Start dualp0p3 runs with P4+ YOLO initialization |
Note:
--pretrainyolois optimized for thedualp0p3integration (YOLOv12-L). The script automatically copies weights from layer P4 onward while keeping the DINO-enhanced P0–P3 pipeline untouched. It’s ideal when you want a YOLO foundation but still train the DINO front end from scratch.
# DualP0P3 with partial YOLO pretraining (recommended for crack datasets)
python train_yolov12_dino.py \
--data crack.yaml \
--yolo-size l \
--dinoversion 3 \
--dino-variant vitb16 \
--integration dualp0p3 \
--pretrainyolo yolov12l.pt \
--epochs 200 \
--batch-size 8
# Standard ViT models with --dino-variant (alternative to --dino-input)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dinoversion 3 \
--dino-variant vitb16 \
--integration single \
--epochs 100
# PyTorch checkpoint files
--dino-input /path/to/your/custom_dino_model.pth
--dino-input ./fine_tuned_dino.pt
--dino-input /models/specialized_dino.safetensors
--dino-input ~/Downloads/pretrained_dino_weights.pth
# Official Facebook Research models
--dino-input facebook/dinov3-vitb16-pretrain-lvd1689m
--dino-input facebook/dinov2-base
--dino-input facebook/dinov3-vit7b16-pretrain-lvd1689m
# Custom organization models
--dino-input your-org/custom-dino-variant
--dino-input company/domain-specific-dino
# Simplified shortcuts (auto-converted)
--dino-input vitb16 # → dinov3_vitb16
--dino-input convnext_base # → dinov3_convnext_base
--dino-input vith16_plus # → dinov3_vith16_plus
--dino-input vit7b16 # → dinov3_vit7b16
✅ Smart Format Detection:
.pth, .pt, .safetensors formatsstate_dict, model, model_state_dict)✅ Architecture Inference:
✅ Channel Compatibility:
✅ Robust Error Handling:
# Example 1: Domain-specific trained DINO for crack detection
python train_yolov12_dino.py \
--data crack_dataset.yaml \
--yolo-size l \
--dino-input /models/crack_detection_dino.pth \
--integration dual \
--epochs 200 \
--name crack_dino_yolo
# Example 2: Medical imaging DINO with triple integration
python train_yolov12_dino.py \
--data medical_scans.yaml \
--yolo-size x \
--dino-input ./medical_dino_weights.safetensors \
--integration triple \
--epochs 300 \
--name medical_triple_dino
# Example 3: Industrial defect detection with custom model
python train_yolov12_dino.py \
--data defect_data.yaml \
--yolo-size l \
--dino-input /weights/defect_specialized_dino.pt \
--integration dual \
--epochs 150 \
--unfreeze-dino \
--name industrial_defect_detection
| Feature | Status | Description |
|---|---|---|
| Local .pth files | ✅ WORKING | Tested with real user weight files |
| Local .pt files | ✅ WORKING | Full PyTorch checkpoint support |
| Local .safetensors | ✅ WORKING | HuggingFace safetensors format |
| YAML config generation | ✅ FIXED | Properly quoted file paths |
| Channel dimension matching | ✅ FIXED | Automatic YOLOv12 compatibility |
| DetectionModel handling | ✅ FIXED | Handles full model objects |
| Architecture inference | ✅ WORKING | Auto-detects embedding dimensions |
| All integration types | ✅ TESTED | Single, dual, triple all working |
✅ Tested & Confirmed:
📖 Complete Guide: See Custom Input Documentation for detailed examples and troubleshooting.
# 1. Clone the repository
git clone https://github.com/Sompote/DINOV3-YOLOV12.git
cd DINOV3-YOLOV12
# 2. Create conda environment
conda create -n dinov3-yolov12 python=3.11
conda activate dinov3-yolov12
# 3. Install dependencies
pip install -r requirements.txt
pip install transformers # For DINOv3 models
pip install -r requirements_streamlit.txt # For Streamlit web interface
pip install -e .
# 4. Setup Hugging Face authentication (REQUIRED for DINOv3 models)
export HUGGINGFACE_HUB_TOKEN="your_token_here"
# Get your token from: https://huggingface.co/settings/tokens
# Required permissions when creating token:
# - Read access to contents of all repos under your personal namespace
# - Read access to contents of all public gated repos you can access
# Alternative: hf auth login
# 5. Verify installation
python -c "from ultralytics.nn.modules.block import DINO3Backbone; print('✅ DINOv3-YOLOv12 ready!')"
# 6. Quick test (recommended)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-input dinov3_vitb16 \
--integration single \
--epochs 1 \
--name quick_test
# 7. Test Streamlit web interface (optional)
python launch_streamlit.py
# 8. Try pre-trained Construction-PPE model (optional)
wget https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r -O construction_ppe_best.pt
python inference.py --weights construction_ppe_best.pt --source your_image.jpg --save
# For experienced users - complete setup and test in one go
git clone https://github.com/Sompote/DINOV3-YOLOV12.git && \
cd DINOV3-YOLOV12 && \
conda create -n dinov3-yolov12 python=3.11 -y && \
conda activate dinov3-yolov12 && \
pip install -r requirements.txt transformers && \
pip install -e . && \
echo "⚠️ IMPORTANT: Set your Hugging Face token before training:" && \
echo "export HUGGINGFACE_HUB_TOKEN=\"your_token_here\"" && \
echo "Get token from: https://huggingface.co/settings/tokens" && \
echo "Required permissions: Read access to repos + public gated repos" && \
echo "✅ Setup complete! Run: python train_yolov12_dino.py --help"
DINOv3 models from Facebook Research are hosted on Hugging Face as gated repositories, requiring authentication to access.
Create Hugging Face Account: Visit huggingface.co and sign up
Generate Access Token:
Set Required Permissions:
Repositories:
✅ Read access to contents of all repos under your personal namespace
✅ Read access to contents of all public gated repos you can access
Apply Token:
# Method 1: Environment variable (recommended) ✅ FULLY SUPPORTED
export HUGGINGFACE_HUB_TOKEN="hf_your_token_here"
# The training script automatically detects and uses this token
# Method 2: Login command (interactive)
hf auth login
# Follow the interactive prompts:
# - Enter your token (input will not be visible)
# - Choose to add token as git credential (Y/n)
# - Token validation will be confirmed
✅ Token Detection: The training script will show:
Using HUGGINGFACE_HUB_TOKEN: hf_xxxx...
If your token is properly detected.
Verify Access:
hf whoami
# Should show your username if authenticated correctly
wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.3/flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
conda create -n yolov12 python=3.11
conda activate yolov12
pip install -r requirements.txt
pip install transformers # For DINOv3 models
pip install -e .
# Test DINOv3 integration
python -c "from ultralytics.nn.modules.block import DINO3Backbone; print('✅ DINOv3 ready!')"
# Test training script
python train_yolov12_dino.py --help
# Quick functionality test
python test_yolov12l_dual.py
If you have an RTX 5090 GPU, you may encounter CUDA compatibility issues. See RTX 5090 Compatibility Guide for solutions.
Quick Fix for RTX 5090:
# Install PyTorch nightly with RTX 5090 support
pip uninstall torch torchvision -y
pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu121
# Verify RTX 5090 compatibility
python -c "import torch; print(f'✅ GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"No CUDA\"}')"
We provide a specialized YOLOv12-DINO model trained on the Construction-PPE dataset from Ultralytics 8.3.197, optimized for detecting safety equipment on construction sites. This model demonstrates the power of DINO pre-training for small datasets, achieving 35.9% better performance than base YOLOv12.
📊 Model Performance:
🎯 Why This Model Excels:
🔗 Download Trained Weights:
# Download pre-trained Construction-PPE model (mAP@50: 51.9%)
wget https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r -O construction_ppe_best.pt
# Or use direct link
curl -L "https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r" -o construction_ppe_best.pt
🚀 Quick Start with Pre-trained Model:
# Download pre-trained Construction-PPE model (mAP@50: 51.9%)
wget https://1drv.ms/u/c/8a791e13b6e7ac91/ETzuMC0lHxBIv1eeOkOsq1cBZC5Cj7dAZ1W_c5yX_QcyYw?e=IW5N8r -O construction_ppe_best.pt
# Command-line inference
python inference.py \
--weights construction_ppe_best.pt \
--source your_construction_images/ \
--conf 0.25 \
--save
# Streamlit web interface
python launch_streamlit.py
# Upload construction_ppe_best.pt in the interface
🎯 Perfect for:
💡 Pro Tips for Best Results:
--stream mode for real-time detection🔬 Technical Details:
yolov12n
yolov12s
yolov12m
yolov12l
yolov12x
from ultralytics import YOLO
model = YOLO('yolov12{n/s/m/l/x}.pt')
model.val(data='coco.yaml', save_json=True)
from ultralytics import YOLO
model = YOLO('yolov12n.yaml')
# Train the model
results = model.train(
data='coco.yaml',
epochs=600,
batch=256,
imgsz=640,
scale=0.5, # S:0.9; M:0.9; L:0.9; X:0.9
mosaic=1.0,
mixup=0.0, # S:0.05; M:0.15; L:0.15; X:0.2
copy_paste=0.1, # S:0.15; M:0.4; L:0.5; X:0.6
device="0,1,2,3",
)
# Evaluate model performance on the validation set
metrics = model.val()
# Perform object detection on an image
results = model("path/to/image.jpg")
results[0].show()
from ultralytics import YOLO
# Load YOLOv12 + DINOv3 enhanced model
model = YOLO('ultralytics/cfg/models/v12/yolov12-dino3.yaml')
# Train with Vision Transformer enhancement
results = model.train(
data='coco.yaml',
epochs=100, # Reduced epochs due to enhanced features
batch=16, # Adjusted for DINOv3 memory usage
imgsz=640,
device=0,
)
# Available DINOv3 configurations:
# - yolov12-dino3-small.yaml (fastest, +2.5% mAP)
# - yolov12-dino3.yaml (balanced, +5.0% mAP)
# - yolov12-dino3-large.yaml (best accuracy, +5.5% mAP)
# - yolov12-dino3-convnext.yaml (hybrid, +4.5% mAP)
Launch the professional Streamlit interface with advanced analytics and large file support:
# Method 1: Interactive launcher (recommended)
python launch_streamlit.py
# Method 2: Direct launch
streamlit run simple_streamlit_app.py --server.maxUploadSize=5000
Streamlit Features:
Access: http://localhost:8501

Professional Streamlit interface showing PPE detection with confidence scores, class distribution, and detailed analytics
| Feature | Streamlit App | Command Line |
|---|---|---|
| File Upload Limit | 5GB ✅ | Unlimited ✅ |
| Analytics & Charts | Advanced ✅ | Text only 📝 |
| Data Export | CSV/JSON ✅ | Files ✅ |
| UI Style | Professional 🎯 | Terminal 💻 |
| Best For | Production, Analysis | Automation, Batch |
| Model Support | All sizes ✅ | All sizes ✅ |
| Visualization | Interactive charts 📈 | Text summaries 📄 |
| Deployment | Web-based 🌐 | Script-based 🖥️ |
Use the powerful command-line interface for batch processing and automation:
# Single image inference
python inference.py --weights best.pt --source image.jpg --save --show
# Batch inference on directory
python inference.py --weights runs/detect/train/weights/best.pt --source test_images/ --output results/
# Custom thresholds and options
python inference.py --weights model.pt --source images/ --conf 0.5 --iou 0.7 --save-txt --save-crop
# DINOv3-enhanced model inference
python inference.py --weights runs/detect/high_performance_dual/weights/best.pt --source data/ --conf 0.3
Command Options:
--weights: Path to trained model weights (.pt file)--source: Image file, directory, or list of images--conf: Confidence threshold (0.01-1.0, default: 0.25)--iou: IoU threshold for NMS (0.01-1.0, default: 0.7)--save: Save annotated images--save-txt: Save detection results to txt files--save-crop: Save cropped detection images--device: Device to run on (cpu, cuda, mps)Direct integration into your Python applications:
from ultralytics import YOLO
from inference import YOLOInference
# Method 1: Standard YOLO API
model = YOLO('yolov12{n/s/m/l/x}.pt')
results = model.predict('image.jpg', conf=0.25, iou=0.7)
# Method 2: Enhanced Inference Class
inference = YOLOInference(
weights='runs/detect/train/weights/best.pt',
conf=0.25,
iou=0.7,
device='cuda'
)
# Single image
results = inference.predict_single('image.jpg', save=True)
# Batch processing
results = inference.predict_batch('images_folder/', save=True)
# From image list
image_list = ['img1.jpg', 'img2.jpg', 'img3.jpg']
results = inference.predict_from_list(image_list, save=True)
# Print detailed results
inference.print_results_summary(results, "test_images")
Use your trained DINOv3-YOLOv12 models for enhanced object detection:
# DINOv3 single-scale model
python inference.py \
--weights runs/detect/efficient_single/weights/best.pt \
--source test_images/ \
--conf 0.25 \
--save
# DINOv3 dual-scale model (highest performance)
python inference.py \
--weights runs/detect/high_performance_dual/weights/best.pt \
--source complex_scene.jpg \
--conf 0.3 \
--iou 0.6 \
--save --show
# Input preprocessing model
python inference.py \
--weights runs/detect/stable_preprocessing/weights/best.pt \
--source video.mp4 \
--save
| Model Type | Speed | Memory | Best For | Confidence Threshold |
|---|---|---|---|---|
| YOLOv12n | ⚡ Fastest | 2GB | Embedded systems | 0.4-0.6 |
| YOLOv12s | ⚡ Fast | 3GB | General purpose | 0.3-0.5 |
| YOLOv12s-dino3-single | 🎯 Balanced | 4GB | Medium objects | 0.25-0.4 |
| YOLOv12s-dino3-dual | 🎪 Accurate | 8GB | Complex scenes | 0.2-0.35 |
| YOLOv12l-dino3-vitl16 | 🏆 Maximum | 16GB | Research/High-end | 0.15-0.3 |
Real timings for yolov12m-dualp0p3-dino3-vitb16 (107.3 M params), 640×640, batch 1, on an RTX 5080 — torch 2.12.0+cu130, TensorRT 10.16.1.11, 30 warm-up + 200 timed iterations, CUDA-event timed.
| Runtime | Forward only | End-to-end predict() | FPS | Speedup |
|---|---|---|---|---|
| TensorRT FP16 | 2.72 ms (p99 2.89) | 4.18 ms | 367 | 9.6× |
| PyTorch FP16 | 26.18 ms (p99 26.85) | 27.14 ms | 38 | 1.0× |
| PyTorch FP32 | 26.61 ms (p99 29.99) | 27.99 ms | 38 | 1.0× |
Engine stage breakdown: 1.03 pre + 2.63 infer + 0.39 post ms. Reproduce with:
python benchmark_latency.py --engine best.engine --pt best.pt --imgsz 640
Two things worth noting before quoting these numbers:
.pt with half=True alone buys you almost nothing.See the TensorRT Conversion section under Export for how to build the engine, and for two failure modes that silently produce wrong output.
# Custom preprocessing and postprocessing
from inference import YOLOInference
import cv2
inference = YOLOInference('model.pt')
# Load and preprocess image
image = cv2.imread('image.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Run inference with custom parameters
results = inference.predict_single(
source='preprocessed_image.jpg',
save=True,
show=False,
save_txt=True,
save_conf=True,
save_crop=True,
output_dir='custom_results/'
)
# Access detailed results
for result in results:
boxes = result.boxes.xyxy.cpu().numpy() # Bounding boxes
confs = result.boxes.conf.cpu().numpy() # Confidence scores
classes = result.boxes.cls.cpu().numpy() # Class IDs
names = result.names # Class names dictionary
print(f"Detected {len(boxes)} objects")
for box, conf, cls in zip(boxes, confs, classes):
print(f"Class: {names[int(cls)]}, Confidence: {conf:.3f}")
from ultralytics import YOLO
model = YOLO('yolov12{n/s/m/l/x}.pt')
model.export(format="engine", half=True) # or format="onnx"
Trained DINO-YOLO checkpoints (including the DINOv3 weights baked inside the .pt) convert to TensorRT via a two-stage flow:
best.pt ──► ONNX (portable, any machine) ──► TensorRT engine (NVIDIA GPU only)
The DINOv3 ViT is part of the same graph as YOLOv12, so its weights are exported automatically — no separate conversion of the DINO weights is needed.
# Stage 0 — Export dependencies (not covered by requirements.txt):
pip install onnx onnxslim onnxscript "transformers>=4.56,<4.57"
# Stage 1 — Export ONNX (works on any machine, even without a GPU):
python export_tensorrt.py --weights runs/detect/train/weights/best.pt --format onnx
# Stage 2 — Build the TensorRT engine (run on the NVIDIA GPU machine):
python export_tensorrt.py --weights best.pt --format engine --half
# Alternative: build the engine from the ONNX with trtexec:
trtexec --onnx=best.onnx --saveEngine=best.engine --fp16
| Flag | Default | Description |
|---|---|---|
--weights | (required) | Path to trained .pt checkpoint |
--format | onnx | onnx or engine (TensorRT) |
--imgsz | 640 | Fixed inference image size (see caveats) |
--half | off | FP16 export — recommended for TensorRT (~2× faster) |
--batch | 1 | Fixed batch size |
--workspace | 4 | TensorRT builder workspace in GB |
Fixed input size is required (dynamic=False, enforced by the script). The DINO backbone/preprocessor contains shape-dependent Python branching (patch-grid fitting, padding/truncation) that resolves to constants at trace time only when the input shape is fixed. Pick --imgsz to match your deployment resolution.
SDPA export bug on torch < 2.4. Exporting the ViT's scaled_dot_product_attention fails with TypeError: z_(): incompatible function arguments ... 0.125. The script automatically switches the HuggingFace DINOv3 submodules to eager attention for export — identical outputs, and harmless on newer torch versions.
Warm-up forward pass. DINO projection layers can be created lazily on the first forward; the script runs a dummy pass before tracing so the exported graph is complete.
Expect large artifacts. A ViT-B variant produces a ~385 MB ONNX (fp32) / ~200 MB engine (fp16) and longer TensorRT build times than plain YOLOv12. Raise --workspace if the builder runs out of memory.
NMS stays outside the engine — postprocess exactly as with .pt inference.
transformers must match the version that trained the checkpoint. The DINOv3 ViT is pickled inside the .pt, so its module layout is frozen at training time while its forward() code comes from whatever transformers is installed. Checkpoints trained with 4.56.x carry the layout embeddings / rope_embeddings / layer / norm; loading them under transformers 5.x fails with:
AttributeError: 'DINOv3ViTModel' object has no attribute 'model'
Pin transformers>=4.56,<4.57. Check what a checkpoint expects with:
import torch
ck = torch.load("best.pt", map_location="cpu", weights_only=False)
m = ck.get("ema") or ck["model"]
d = next(x.dino_model for x in m.modules() if hasattr(x, "dino_model"))
print(d.config.transformers_version, [n for n, _ in d.named_children()])
The FP16 engine has FP32 input/output bindings — never feed it half tensors. --half makes TensorRT compute in FP16, but the network I/O stays FP32 (the build log confirms: input "images" ... DataType.FLOAT). Ultralytics binds the input by raw pointer without converting, so a half tensor makes TensorRT read 4 bytes per element out of a 2-byte-per-element buffer. It reads past the end of the buffer, runs at full speed, and silently returns garbage or NaN — there is no error. The failure is nondeterministic, which makes it easy to mistake for a numerical problem.
model = YOLO("best.engine", task="detect")
model.predict(src, imgsz=640) # correct — dtype is auto-detected
model.predict(src, imgsz=640, half=True) # WRONG — silent garbage/NaN
The same applies to AutoBackend: pass fp16=False and let it read the real dtypes off the engine bindings. Verify with AutoBackend("best.engine", ...).fp16, which should report False.
Numerical parity between .pt and ONNX has been validated (max abs diff ~1.5e-4, ordinary fp32 noise). Still, sanity-check your own checkpoint before building the engine:
yolo predict model=best.onnx imgsz=640 source=path/to/test_image.jpg
Compare a few detections against the original .pt — they should match.
Benchmarked with benchmark_latency.py (in the repo root):
python benchmark_latency.py --engine best.engine --pt best.pt --imgsz 640
Setup. yolov12m-dualp0p3-dino3-vitb16 (107.3 M params, 14,100 GFLOPs as reported by Ultralytics), 640×640, batch 1, RTX 5080 (16 GB), torch 2.12.0+cu130, TensorRT 10.16.1.11. 30 warm-up + 200 timed iterations, CUDA-event timed with a per-iteration synchronize().
| forward only | end-to-end predict() | FPS (forward) | |
|---|---|---|---|
| TensorRT FP16 | 2.72 ms (p99 2.89) | 4.18 ms | 367 |
| PyTorch FP16 | 26.18 ms (p99 26.85) | 27.14 ms | 38 |
| PyTorch FP32 | 26.61 ms (p99 29.99) | 27.99 ms | 38 |
≈9.6× faster on the forward pass and ≈6.5× end-to-end. Stage breakdown for the engine: 1.03 pre + 2.63 infer + 0.39 post ms — once the backbone drops to 2.6 ms, letterboxing becomes ~25% of the per-image cost.
Note that PyTorch FP16 and FP32 are within noise of each other (26.2 vs 26.6 ms): in eager mode this model is not tensor-core bound, so essentially the entire speedup comes from TensorRT's kernel fusion and scheduling rather than from reduced precision.
Two numbers, not one. Forward only is the network in isolation — the honest "the engine is X ms" figure. End-to-end is Ultralytics' full path including letterbox and NMS, which is what you actually pay per image in a pipeline. Quote whichever matches your claim.
Build cost. 104 s total on the RTX 5080 (65 s of it TensorRT engine generation), producing a 209 MB engine from a 430 MB intermediate ONNX.
Numerical parity between .pt (FP32) and the FP16 engine on identical input:
| metric | value |
|---|---|
| cosine similarity (full output tensor) | 0.99988 |
| confidence correlation across 8400 anchors | 0.972 |
| box max diff, top-20 anchors by confidence | 3.6 px |
Consistent with ordinary FP16 accumulation error in the ViT. Large box differences do appear on low-confidence background anchors, but those are unconstrained during training and get discarded by NMS — compare only anchors that survive your confidence threshold, or the numbers will look alarming for no reason.
Caveat on these parity figures. They were measured on an image containing no positive detections, so they compare the two models near the noise floor rather than on confident boxes. They show the graph was exported correctly, but they are not a substitute for validating mAP on your own dataset. Before deploying, run
yolo val model=best.engine data=your_data.yaml imgsz=640and compare against the.pt.
Launch the professional Streamlit interface with advanced analytics:
# Interactive launcher with app selection
python launch_streamlit.py
# Or direct launch
streamlit run simple_streamlit_app.py --server.maxUploadSize=5000
# Open your browser and visit: http://localhost:8501
Professional Features:
Choose Streamlit Interface for:
Choose Command Line for:
This repository includes official DINOv3 integration directly from Facebook Research with advanced custom model support:
--dinoversion argument: DINOv3 is default (version=3), DINOv2 support (version=2)--dino-input parameter for ANY custom DINO model--dino-input parameter documentation--unfreeze-dinoBy default, DINO weights are FROZEN ❄️ for optimal training efficiency. Use --unfreeze-dino to make DINO weights trainable for advanced fine-tuning:
# Default behavior (Recommended) - DINO weights are FROZEN
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 100
# Advanced: Make DINO weights TRAINABLE for fine-tuning
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--unfreeze-dino \
--epochs 100
| Configuration | DINO Weights | VRAM Usage | Training Speed | Best For |
|---|---|---|---|---|
| Default (Frozen) ❄️ | Fixed | 🟢 Lower | ⚡ Faster | Production, general use |
--unfreeze-dino 🔥 | Trainable | 🔴 Higher | 🐌 Slower | Research, specialized domains |
✅ Use Default (Frozen) when:
🔥 Use --unfreeze-dino when:
# 1️⃣ Single P0 Input Integration
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration single
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration single --unfreeze-dino
# 2️⃣ Dual P3+P4 Backbone Integration
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dual
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dual --unfreeze-dino
# 3️⃣ DualP0P3 P0+P3 Optimized Integration (Balanced)
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dualp0p3
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration dualp0p3 --unfreeze-dino
# 4️⃣ Triple P0+P3+P4 All Levels Integration (Ultimate)
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration triple
python train_yolov12_dino.py --data data.yaml --yolo-size s --dino-variant vitb16 --integration triple --unfreeze-dino
# Test pure YOLOv12 (no DINO)
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--epochs 5 \
--name test_pure_yolov12
# Test official DINOv3 integration
python validate_dinov3.py --test-all
# Test custom input support
python test_custom_dino_input.py
# Test local weight file loading
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-input ./my_custom_dino.pth \
--integration single \
--epochs 5 \
--name test_local_weights
# Example training with official DINOv3 single integration
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration single \
--epochs 10 \
--name test_dinov3_single
# Example training with DINOv3 dual integration
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dino-variant vitb16 \
--integration dual \
--epochs 10 \
--name test_dinov3_dual
# Test ViT-H+/16 distilled (840M) - Enterprise grade
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--dino-variant vith16_plus \
--integration dual \
--epochs 10 \
--batch-size 4 \
--name test_vith16_plus_enterprise
# Test ViT-7B/16 ultra (6.7B) - Research only
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size l \
--dino-variant vit7b16 \
--integration single \
--epochs 5 \
--batch-size 1 \
--name test_vit7b16_research
# Test backward compatibility with DINOv2
python train_yolov12_dino.py \
--data coco.yaml \
--yolo-size s \
--dinoversion 2 \
--dino-variant vitb16 \
--integration single \
--epochs 5 \
--name test_dinov2_compatibility
Quick Fix - Choose One:
Option 1: Reduce Batch Size
# If using batch 90 → try 45
--batch-size 45
# Still NaN? → try 24
--batch-size 24
# Still NaN? → try 16
--batch-size 16
Option 2: Reduce Learning Rate
# If using lr 0.01 → try 0.005
--lr 0.005
# Still NaN? → try 0.003
--lr 0.003
# Still NaN? → try 0.001
--lr 0.001
Option 3: Both (Most Reliable)
--batch-size 24 --lr 0.005
NaN Loss = Reduce batch size by half OR reduce learning rate by half (or both)
YOLOv12-DINO3 now supports OBB detection for rotated objects - ideal for aerial imagery, document analysis, and applications where object orientation matters.
Example: OBB detection on aerial imagery showing rotated bounding boxes for ships and other objects
# Train OBB model
python trainobb.py --model yolov12m-dualp0p3 --data dota.yaml --epochs 100 --imgsz 1024
# Run inference
python inferobb.py --weights best.pt --source images/ --conf 0.25 --save-txt
| Model | CLI Name | Description |
|---|---|---|
| YOLOv12s-P0only-OBB | yolov12s-p0only | Small, P0 preprocessing |
| YOLOv12m-DualP0P3-OBB | yolov12m-dualp0p3 | Medium, balanced |
| YOLOv12l-DualP0P3-OBB | yolov12l-dualp0p3 | Large, high accuracy |
For complete OBB documentation including:
See: README_OBB.md
Made by AI Research Group, Department of Civil Engineering, KMUTT 🏛️
The code is based on ultralytics. Thanks for their excellent work!
Official DINOv3 Integration: This implementation uses official DINOv3 models directly from Meta's Facebook Research repository: facebookresearch/dinov3. The integration includes comprehensive support for all official DINOv3 variants and the innovative --dino-input parameter for custom model loading.
YOLOv12: Based on the official YOLOv12 implementation with attention-centric architecture from sunsmarterjie/yolov12.
@article{tian2025yolov12,
title={YOLOv12: Attention-Centric Real-Time Object Detectors},
author={Tian, Yunjie and Ye, Qixiang and Doermann, David},
journal={arXiv preprint arXiv:2502.12524},
year={2025}
}
@article{dinov3_yolov12_2025
title={DINOv3-YOLOv12: Systematic Vision Transformer Integration for Enhanced Object Detection},
author={AI Research Group, Department of Civil Engineering, KMUTT},
journal={GitHub Repository},
year={2024},
url={https://github.com/Sompote/DINOV3-YOLOV12}
}
@article{yolo_dino_paper_2025,
title={YOLO-DINO: YOLOv12-DINOv3 Hybrid Architecture for Data-Efficient Object Detection},
author={AI Research Group, Department of Civil Engineering, KMUTT},
journal={arXiv preprint arXiv:2510.25140},
year={2024},
url={https://arxiv.org/abs/2510.25140}
}
🚀 Revolutionizing Object Detection with Systematic Vision Transformer Integration
Made with ❤️ by the AI Research Group, Department of Civil Engineering King Mongkut's University of Technology Thonburi (KMUTT)
Python
99.5%