Complete YOLOv12 instance segmentation model family with true DINOv3 enhancement for superior feature extraction and pixel-perfect mask prediction.
π Latest Update: NEW DualP0P3 Integration Mode (
--integration dualp0p3) - optimal balance for satellite imagery! Plus official DINOv3 models from Hugging Face with--dinoversion v3.
This repository provides 25 YOLOv12 segmentation model variants combining YOLOv12's efficient architecture with DINOv3's advanced vision transformer features for state-of-the-art instance segmentation performance with precise mask prediction.
--dinoversion v3π Citation: If you use this work, please cite our repository: https://github.com/Sompote/DinoV3-YOLO-Segment
| Category | Description | Models | DINO Integration | CLI Usage |
|---|---|---|---|---|
| Standard | Base YOLOv12 segmentation | 5 variants | None | No --use-dino flag |
| Single | DINO at P4 feature level | 5 variants | P4 enhancement | --integration single |
| Dual | DINO at P3 and P4 levels | 5 variants | P3 + P4 enhancement | --integration dual |
| π DualP0P3 | Balanced preprocessing + backbone | 5 variants | P0 + P3 enhancement | --integration dualp0p3 |
| π Triple | Ultimate performance | 5 variants | P0 + P3 + P4 enhancement | --integration triple |
| Model | mAPmask | mAPmask@0.5 | Speed (ms) | Parameters | Mask Quality |
|---|---|---|---|---|---|
| YOLOv12n-seg | 32.8 | 52.1 | 1.84 | 2.8M | High |
| YOLOv12s-seg | 38.6 | 59.2 | 2.84 | 9.8M | High |
| YOLOv12m-seg | 42.3 | 63.8 | 6.27 | 21.9M | Very High |
| YOLOv12l-seg | 43.2 | 64.5 | 7.61 | 28.8M | Very High |
| YOLOv12x-seg | 44.2 | 65.3 | 15.43 | 64.5M | Excellent |
Note: DINO-enhanced variants show 2-5% mask mAP improvements with enhanced boundary precision. DINOv3 models provide superior performance over DINOv2 with better feature extraction.
The DualP0P3 integration mode (--integration dualp0p3) provides a balanced approach between performance and memory efficiency:
Input Image β DINO3Preprocessor (P0) β Enhanced Features β YOLOv12 Backbone β DINO3Backbone (P3) β Segmentation Head
| Mode | Integration Points | Memory | Performance | Speed | Best Use Case |
|---|---|---|---|---|---|
| Single | P4 only | π’ Low | π‘ Good | π’ Fast | General tasks, development |
| Dual | P3 + P4 | π‘ Medium | π’ High | π‘ Medium | Dense scenes, small objects |
| π DualP0P3 | P0 + P3 | π‘ Medium | π’ High | π‘ Medium | Satellite imagery, balanced needs |
| Triple | P0 + P3 + P4 | π΄ High | π’ Maximum | π΄ Slow | Research, maximum accuracy |
# Standard segmentation with DualP0P3
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--integration dualp0p3 \
--dinoversion v3
# Satellite imagery segmentation (recommended)
python train_yolov12_segmentation.py \
--data satellite_data.yaml \
--model-size m \
--use-dino \
--dino-variant vitl16_distilled \
--integration dualp0p3 \
--dinoversion v3
This implementation supports both DINOv2 and DINOv3 models for maximum flexibility and cutting-edge performance:
| Version | Description | Compatibility | Recommended Use |
|---|---|---|---|
DINOv2 (--dinoversion v2) | Stable, widely tested | Full Hugging Face support | Production, proven performance |
DINOv3 (--dinoversion v3) | π Latest features, superior performance | β Full support via Hugging Face | Recommended for best results |
π New: DINOv3 models are now fully supported using official
facebook/dinov3-*-pretrain-lvd1689mmodels from Hugging Face!
| Variant | DINOv2 | DINOv3 | Parameters | Embed Dim | Dataset | Description | Memory | Recommended For |
|---|---|---|---|---|---|---|---|---|
vits16 | β | β | 21M | 384 | LVD-1689M | Small, fast | Low | Development, testing |
vitb16 | β | β | 86M | 768 | LVD-1689M | Balanced | Medium | General use, production |
vitl16 | β | β | 300M | 1024 | LVD-1689M | Large, high-performance | High | High-accuracy needs |
vitl16_distilled | β | β | 300M | 1024 | SAT-493M | ViT-L/16 Distilled (Satellite) | High | Satellite/aerial imagery |
vith16_plus | β | β | 840M | 1536 | LVD-1689M | ViT-H+/16 Distilled | Very High | Maximum performance |
vit7b16 | β | β | 6,716M | 4096 | SAT-493M | ViT-7B/16 (Satellite) | Extreme | Satellite imagery, research |
vit7b16_lvd | β | β | 6,716M | 4096 | LVD-1689M | ViT-7B/16 (Standard) | Extreme | Research, maximum scale |
# Single Integration: DINO enhancement at P4 level (DINOv2)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--integration single \
--dinoversion v2
# Dual Integration: DINO enhancement at P3+P4 levels (DINOv3)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration dual \
--dinoversion v3
# DualP0P3 Integration: DINO enhancement at P0+P3 levels (Balanced)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration dualp0p3 \
--dinoversion v3
# Triple Integration: DINO enhancement at P0+P3+P4 levels (Ultimate Performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3
# Satellite/Aerial Imagery: Use SAT-493M pretrained models for optimal performance
python train_yolov12_segmentation.py \
--data satellite_segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--integration dual \
--dinoversion v3
# Large-scale Satellite Imagery: ViT-7B/16 for maximum accuracy
python train_yolov12_segmentation.py \
--data satellite_segmentation_data.yaml \
--model-size x \
--use-dino \
--dino-variant vit7b16 \
--integration dual \
--dinoversion v3
Important: The
--dinoversionparameter is REQUIRED when using--use-dinoto specify which DINO version to use.
π‘ Tip: For satellite/aerial imagery segmentation, use
vitl16_distilledorvit7b16variants which are pretrained on SAT-493M dataset for optimal performance on overhead imagery.
DINOv3 models require Hugging Face authentication as they are gated models. You need to:
export HF_TOKEN="your_hf_token_here"
# or
export HUGGING_FACE_HUB_TOKEN="your_hf_token_here"
huggingface-cli login
Note: DINOv2 models work without authentication, while DINOv3 models provide superior performance but require the setup above.
# Clone repository
git clone https://github.com/Sompote/DinoV3-YOLO-Segment.git
cd DinoV3-YOLO-Segment
# Create conda environment
conda create -n yolov12-segment python=3.11
conda activate yolov12-segment
# Install dependencies
pip install -r requirements.txt
pip install transformers # For DINO models
pip install -e .
# 4. Setup Hugging Face authentication (REQUIRED for DINOv3 models)
# Method 1: Environment variable
export HF_TOKEN="your_token_here"
# Get your token from: https://huggingface.co/settings/tokens
# Method 2: Interactive login
huggingface-cli login
# Expected output:
# _| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|
# _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
# _|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|
# _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
# _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
#
# To log in, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
# Enter your token (input will not be visible):
# Add token as git credential? (Y/n) Y
# Token is valid (permission: fineGrained).
# The token `hf2` has been saved to /workspace/.hf_home/stored_tokens
# Verify installation
python -c "from ultralytics.nn.modules.block import DINO3Backbone; print('β
YOLOv12 Segmentation ready!')"
# Basic YOLOv12 segmentation training (recommended)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s
# With custom optimizer and parameters
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--optimizer SGD \
--lr 0.01 \
--momentum 0.937 \
--epochs 100 \
--batch-size 16 \
--imgsz 640
# Single-scale DINO enhancement with DINOv3 (balanced performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration single \
--optimizer AdamW \
--lr 0.002
# Dual-scale DINO enhancement with DINOv2 (best compatibility)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v2 \
--integration dual \
--optimizer AdamW \
--lr 0.002
# TRIPLE DINO integration with DINOv3 (ultimate performance - P0+P3+P4)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration triple \
--optimizer AdamW \
--lr 0.001 \
--momentum 0.9 \
--weight-decay 0.01
Control optimizer settings to prevent automatic parameter override:
# Available optimizers with recommended settings
--optimizer SGD --lr 0.01 --momentum 0.937 # Best for large datasets
--optimizer Adam --lr 0.001 --weight-decay 0.0005 # Fast convergence
--optimizer AdamW --lr 0.001 --weight-decay 0.01 # Best for DINO models
--optimizer RMSProp --lr 0.001 # Adaptive learning
--optimizer auto # Automatic selection (overrides manual settings)
Key Benefits:
--lr, --momentum, --weight-decay are respectedEnsure proper best weight saving to prevent best.pt = last.pt issues:
# Recommended settings for proper best weight detection
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--val \
--val-period 1 \
--patience 20 \
--save-best \
--plots \
--save-json \
--epochs 150
Best Practices for Weight Saving:
--val to ensure fitness calculation--patience 20-50 for early stopping--plots --save-json to track progress# Fast training for development (25x faster validation)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration single \
--val-period 5 \
--val-split 0.2 \
--fast-val
# Ultra-fast experimentation (100x faster validation)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--val-period 10 \
--val-split 0.1 \
--fast-val \
--epochs 100
# Production training with balanced validation
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration triple \
--val-period 5 \
--val-split 0.3 \
--epochs 300
For optimal performance on satellite, aerial, or overhead imagery, use models pretrained on the SAT-493M dataset:
| Use Case | Model Variant | Parameters | Integration | Best For |
|---|---|---|---|---|
| Standard Satellite | vitl16_distilled | 300M | dual | General satellite imagery |
| π Balanced Satellite | vitl16_distilled | 300M | dualp0p3 | Optimal memory/performance balance |
| High-Resolution Aerial | vit7b16 | 6,716M | dual | Ultra-high detail requirements |
| π Efficient High-Res | vit7b16 | 6,716M | dualp0p3 | Large models with memory constraints |
| Fast Satellite Processing | vitl16_distilled | 300M | single | Real-time applications |
# Standard satellite imagery segmentation
python train_yolov12_segmentation.py \
--data satellite_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--integration dual \
--dinoversion v3 \
--epochs 200
# π NEW: Balanced satellite imagery (recommended for most use cases)
python train_yolov12_segmentation.py \
--data satellite_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--integration dualp0p3 \
--dinoversion v3 \
--epochs 200
# Ultra-high resolution aerial imagery (research/precision applications)
python train_yolov12_segmentation.py \
--data aerial_dataset.yaml \
--model-size x \
--use-dino \
--dino-variant vit7b16 \
--integration dual \
--dinoversion v3 \
--batch-size 2 \
--epochs 300
# π NEW: Efficient high-resolution with ViT-7B (memory optimized)
python train_yolov12_segmentation.py \
--data aerial_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16 \
--integration dualp0p3 \
--dinoversion v3 \
--batch-size 4 \
--epochs 250
π‘ Why SAT-493M Models? These variants are specifically trained on 493M satellite images, making them particularly effective for:
- Land use classification segmentation
- Urban planning and infrastructure mapping
- Agricultural field boundary detection
- Environmental monitoring and change detection
- Disaster assessment and damage mapping
π DualP0P3 + SAT-493M: The combination of DualP0P3 integration with SAT-493M models provides optimal balance for satellite imagery:
- Lower memory usage than triple integration while maintaining high accuracy
- Enhanced preprocessing specifically tuned for satellite imagery characteristics
- Improved P3-level features for better boundary detection in aerial views
- Recommended for production satellite segmentation workflows
Dataset: Crack Segmentation Dataset from Roboflow
Performance comparison on crack segmentation dataset using YOLOv12 Large (L) variants:
| Model Configuration | mAPβ β (Box) | mAPβ β (Segment) | Model Type | DINO Integration |
|---|---|---|---|---|
| YOLOv12l-seg | 0.672 | 0.564 | Standard | None |
| YOLOv12l + Triple DINO (VIT-B) | 0.780 | 0.626 | Enhanced | P0+P3+P4 |
π― Triple DINO Integration Benefits:
π Performance Analysis:
Standard YOLOv12l-seg:
βββ Box mAPβ
β: 67.2%
βββ Segment mAPβ
β: 56.4%
βββ Configuration: Base segmentation model
Triple DINO YOLOv12l-seg:
βββ Box mAPβ
β: 78.0% (+10.8 points)
βββ Segment mAPβ
β: 62.6% (+6.2 points)
βββ Configuration: P0+P3+P4 DINO integration with VIT-B
π Crack Detection Capabilities:
For optimal crack segmentation results, use the Triple DINO configuration:
# Recommended training command for crack segmentation
python train_yolov12_segmentation.py \
--data crack_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration triple \
--optimizer AdamW \
--lr 0.001 \
--momentum 0.9 \
--weight-decay 0.01 \
--epochs 300 \
--batch-size 4 \
--patience 50 \
--name crack_triple_dino
The new --integration parameter simplifies DINO integration selection:
| Integration | Description | Enhancement Levels | Performance | Use Case |
|---|---|---|---|---|
single | DINO at P4 level only | P4 enhancement | Good | Balanced speed/accuracy |
dual | DINO at P3 and P4 levels | P3 + P4 enhancement | Better | High accuracy needs |
triple | DINO at P0, P3, and P4 levels | P0 + P3 + P4 enhancement | Best | Ultimate performance |
# Single integration (fastest)
python train_yolov12_segmentation.py \
--data data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration single
# Dual integration (balanced)
python train_yolov12_segmentation.py \
--data data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration dual
# Triple integration (ultimate)
python train_yolov12_segmentation.py \
--data data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration triple
For maximum performance with the largest DINOv3 models:
# ViT-L/16 Distilled (300M parameters, satellite-trained) - Optimized large model
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--dinoversion v3 \
--integration dual \
--epochs 250 \
--batch-size 4 \
--name vitL_distilled_satellite
# ViT-H+/16 Distilled (840M parameters) - High-performance variant
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vith16_plus \
--dinoversion v3 \
--integration dual \
--epochs 200 \
--batch-size 2 \
--name vitH_plus_experiment
# ViT-7B/16 (6.7B parameters, satellite-trained) - Ultimate performance (Satellite)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16 \
--dinoversion v3 \
--integration dual \
--epochs 150 \
--batch-size 1 \
--device cuda \
--name vit7b_ultimate_satellite
# ViT-7B/16 (6.7B parameters, LVD-1689M trained) - Ultimate performance (Standard)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16_lvd \
--dinoversion v3 \
--integration dual \
--epochs 150 \
--batch-size 1 \
--device cuda \
--name vit7b_ultimate_standard
# Triple integration for ViT-7B/16 (satellite-trained, ultimate performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16 \
--dinoversion v3 \
--integration triple \
--epochs 100 \
--batch-size 1 \
--name vit7b_triple_satellite
# Triple integration for ViT-7B/16 (LVD-1689M, ultimate performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16_lvd \
--dinoversion v3 \
--integration triple \
--epochs 100 \
--batch-size 1 \
--name vit7b_triple_standard
from ultralytics import YOLO
# Load trained segmentation model
model = YOLO('runs/segment/yolov12s-seg/weights/best.pt')
# Run segmentation inference
results = model('path/to/image.jpg')
results[0].show() # Display results with instance masks
# Access segmentation masks
for result in results:
masks = result.masks # Masks object
if masks is not None:
mask_data = masks.data # Raw mask data
mask_pixels = masks.xy # Mask contours
from ultralytics import YOLO
# Load DINO-enhanced segmentation model
model = YOLO('runs/segment/yolov12l-seg-dino3-triple-vitb16-dual/weights/best.pt')
# Enhanced segmentation inference with DINO
results = model('crack_image.jpg')
for result in results:
# Access enhanced masks from DINO features
if result.masks is not None:
print(f"Found {len(result.masks)} precise instance masks")
# Masks are more accurate due to DINO enhancement
masks = result.masks.data
The YOLOv12-DINO triple integration model demonstrates exceptional crack detection performance on real concrete structures:
Example 1: Multiple Crack Detection

Example 2: Single Crack with High Precision

Performance Highlights:
π― Crack Segmentation Performance:
Model: YOLOv12l + Triple DINO (P0+P3+P4)
βββ Instance Detection: 100% accuracy on visible cracks
βββ Confidence Range: 0.25 - 0.70 (robust detection)
βββ Mask Precision: Pixel-level boundary accuracy
βββ Processing Speed: Real-time inference
βββ Use Cases: Infrastructure inspection, quality control
# Train crack segmentation model with triple DINO integration
python train_yolov12_segmentation.py \
--data crack_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration triple \
--epochs 300 \
--batch-size 4
# Run crack detection inference with mask output
python inference.py \
--weights runs/segment/train/weights/best.pt \
--source concrete_images/ \
--save --save-masks \
--conf 0.25 \
--output crack_results/
Training can be dramatically sped up with smart validation strategies:
# π― Development Phase: Ultra-fast iteration (100x faster validation)
python train_yolov12_segmentation.py \
--data your_data.yaml \
--model-size s \
--val-period 10 \
--val-split 0.1 \
--fast-val \
--patience 15 \
--epochs 100
# π Production Phase: Balanced performance (25x faster validation)
python train_yolov12_segmentation.py \
--data your_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitb16 \
--integration dual \
--dinoversion v3 \
--val-period 5 \
--val-split 0.2 \
--fast-val \
--patience 25 \
--epochs 300
# π Final Training: Full validation for best results
python train_yolov12_segmentation.py \
--data your_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3 \
--val-period 2 \
--patience 50 \
--plots \
--save-json \
--epochs 300
| Strategy | Speed Gain | Best For | Example |
|---|---|---|---|
--val-period 10 | 10x faster | Long experiments, development | Skip validation 9/10 epochs |
--val-split 0.2 | 5x faster | Large datasets | Use 20% of validation data |
--fast-val | 2-3x faster | Quick iterations | Simplified metrics |
--patience 20 | Early stopping | Prevent overfitting | Stop if no improvement for 20 epochs |
--cache ram | 20-50% faster | Systems with sufficient RAM | Cache dataset in memory |
| Combined | 50-100x faster | Rapid experimentation | Use all strategies together |
All hyperparameters are configured through CLI arguments in train_yolov12_segmentation.py and default values from ultralytics/cfg/default.yaml:
| Parameter | CLI Argument | Default | Range | Description |
|---|---|---|---|---|
| Learning Rate Control | ||||
| Initial LR | --lr | 0.01 | 0.0001-0.1 | Initial learning rate (SGD=1E-2, Adam=1E-3) |
| Final LR Factor | N/A (default.yaml) | 0.01 | 0.001-0.1 | Final learning rate = lr0 Γ lrf |
| Momentum | --momentum | 0.937 | 0.8-0.99 | SGD momentum / Adam beta1 |
| Weight Decay | --weight-decay | 0.0005 | 0.0001-0.01 | L2 regularization strength |
| Warmup Strategy | ||||
| Warmup Epochs | --warmup-epochs | 3 | 0-20 | Linear warmup duration |
| Warmup Momentum | N/A (default.yaml) | 0.8 | 0.5-0.95 | Initial momentum during warmup |
| Warmup Bias LR | N/A (default.yaml) | 0.0 | 0.0-0.1 | Bias learning rate during warmup |
| Training Control | ||||
| Epochs | --epochs | auto | 50-1000 | Training duration |
| Batch Size | --batch-size | auto | 1-128 | Samples per batch |
| Patience | --patience | 10 | 5-200 | Early stopping patience |
| Image Size | --imgsz | 640 | 320-1280 | Input resolution |
| Component | CLI Argument | Default | Range | Description |
|---|---|---|---|---|
| Box Loss | --box-loss-gain | 7.5 | 1.0-20.0 | Bounding box regression weight |
| Classification Loss | --cls-loss-gain | 0.5 | 0.1-2.0 | Class prediction weight |
| DFL Loss | --dfl-loss-gain | 1.5 | 0.5-5.0 | Distribution Focal Loss weight |
| Category | CLI Argument | Default | Range | Description |
|---|---|---|---|---|
| Color Augmentation | ||||
| HSV Hue | --hsv-h | 0.015 | 0.0-0.1 | Hue shift range |
| HSV Saturation | --hsv-s | 0.7 | 0.0-1.0 | Saturation scaling |
| HSV Value | --hsv-v | 0.4 | 0.0-1.0 | Brightness scaling |
| Geometric Augmentation | ||||
| Rotation | --degrees | 0.0 | 0.0-45.0 | Random rotation degrees |
| Translation | --translate | 0.1 | 0.0-0.5 | Position shift fraction |
| Scaling | --scale | 0.5 | 0.0-1.0 | Size variation range |
| Shearing | --shear | 0.0 | 0.0-20.0 | Shear transformation |
| Perspective | --perspective | 0.0 | 0.0-0.001 | Perspective distortion |
| Flip Augmentation | ||||
| Vertical Flip | --flipud | 0.0 | 0.0-1.0 | Up-down flip probability |
| Horizontal Flip | --fliplr | 0.5 | 0.0-1.0 | Left-right flip probability |
| Advanced Augmentation | ||||
| Mosaic | --mosaic | 1.0 | 0.0-1.0 | 4-image mosaic probability |
| Mixup | --mixup | 0.0 | 0.0-1.0 | Image blending probability |
| Copy-Paste | --copy-paste | 0.1 | 0.0-1.0 | Instance copy-paste (segmentation) |
| Parameter | CLI Argument | Default | Description |
|---|---|---|---|
| Overlap Masks | --overlap-mask | True | Allow overlapping instance masks |
| Mask Ratio | --mask-ratio | 4 | Mask downsample ratio (1,2,4,8) |
| Single Class | --single-cls | False | Treat as single-class problem |
For unstable training with NaN losses or exploding gradients:
# Conservative Stable Training
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.001 \
--weight-decay 0.001 \
--warmup-epochs 15 \
--momentum 0.9 \
--box-loss-gain 3.0 \
--cls-loss-gain 0.25 \
--dfl-loss-gain 0.75 \
--batch-size 8 \
--patience 25
# Phase 1: Warmup Training (50 epochs)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.005 \
--warmup-epochs 20 \
--epochs 50 \
--patience 15 \
--name phase1_warmup
# Phase 2: Full Training (resume from phase 1)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.01 \
--epochs 200 \
--patience 30 \
--resume runs/segment/phase1_warmup/weights/last.pt \
--name phase2_full
Nano Models (n) - Fast Training:
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size n \
--lr 0.01 \
--batch-size 32 \
--weight-decay 0.0005 \
--warmup-epochs 3 \
--epochs 150
Large Models (l,x) - Stable Training:
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--lr 0.003 \
--batch-size 6 \
--weight-decay 0.0003 \
--warmup-epochs 10 \
--patience 50 \
--epochs 300
DINO Single-Scale (Stable):
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--integration single \
--dinoversion v3 \
--lr 0.008 \
--weight-decay 0.0003 \
--warmup-epochs 5 \
--batch-size 8
DINO Dual-Scale (Advanced):
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration dual \
--dinoversion v2 \
--lr 0.002 \
--weight-decay 0.0001 \
--warmup-epochs 15 \
--batch-size 4 \
--patience 50
DINO Triple Integration (Expert):
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3 \
--lr 0.0015 \
--weight-decay 0.00005 \
--warmup-epochs 20 \
--batch-size 2 \
--patience 75 \
--epochs 400
| Scenario | Recommended LR | Reasoning |
|---|---|---|
| Small datasets (<1000 images) | 0.005-0.008 | Prevent overfitting |
| Large datasets (>10k images) | 0.01-0.02 | Faster convergence |
| DINO integration | 0.002-0.008 | Complex model needs stability |
| Fine-tuning | 0.001-0.003 | Preserve pretrained features |
| High resolution (>1024px) | 0.003-0.006 | More stable gradients |
# Auto-batch size detection
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--batch-size -1 # Auto-detect maximum batch size
# Manual batch size based on GPU memory
# RTX 3060 (12GB): batch-size 8-16
# RTX 4090 (24GB): batch-size 16-32
# A100 (40GB): batch-size 32-64
Balanced Detection + Segmentation:
--box-loss-gain 7.5 --cls-loss-gain 0.5 --dfl-loss-gain 1.5
Prioritize Mask Quality:
--box-loss-gain 5.0 --cls-loss-gain 1.0 --dfl-loss-gain 2.0
Prioritize Detection Accuracy:
--box-loss-gain 10.0 --cls-loss-gain 0.3 --dfl-loss-gain 1.0
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3 \
--lr 0.002 \
--weight-decay 0.0001 \
--warmup-epochs 25 \
--patience 75 \
--box-loss-gain 6.0 \
--cls-loss-gain 0.8 \
--dfl-loss-gain 2.0 \
--mixup 0.2 \
--copy-paste 0.4 \
--epochs 500 \
--cache ram
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.015 \
--batch-size 24 \
--warmup-epochs 2 \
--patience 15 \
--val-period 5 \
--fast-val \
--epochs 100
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size m \
--batch-size 4 \
--lr 0.005 \
--weight-decay 0.001 \
--warmup-epochs 10 \
--cache False \
--workers 4
| File | Description | Usage |
|---|---|---|
| Training Scripts | ||
train_yolov12_segmentation.py | Main segmentation training script | CLI interface with fast validation |
train_yolov12_dino.py | DINO detection training script | For detection tasks |
| Inference & Demo | ||
inference.py | Segmentation inference script | Batch processing with mask output |
app.py | Gradio web interface | Interactive demo |
| Documentation | ||
FAST_VALIDATION_GUIDE.md | Fast validation strategies | Speed optimization guide |
SEGMENTATION_CLI_GUIDE.md | Complete CLI reference | All training parameters |
README_SEGMENTATION.md | Segmentation overview | Task-specific guide |
DINO_FIX_DOCUMENTATION.md | Technical fixes | Troubleshooting guide |
| Model Size | Standard | Single Integration | Dual Integration | Triple Integration |
|---|---|---|---|---|
| Nano | yolov12n-seg.yaml | yolov12n-dino3-vitb16-single-seg.yaml | yolov12n-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Small | yolov12s-seg.yaml | yolov12s-dino3-vitb16-single-seg.yaml | yolov12s-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Medium | yolov12m-seg.yaml | yolov12m-dino3-vitb16-single-seg.yaml | yolov12m-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Large | yolov12l-seg.yaml | yolov12l-dino3-vitb16-single-seg.yaml | yolov12l-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Extra | yolov12x-seg.yaml | yolov12x-dino3-vitb16-single-seg.yaml | yolov12x-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Directory | Contents | Purpose |
|---|---|---|
runs/segment/ | Training results, weights, metrics | Model outputs |
safety_test_results/ | Test images and predictions | Validation samples |
assets/ | Architecture diagrams (SVG) | Technical documentation |
logs/ | Training performance logs | Model benchmarks |
| File | Description |
|---|---|
requirements.txt | Python dependencies |
requirements_rtx5090.txt | RTX 5090 specific requirements |
pyproject.toml | Project configuration |
ultralytics/cfg/models/v12/ | All model architecture configs |
ultralytics/cfg/datasets/ | Dataset configuration templates |
# segmentation_data.yaml
path: /path/to/dataset
train: images/train
val: images/val
test: images/test
nc: 1 # number of classes
names: ['crack'] # class names
# Segmentation-specific paths
train_masks: masks/train # Training masks directory
val_masks: masks/val # Validation masks directory
# Show all available options
python train_yolov12_segmentation.py --help
# Basic segmentation training
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size s
# DINO-enhanced training (recommended) - simplified with --integration
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size s --use-dino --dino-variant vitb16 --dinoversion v3 --integration single
# π NEW: DualP0P3 integration (balanced performance/memory)
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size s --use-dino --dino-variant vitb16 --dinoversion v3 --integration dualp0p3
# Advanced configuration with early stopping - simplified with --integration
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size l --use-dino --dino-variant vitl16 --dinoversion v2 --integration dual --epochs 150 --batch-size 8 --patience 20 --name my-experiment
| Category | Arguments | Description |
|---|---|---|
| Required | --data, --model-size | Dataset YAML and model size (n/s/m/l/x) |
| DINO | --use-dino, --dino-variant, --integration, --dinoversion | DINO enhancement options (single/dual/dualp0p3/triple integration, v2/v3 support, dinoversion REQUIRED) |
| Optimizer | --optimizer, --lr, --momentum, --weight-decay | Optimizer control (SGD/Adam/AdamW/RMSProp/auto) |
| Fast Validation | --val-period, --val-split, --fast-val | Speed optimization (25-100x faster) |
| Segmentation | --overlap-mask, --mask-ratio, --box-loss-gain | Segmentation-specific parameters |
| Training | --epochs, --batch-size, --device, --patience | Core training configuration |
| Experiment | --name, --project, --resume | Experiment management |
ultralytics/cfg/models/v12/
βββ Standard Segmentation
β βββ yolov12n-seg.yaml
β βββ yolov12s-seg.yaml
β βββ yolov12m-seg.yaml
β βββ yolov12l-seg.yaml
β βββ yolov12x-seg.yaml
βββ Single-Scale DINO
β βββ yolov12n-dino3-vitb16-single-seg.yaml
β βββ yolov12s-dino3-vitb16-single-seg.yaml
β βββ yolov12m-dino3-vitb16-single-seg.yaml
β βββ yolov12l-dino3-vitb16-single-seg.yaml
β βββ yolov12x-dino3-vitb16-single-seg.yaml
βββ Dual-Scale DINO
β βββ yolov12n-dino3-vitb16-dual-seg.yaml
β βββ yolov12s-dino3-vitb16-dual-seg.yaml
β βββ yolov12m-dino3-vitb16-dual-seg.yaml
β βββ yolov12l-dino3-vitb16-dual-seg.yaml
β βββ yolov12x-dino3-vitb16-dual-seg.yaml
βββ π DualP0P3 Integration (uses preprocessing configs + P3 enhancement)
β βββ Built from preprocessing configs + automatic P3 enhancement
β βββ Configured via --integration dualp0p3
βββ Triple Integration (uses dual configs + preprocessing)
βββ Built from dual configs + automatic preprocessing
βββ Configured via --integration triple
--integration single)--use-dino --dino-variant vitb16 --integration single --dinoversion v3--integration dual)--use-dino --dino-variant vitl16 --integration dual --dinoversion v3--integration dualp0p3)--use-dino --dino-variant vitl16 --integration dualp0p3 --dinoversion v3--integration triple)--use-dino --dino-variant vitl16 --integration triple --dinoversion v3yolov12n
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('yolov12{n/s/m/l/x}.pt')
model.export(format="engine", half=True) # or format="onnx"
2025/09/22: π NEW: Complete YOLOv12 Segmentation with DINOv3 - Added comprehensive instance segmentation support with 20 model variants! Features systematic architecture with 4 integration approaches (Standard, Single-Scale DINO, Dual-Scale DINO, Preprocessing DINO), and support for all model sizes (n,s,m,l,x). Now includes precise mask prediction with 32 prototypes and 256 feature dimensions for superior segmentation accuracy.
2025/02/19: Base YOLOv12 architecture established with attention-centric design for enhanced feature extraction.
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.
This repository provides 5 distinct integration strategies for combining DINO with YOLOv12 segmentation, each optimized for different use cases:
| Integration Mode | Points | Memory | Performance | Speed | Training Time | Best Use Case |
|---|---|---|---|---|---|---|
| Standard | None | π’ Lowest | π‘ Baseline | π’ Fastest | π’ Shortest | Development, testing |
| Single | P4 | π’ Low | π‘ Good | π’ Fast | π’ Short | General tasks, production |
| Dual | P3+P4 | π‘ Medium | π’ High | π‘ Medium | π‘ Medium | Dense scenes, small objects |
| π DualP0P3 | P0+P3 | π‘ Medium | π’ High | π‘ Medium | π‘ Medium | Satellite imagery, balanced |
| Triple | P0+P3+P4 | π΄ High | π’ Maximum | π΄ Slow | π΄ Long | Research, maximum accuracy |
--integration single or --integration dual--integration dualp0p3 β Recommended--integration single--integration triple--integration dualp0p3--integration dualp0p3--integration dualp0p3 with vitl16_distilled--integration dualp0p3 with vit7b16--integration dualp0p3 + SAT-493M models# π DualP0P3 - Recommended for most satellite/aerial use cases
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitl16_distilled --integration dualp0p3 --dinoversion v3
# π Triple - Maximum performance (high memory)
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitl16 --integration triple --dinoversion v3
# β‘ Single - Fast and efficient
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitb16 --integration single --dinoversion v3
# π― Dual - High performance multi-scale
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitl16 --integration dual --dinoversion v3
π New: The DualP0P3 integration mode provides the optimal balance of performance and efficiency, especially for satellite and aerial imagery. It combines the benefits of preprocessing enhancement (P0) with targeted feature extraction at P3 level, making it ideal for production satellite segmentation workflows.
If you use this work in your research, please cite:
@misc{sompote2024dinov3yolosegment,
author = {Sompote},
title = {DinoV3-YOLO-Segment: Enhanced Instance Segmentation with Vision Transformer Integration},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/Sompote/DinoV3-YOLO-Segment}}
}
π Revolutionizing Instance Segmentation with Systematic Vision Transformer Integration
Made with β€οΈ by the AI Research Group, Department of Civil Engineering
King Mongkut's University of Technology Thonburi (KMUTT)
π₯ Get Started Now β’ π― Explore Models β’ ποΈ View Integration
Python
99.6%
Complete YOLOv12 instance segmentation model family with true DINOv3 enhancement for superior feature extraction and pixel-perfect mask prediction.
π Latest Update: NEW DualP0P3 Integration Mode (
--integration dualp0p3) - optimal balance for satellite imagery! Plus official DINOv3 models from Hugging Face with--dinoversion v3.
This repository provides 25 YOLOv12 segmentation model variants combining YOLOv12's efficient architecture with DINOv3's advanced vision transformer features for state-of-the-art instance segmentation performance with precise mask prediction.
--dinoversion v3π Citation: If you use this work, please cite our repository: https://github.com/Sompote/DinoV3-YOLO-Segment
| Category | Description | Models | DINO Integration | CLI Usage |
|---|---|---|---|---|
| Standard | Base YOLOv12 segmentation | 5 variants | None | No --use-dino flag |
| Single | DINO at P4 feature level | 5 variants | P4 enhancement | --integration single |
| Dual | DINO at P3 and P4 levels | 5 variants | P3 + P4 enhancement | --integration dual |
| π DualP0P3 | Balanced preprocessing + backbone | 5 variants | P0 + P3 enhancement | --integration dualp0p3 |
| π Triple | Ultimate performance | 5 variants | P0 + P3 + P4 enhancement | --integration triple |
| Model | mAPmask | mAPmask@0.5 | Speed (ms) | Parameters | Mask Quality |
|---|---|---|---|---|---|
| YOLOv12n-seg | 32.8 | 52.1 | 1.84 | 2.8M | High |
| YOLOv12s-seg | 38.6 | 59.2 | 2.84 | 9.8M | High |
| YOLOv12m-seg | 42.3 | 63.8 | 6.27 | 21.9M | Very High |
| YOLOv12l-seg | 43.2 | 64.5 | 7.61 | 28.8M | Very High |
| YOLOv12x-seg | 44.2 | 65.3 | 15.43 | 64.5M | Excellent |
Note: DINO-enhanced variants show 2-5% mask mAP improvements with enhanced boundary precision. DINOv3 models provide superior performance over DINOv2 with better feature extraction.
The DualP0P3 integration mode (--integration dualp0p3) provides a balanced approach between performance and memory efficiency:
Input Image β DINO3Preprocessor (P0) β Enhanced Features β YOLOv12 Backbone β DINO3Backbone (P3) β Segmentation Head
| Mode | Integration Points | Memory | Performance | Speed | Best Use Case |
|---|---|---|---|---|---|
| Single | P4 only | π’ Low | π‘ Good | π’ Fast | General tasks, development |
| Dual | P3 + P4 | π‘ Medium | π’ High | π‘ Medium | Dense scenes, small objects |
| π DualP0P3 | P0 + P3 | π‘ Medium | π’ High | π‘ Medium | Satellite imagery, balanced needs |
| Triple | P0 + P3 + P4 | π΄ High | π’ Maximum | π΄ Slow | Research, maximum accuracy |
# Standard segmentation with DualP0P3
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--integration dualp0p3 \
--dinoversion v3
# Satellite imagery segmentation (recommended)
python train_yolov12_segmentation.py \
--data satellite_data.yaml \
--model-size m \
--use-dino \
--dino-variant vitl16_distilled \
--integration dualp0p3 \
--dinoversion v3
This implementation supports both DINOv2 and DINOv3 models for maximum flexibility and cutting-edge performance:
| Version | Description | Compatibility | Recommended Use |
|---|---|---|---|
DINOv2 (--dinoversion v2) | Stable, widely tested | Full Hugging Face support | Production, proven performance |
DINOv3 (--dinoversion v3) | π Latest features, superior performance | β Full support via Hugging Face | Recommended for best results |
π New: DINOv3 models are now fully supported using official
facebook/dinov3-*-pretrain-lvd1689mmodels from Hugging Face!
| Variant | DINOv2 | DINOv3 | Parameters | Embed Dim | Dataset | Description | Memory | Recommended For |
|---|---|---|---|---|---|---|---|---|
vits16 | β | β | 21M | 384 | LVD-1689M | Small, fast | Low | Development, testing |
vitb16 | β | β | 86M | 768 | LVD-1689M | Balanced | Medium | General use, production |
vitl16 | β | β | 300M | 1024 | LVD-1689M | Large, high-performance | High | High-accuracy needs |
vitl16_distilled | β | β | 300M | 1024 | SAT-493M | ViT-L/16 Distilled (Satellite) | High | Satellite/aerial imagery |
vith16_plus | β | β | 840M | 1536 | LVD-1689M | ViT-H+/16 Distilled | Very High | Maximum performance |
vit7b16 | β | β | 6,716M | 4096 | SAT-493M | ViT-7B/16 (Satellite) | Extreme | Satellite imagery, research |
vit7b16_lvd | β | β | 6,716M | 4096 | LVD-1689M | ViT-7B/16 (Standard) | Extreme | Research, maximum scale |
# Single Integration: DINO enhancement at P4 level (DINOv2)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--integration single \
--dinoversion v2
# Dual Integration: DINO enhancement at P3+P4 levels (DINOv3)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration dual \
--dinoversion v3
# DualP0P3 Integration: DINO enhancement at P0+P3 levels (Balanced)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration dualp0p3 \
--dinoversion v3
# Triple Integration: DINO enhancement at P0+P3+P4 levels (Ultimate Performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3
# Satellite/Aerial Imagery: Use SAT-493M pretrained models for optimal performance
python train_yolov12_segmentation.py \
--data satellite_segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--integration dual \
--dinoversion v3
# Large-scale Satellite Imagery: ViT-7B/16 for maximum accuracy
python train_yolov12_segmentation.py \
--data satellite_segmentation_data.yaml \
--model-size x \
--use-dino \
--dino-variant vit7b16 \
--integration dual \
--dinoversion v3
Important: The
--dinoversionparameter is REQUIRED when using--use-dinoto specify which DINO version to use.
π‘ Tip: For satellite/aerial imagery segmentation, use
vitl16_distilledorvit7b16variants which are pretrained on SAT-493M dataset for optimal performance on overhead imagery.
DINOv3 models require Hugging Face authentication as they are gated models. You need to:
export HF_TOKEN="your_hf_token_here"
# or
export HUGGING_FACE_HUB_TOKEN="your_hf_token_here"
huggingface-cli login
Note: DINOv2 models work without authentication, while DINOv3 models provide superior performance but require the setup above.
# Clone repository
git clone https://github.com/Sompote/DinoV3-YOLO-Segment.git
cd DinoV3-YOLO-Segment
# Create conda environment
conda create -n yolov12-segment python=3.11
conda activate yolov12-segment
# Install dependencies
pip install -r requirements.txt
pip install transformers # For DINO models
pip install -e .
# 4. Setup Hugging Face authentication (REQUIRED for DINOv3 models)
# Method 1: Environment variable
export HF_TOKEN="your_token_here"
# Get your token from: https://huggingface.co/settings/tokens
# Method 2: Interactive login
huggingface-cli login
# Expected output:
# _| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|
# _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
# _|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|
# _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
# _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
#
# To log in, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
# Enter your token (input will not be visible):
# Add token as git credential? (Y/n) Y
# Token is valid (permission: fineGrained).
# The token `hf2` has been saved to /workspace/.hf_home/stored_tokens
# Verify installation
python -c "from ultralytics.nn.modules.block import DINO3Backbone; print('β
YOLOv12 Segmentation ready!')"
# Basic YOLOv12 segmentation training (recommended)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s
# With custom optimizer and parameters
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--optimizer SGD \
--lr 0.01 \
--momentum 0.937 \
--epochs 100 \
--batch-size 16 \
--imgsz 640
# Single-scale DINO enhancement with DINOv3 (balanced performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration single \
--optimizer AdamW \
--lr 0.002
# Dual-scale DINO enhancement with DINOv2 (best compatibility)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v2 \
--integration dual \
--optimizer AdamW \
--lr 0.002
# TRIPLE DINO integration with DINOv3 (ultimate performance - P0+P3+P4)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration triple \
--optimizer AdamW \
--lr 0.001 \
--momentum 0.9 \
--weight-decay 0.01
Control optimizer settings to prevent automatic parameter override:
# Available optimizers with recommended settings
--optimizer SGD --lr 0.01 --momentum 0.937 # Best for large datasets
--optimizer Adam --lr 0.001 --weight-decay 0.0005 # Fast convergence
--optimizer AdamW --lr 0.001 --weight-decay 0.01 # Best for DINO models
--optimizer RMSProp --lr 0.001 # Adaptive learning
--optimizer auto # Automatic selection (overrides manual settings)
Key Benefits:
--lr, --momentum, --weight-decay are respectedEnsure proper best weight saving to prevent best.pt = last.pt issues:
# Recommended settings for proper best weight detection
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--val \
--val-period 1 \
--patience 20 \
--save-best \
--plots \
--save-json \
--epochs 150
Best Practices for Weight Saving:
--val to ensure fitness calculation--patience 20-50 for early stopping--plots --save-json to track progress# Fast training for development (25x faster validation)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration single \
--val-period 5 \
--val-split 0.2 \
--fast-val
# Ultra-fast experimentation (100x faster validation)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--val-period 10 \
--val-split 0.1 \
--fast-val \
--epochs 100
# Production training with balanced validation
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration triple \
--val-period 5 \
--val-split 0.3 \
--epochs 300
For optimal performance on satellite, aerial, or overhead imagery, use models pretrained on the SAT-493M dataset:
| Use Case | Model Variant | Parameters | Integration | Best For |
|---|---|---|---|---|
| Standard Satellite | vitl16_distilled | 300M | dual | General satellite imagery |
| π Balanced Satellite | vitl16_distilled | 300M | dualp0p3 | Optimal memory/performance balance |
| High-Resolution Aerial | vit7b16 | 6,716M | dual | Ultra-high detail requirements |
| π Efficient High-Res | vit7b16 | 6,716M | dualp0p3 | Large models with memory constraints |
| Fast Satellite Processing | vitl16_distilled | 300M | single | Real-time applications |
# Standard satellite imagery segmentation
python train_yolov12_segmentation.py \
--data satellite_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--integration dual \
--dinoversion v3 \
--epochs 200
# π NEW: Balanced satellite imagery (recommended for most use cases)
python train_yolov12_segmentation.py \
--data satellite_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--integration dualp0p3 \
--dinoversion v3 \
--epochs 200
# Ultra-high resolution aerial imagery (research/precision applications)
python train_yolov12_segmentation.py \
--data aerial_dataset.yaml \
--model-size x \
--use-dino \
--dino-variant vit7b16 \
--integration dual \
--dinoversion v3 \
--batch-size 2 \
--epochs 300
# π NEW: Efficient high-resolution with ViT-7B (memory optimized)
python train_yolov12_segmentation.py \
--data aerial_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16 \
--integration dualp0p3 \
--dinoversion v3 \
--batch-size 4 \
--epochs 250
π‘ Why SAT-493M Models? These variants are specifically trained on 493M satellite images, making them particularly effective for:
- Land use classification segmentation
- Urban planning and infrastructure mapping
- Agricultural field boundary detection
- Environmental monitoring and change detection
- Disaster assessment and damage mapping
π DualP0P3 + SAT-493M: The combination of DualP0P3 integration with SAT-493M models provides optimal balance for satellite imagery:
- Lower memory usage than triple integration while maintaining high accuracy
- Enhanced preprocessing specifically tuned for satellite imagery characteristics
- Improved P3-level features for better boundary detection in aerial views
- Recommended for production satellite segmentation workflows
Dataset: Crack Segmentation Dataset from Roboflow
Performance comparison on crack segmentation dataset using YOLOv12 Large (L) variants:
| Model Configuration | mAPβ β (Box) | mAPβ β (Segment) | Model Type | DINO Integration |
|---|---|---|---|---|
| YOLOv12l-seg | 0.672 | 0.564 | Standard | None |
| YOLOv12l + Triple DINO (VIT-B) | 0.780 | 0.626 | Enhanced | P0+P3+P4 |
π― Triple DINO Integration Benefits:
π Performance Analysis:
Standard YOLOv12l-seg:
βββ Box mAPβ
β: 67.2%
βββ Segment mAPβ
β: 56.4%
βββ Configuration: Base segmentation model
Triple DINO YOLOv12l-seg:
βββ Box mAPβ
β: 78.0% (+10.8 points)
βββ Segment mAPβ
β: 62.6% (+6.2 points)
βββ Configuration: P0+P3+P4 DINO integration with VIT-B
π Crack Detection Capabilities:
For optimal crack segmentation results, use the Triple DINO configuration:
# Recommended training command for crack segmentation
python train_yolov12_segmentation.py \
--data crack_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration triple \
--optimizer AdamW \
--lr 0.001 \
--momentum 0.9 \
--weight-decay 0.01 \
--epochs 300 \
--batch-size 4 \
--patience 50 \
--name crack_triple_dino
The new --integration parameter simplifies DINO integration selection:
| Integration | Description | Enhancement Levels | Performance | Use Case |
|---|---|---|---|---|
single | DINO at P4 level only | P4 enhancement | Good | Balanced speed/accuracy |
dual | DINO at P3 and P4 levels | P3 + P4 enhancement | Better | High accuracy needs |
triple | DINO at P0, P3, and P4 levels | P0 + P3 + P4 enhancement | Best | Ultimate performance |
# Single integration (fastest)
python train_yolov12_segmentation.py \
--data data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration single
# Dual integration (balanced)
python train_yolov12_segmentation.py \
--data data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration dual
# Triple integration (ultimate)
python train_yolov12_segmentation.py \
--data data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--dinoversion v3 \
--integration triple
For maximum performance with the largest DINOv3 models:
# ViT-L/16 Distilled (300M parameters, satellite-trained) - Optimized large model
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16_distilled \
--dinoversion v3 \
--integration dual \
--epochs 250 \
--batch-size 4 \
--name vitL_distilled_satellite
# ViT-H+/16 Distilled (840M parameters) - High-performance variant
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vith16_plus \
--dinoversion v3 \
--integration dual \
--epochs 200 \
--batch-size 2 \
--name vitH_plus_experiment
# ViT-7B/16 (6.7B parameters, satellite-trained) - Ultimate performance (Satellite)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16 \
--dinoversion v3 \
--integration dual \
--epochs 150 \
--batch-size 1 \
--device cuda \
--name vit7b_ultimate_satellite
# ViT-7B/16 (6.7B parameters, LVD-1689M trained) - Ultimate performance (Standard)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16_lvd \
--dinoversion v3 \
--integration dual \
--epochs 150 \
--batch-size 1 \
--device cuda \
--name vit7b_ultimate_standard
# Triple integration for ViT-7B/16 (satellite-trained, ultimate performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16 \
--dinoversion v3 \
--integration triple \
--epochs 100 \
--batch-size 1 \
--name vit7b_triple_satellite
# Triple integration for ViT-7B/16 (LVD-1689M, ultimate performance)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vit7b16_lvd \
--dinoversion v3 \
--integration triple \
--epochs 100 \
--batch-size 1 \
--name vit7b_triple_standard
from ultralytics import YOLO
# Load trained segmentation model
model = YOLO('runs/segment/yolov12s-seg/weights/best.pt')
# Run segmentation inference
results = model('path/to/image.jpg')
results[0].show() # Display results with instance masks
# Access segmentation masks
for result in results:
masks = result.masks # Masks object
if masks is not None:
mask_data = masks.data # Raw mask data
mask_pixels = masks.xy # Mask contours
from ultralytics import YOLO
# Load DINO-enhanced segmentation model
model = YOLO('runs/segment/yolov12l-seg-dino3-triple-vitb16-dual/weights/best.pt')
# Enhanced segmentation inference with DINO
results = model('crack_image.jpg')
for result in results:
# Access enhanced masks from DINO features
if result.masks is not None:
print(f"Found {len(result.masks)} precise instance masks")
# Masks are more accurate due to DINO enhancement
masks = result.masks.data
The YOLOv12-DINO triple integration model demonstrates exceptional crack detection performance on real concrete structures:
Example 1: Multiple Crack Detection

Example 2: Single Crack with High Precision

Performance Highlights:
π― Crack Segmentation Performance:
Model: YOLOv12l + Triple DINO (P0+P3+P4)
βββ Instance Detection: 100% accuracy on visible cracks
βββ Confidence Range: 0.25 - 0.70 (robust detection)
βββ Mask Precision: Pixel-level boundary accuracy
βββ Processing Speed: Real-time inference
βββ Use Cases: Infrastructure inspection, quality control
# Train crack segmentation model with triple DINO integration
python train_yolov12_segmentation.py \
--data crack_dataset.yaml \
--model-size l \
--use-dino \
--dino-variant vitb16 \
--dinoversion v3 \
--integration triple \
--epochs 300 \
--batch-size 4
# Run crack detection inference with mask output
python inference.py \
--weights runs/segment/train/weights/best.pt \
--source concrete_images/ \
--save --save-masks \
--conf 0.25 \
--output crack_results/
Training can be dramatically sped up with smart validation strategies:
# π― Development Phase: Ultra-fast iteration (100x faster validation)
python train_yolov12_segmentation.py \
--data your_data.yaml \
--model-size s \
--val-period 10 \
--val-split 0.1 \
--fast-val \
--patience 15 \
--epochs 100
# π Production Phase: Balanced performance (25x faster validation)
python train_yolov12_segmentation.py \
--data your_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitb16 \
--integration dual \
--dinoversion v3 \
--val-period 5 \
--val-split 0.2 \
--fast-val \
--patience 25 \
--epochs 300
# π Final Training: Full validation for best results
python train_yolov12_segmentation.py \
--data your_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3 \
--val-period 2 \
--patience 50 \
--plots \
--save-json \
--epochs 300
| Strategy | Speed Gain | Best For | Example |
|---|---|---|---|
--val-period 10 | 10x faster | Long experiments, development | Skip validation 9/10 epochs |
--val-split 0.2 | 5x faster | Large datasets | Use 20% of validation data |
--fast-val | 2-3x faster | Quick iterations | Simplified metrics |
--patience 20 | Early stopping | Prevent overfitting | Stop if no improvement for 20 epochs |
--cache ram | 20-50% faster | Systems with sufficient RAM | Cache dataset in memory |
| Combined | 50-100x faster | Rapid experimentation | Use all strategies together |
All hyperparameters are configured through CLI arguments in train_yolov12_segmentation.py and default values from ultralytics/cfg/default.yaml:
| Parameter | CLI Argument | Default | Range | Description |
|---|---|---|---|---|
| Learning Rate Control | ||||
| Initial LR | --lr | 0.01 | 0.0001-0.1 | Initial learning rate (SGD=1E-2, Adam=1E-3) |
| Final LR Factor | N/A (default.yaml) | 0.01 | 0.001-0.1 | Final learning rate = lr0 Γ lrf |
| Momentum | --momentum | 0.937 | 0.8-0.99 | SGD momentum / Adam beta1 |
| Weight Decay | --weight-decay | 0.0005 | 0.0001-0.01 | L2 regularization strength |
| Warmup Strategy | ||||
| Warmup Epochs | --warmup-epochs | 3 | 0-20 | Linear warmup duration |
| Warmup Momentum | N/A (default.yaml) | 0.8 | 0.5-0.95 | Initial momentum during warmup |
| Warmup Bias LR | N/A (default.yaml) | 0.0 | 0.0-0.1 | Bias learning rate during warmup |
| Training Control | ||||
| Epochs | --epochs | auto | 50-1000 | Training duration |
| Batch Size | --batch-size | auto | 1-128 | Samples per batch |
| Patience | --patience | 10 | 5-200 | Early stopping patience |
| Image Size | --imgsz | 640 | 320-1280 | Input resolution |
| Component | CLI Argument | Default | Range | Description |
|---|---|---|---|---|
| Box Loss | --box-loss-gain | 7.5 | 1.0-20.0 | Bounding box regression weight |
| Classification Loss | --cls-loss-gain | 0.5 | 0.1-2.0 | Class prediction weight |
| DFL Loss | --dfl-loss-gain | 1.5 | 0.5-5.0 | Distribution Focal Loss weight |
| Category | CLI Argument | Default | Range | Description |
|---|---|---|---|---|
| Color Augmentation | ||||
| HSV Hue | --hsv-h | 0.015 | 0.0-0.1 | Hue shift range |
| HSV Saturation | --hsv-s | 0.7 | 0.0-1.0 | Saturation scaling |
| HSV Value | --hsv-v | 0.4 | 0.0-1.0 | Brightness scaling |
| Geometric Augmentation | ||||
| Rotation | --degrees | 0.0 | 0.0-45.0 | Random rotation degrees |
| Translation | --translate | 0.1 | 0.0-0.5 | Position shift fraction |
| Scaling | --scale | 0.5 | 0.0-1.0 | Size variation range |
| Shearing | --shear | 0.0 | 0.0-20.0 | Shear transformation |
| Perspective | --perspective | 0.0 | 0.0-0.001 | Perspective distortion |
| Flip Augmentation | ||||
| Vertical Flip | --flipud | 0.0 | 0.0-1.0 | Up-down flip probability |
| Horizontal Flip | --fliplr | 0.5 | 0.0-1.0 | Left-right flip probability |
| Advanced Augmentation | ||||
| Mosaic | --mosaic | 1.0 | 0.0-1.0 | 4-image mosaic probability |
| Mixup | --mixup | 0.0 | 0.0-1.0 | Image blending probability |
| Copy-Paste | --copy-paste | 0.1 | 0.0-1.0 | Instance copy-paste (segmentation) |
| Parameter | CLI Argument | Default | Description |
|---|---|---|---|
| Overlap Masks | --overlap-mask | True | Allow overlapping instance masks |
| Mask Ratio | --mask-ratio | 4 | Mask downsample ratio (1,2,4,8) |
| Single Class | --single-cls | False | Treat as single-class problem |
For unstable training with NaN losses or exploding gradients:
# Conservative Stable Training
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.001 \
--weight-decay 0.001 \
--warmup-epochs 15 \
--momentum 0.9 \
--box-loss-gain 3.0 \
--cls-loss-gain 0.25 \
--dfl-loss-gain 0.75 \
--batch-size 8 \
--patience 25
# Phase 1: Warmup Training (50 epochs)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.005 \
--warmup-epochs 20 \
--epochs 50 \
--patience 15 \
--name phase1_warmup
# Phase 2: Full Training (resume from phase 1)
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.01 \
--epochs 200 \
--patience 30 \
--resume runs/segment/phase1_warmup/weights/last.pt \
--name phase2_full
Nano Models (n) - Fast Training:
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size n \
--lr 0.01 \
--batch-size 32 \
--weight-decay 0.0005 \
--warmup-epochs 3 \
--epochs 150
Large Models (l,x) - Stable Training:
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--lr 0.003 \
--batch-size 6 \
--weight-decay 0.0003 \
--warmup-epochs 10 \
--patience 50 \
--epochs 300
DINO Single-Scale (Stable):
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--use-dino \
--dino-variant vitb16 \
--integration single \
--dinoversion v3 \
--lr 0.008 \
--weight-decay 0.0003 \
--warmup-epochs 5 \
--batch-size 8
DINO Dual-Scale (Advanced):
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration dual \
--dinoversion v2 \
--lr 0.002 \
--weight-decay 0.0001 \
--warmup-epochs 15 \
--batch-size 4 \
--patience 50
DINO Triple Integration (Expert):
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3 \
--lr 0.0015 \
--weight-decay 0.00005 \
--warmup-epochs 20 \
--batch-size 2 \
--patience 75 \
--epochs 400
| Scenario | Recommended LR | Reasoning |
|---|---|---|
| Small datasets (<1000 images) | 0.005-0.008 | Prevent overfitting |
| Large datasets (>10k images) | 0.01-0.02 | Faster convergence |
| DINO integration | 0.002-0.008 | Complex model needs stability |
| Fine-tuning | 0.001-0.003 | Preserve pretrained features |
| High resolution (>1024px) | 0.003-0.006 | More stable gradients |
# Auto-batch size detection
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--batch-size -1 # Auto-detect maximum batch size
# Manual batch size based on GPU memory
# RTX 3060 (12GB): batch-size 8-16
# RTX 4090 (24GB): batch-size 16-32
# A100 (40GB): batch-size 32-64
Balanced Detection + Segmentation:
--box-loss-gain 7.5 --cls-loss-gain 0.5 --dfl-loss-gain 1.5
Prioritize Mask Quality:
--box-loss-gain 5.0 --cls-loss-gain 1.0 --dfl-loss-gain 2.0
Prioritize Detection Accuracy:
--box-loss-gain 10.0 --cls-loss-gain 0.3 --dfl-loss-gain 1.0
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size l \
--use-dino \
--dino-variant vitl16 \
--integration triple \
--dinoversion v3 \
--lr 0.002 \
--weight-decay 0.0001 \
--warmup-epochs 25 \
--patience 75 \
--box-loss-gain 6.0 \
--cls-loss-gain 0.8 \
--dfl-loss-gain 2.0 \
--mixup 0.2 \
--copy-paste 0.4 \
--epochs 500 \
--cache ram
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size s \
--lr 0.015 \
--batch-size 24 \
--warmup-epochs 2 \
--patience 15 \
--val-period 5 \
--fast-val \
--epochs 100
python train_yolov12_segmentation.py \
--data segmentation_data.yaml \
--model-size m \
--batch-size 4 \
--lr 0.005 \
--weight-decay 0.001 \
--warmup-epochs 10 \
--cache False \
--workers 4
| File | Description | Usage |
|---|---|---|
| Training Scripts | ||
train_yolov12_segmentation.py | Main segmentation training script | CLI interface with fast validation |
train_yolov12_dino.py | DINO detection training script | For detection tasks |
| Inference & Demo | ||
inference.py | Segmentation inference script | Batch processing with mask output |
app.py | Gradio web interface | Interactive demo |
| Documentation | ||
FAST_VALIDATION_GUIDE.md | Fast validation strategies | Speed optimization guide |
SEGMENTATION_CLI_GUIDE.md | Complete CLI reference | All training parameters |
README_SEGMENTATION.md | Segmentation overview | Task-specific guide |
DINO_FIX_DOCUMENTATION.md | Technical fixes | Troubleshooting guide |
| Model Size | Standard | Single Integration | Dual Integration | Triple Integration |
|---|---|---|---|---|
| Nano | yolov12n-seg.yaml | yolov12n-dino3-vitb16-single-seg.yaml | yolov12n-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Small | yolov12s-seg.yaml | yolov12s-dino3-vitb16-single-seg.yaml | yolov12s-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Medium | yolov12m-seg.yaml | yolov12m-dino3-vitb16-single-seg.yaml | yolov12m-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Large | yolov12l-seg.yaml | yolov12l-dino3-vitb16-single-seg.yaml | yolov12l-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Extra | yolov12x-seg.yaml | yolov12x-dino3-vitb16-single-seg.yaml | yolov12x-dino3-vitb16-dual-seg.yaml | Uses dual + preprocessing |
| Directory | Contents | Purpose |
|---|---|---|
runs/segment/ | Training results, weights, metrics | Model outputs |
safety_test_results/ | Test images and predictions | Validation samples |
assets/ | Architecture diagrams (SVG) | Technical documentation |
logs/ | Training performance logs | Model benchmarks |
| File | Description |
|---|---|
requirements.txt | Python dependencies |
requirements_rtx5090.txt | RTX 5090 specific requirements |
pyproject.toml | Project configuration |
ultralytics/cfg/models/v12/ | All model architecture configs |
ultralytics/cfg/datasets/ | Dataset configuration templates |
# segmentation_data.yaml
path: /path/to/dataset
train: images/train
val: images/val
test: images/test
nc: 1 # number of classes
names: ['crack'] # class names
# Segmentation-specific paths
train_masks: masks/train # Training masks directory
val_masks: masks/val # Validation masks directory
# Show all available options
python train_yolov12_segmentation.py --help
# Basic segmentation training
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size s
# DINO-enhanced training (recommended) - simplified with --integration
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size s --use-dino --dino-variant vitb16 --dinoversion v3 --integration single
# π NEW: DualP0P3 integration (balanced performance/memory)
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size s --use-dino --dino-variant vitb16 --dinoversion v3 --integration dualp0p3
# Advanced configuration with early stopping - simplified with --integration
python train_yolov12_segmentation.py --data segmentation_data.yaml --model-size l --use-dino --dino-variant vitl16 --dinoversion v2 --integration dual --epochs 150 --batch-size 8 --patience 20 --name my-experiment
| Category | Arguments | Description |
|---|---|---|
| Required | --data, --model-size | Dataset YAML and model size (n/s/m/l/x) |
| DINO | --use-dino, --dino-variant, --integration, --dinoversion | DINO enhancement options (single/dual/dualp0p3/triple integration, v2/v3 support, dinoversion REQUIRED) |
| Optimizer | --optimizer, --lr, --momentum, --weight-decay | Optimizer control (SGD/Adam/AdamW/RMSProp/auto) |
| Fast Validation | --val-period, --val-split, --fast-val | Speed optimization (25-100x faster) |
| Segmentation | --overlap-mask, --mask-ratio, --box-loss-gain | Segmentation-specific parameters |
| Training | --epochs, --batch-size, --device, --patience | Core training configuration |
| Experiment | --name, --project, --resume | Experiment management |
ultralytics/cfg/models/v12/
βββ Standard Segmentation
β βββ yolov12n-seg.yaml
β βββ yolov12s-seg.yaml
β βββ yolov12m-seg.yaml
β βββ yolov12l-seg.yaml
β βββ yolov12x-seg.yaml
βββ Single-Scale DINO
β βββ yolov12n-dino3-vitb16-single-seg.yaml
β βββ yolov12s-dino3-vitb16-single-seg.yaml
β βββ yolov12m-dino3-vitb16-single-seg.yaml
β βββ yolov12l-dino3-vitb16-single-seg.yaml
β βββ yolov12x-dino3-vitb16-single-seg.yaml
βββ Dual-Scale DINO
β βββ yolov12n-dino3-vitb16-dual-seg.yaml
β βββ yolov12s-dino3-vitb16-dual-seg.yaml
β βββ yolov12m-dino3-vitb16-dual-seg.yaml
β βββ yolov12l-dino3-vitb16-dual-seg.yaml
β βββ yolov12x-dino3-vitb16-dual-seg.yaml
βββ π DualP0P3 Integration (uses preprocessing configs + P3 enhancement)
β βββ Built from preprocessing configs + automatic P3 enhancement
β βββ Configured via --integration dualp0p3
βββ Triple Integration (uses dual configs + preprocessing)
βββ Built from dual configs + automatic preprocessing
βββ Configured via --integration triple
--integration single)--use-dino --dino-variant vitb16 --integration single --dinoversion v3--integration dual)--use-dino --dino-variant vitl16 --integration dual --dinoversion v3--integration dualp0p3)--use-dino --dino-variant vitl16 --integration dualp0p3 --dinoversion v3--integration triple)--use-dino --dino-variant vitl16 --integration triple --dinoversion v3yolov12n
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('yolov12{n/s/m/l/x}.pt')
model.export(format="engine", half=True) # or format="onnx"
2025/09/22: π NEW: Complete YOLOv12 Segmentation with DINOv3 - Added comprehensive instance segmentation support with 20 model variants! Features systematic architecture with 4 integration approaches (Standard, Single-Scale DINO, Dual-Scale DINO, Preprocessing DINO), and support for all model sizes (n,s,m,l,x). Now includes precise mask prediction with 32 prototypes and 256 feature dimensions for superior segmentation accuracy.
2025/02/19: Base YOLOv12 architecture established with attention-centric design for enhanced feature extraction.
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.
This repository provides 5 distinct integration strategies for combining DINO with YOLOv12 segmentation, each optimized for different use cases:
| Integration Mode | Points | Memory | Performance | Speed | Training Time | Best Use Case |
|---|---|---|---|---|---|---|
| Standard | None | π’ Lowest | π‘ Baseline | π’ Fastest | π’ Shortest | Development, testing |
| Single | P4 | π’ Low | π‘ Good | π’ Fast | π’ Short | General tasks, production |
| Dual | P3+P4 | π‘ Medium | π’ High | π‘ Medium | π‘ Medium | Dense scenes, small objects |
| π DualP0P3 | P0+P3 | π‘ Medium | π’ High | π‘ Medium | π‘ Medium | Satellite imagery, balanced |
| Triple | P0+P3+P4 | π΄ High | π’ Maximum | π΄ Slow | π΄ Long | Research, maximum accuracy |
--integration single or --integration dual--integration dualp0p3 β Recommended--integration single--integration triple--integration dualp0p3--integration dualp0p3--integration dualp0p3 with vitl16_distilled--integration dualp0p3 with vit7b16--integration dualp0p3 + SAT-493M models# π DualP0P3 - Recommended for most satellite/aerial use cases
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitl16_distilled --integration dualp0p3 --dinoversion v3
# π Triple - Maximum performance (high memory)
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitl16 --integration triple --dinoversion v3
# β‘ Single - Fast and efficient
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitb16 --integration single --dinoversion v3
# π― Dual - High performance multi-scale
python train_yolov12_segmentation.py --data your_data.yaml --model-size s --use-dino --dino-variant vitl16 --integration dual --dinoversion v3
π New: The DualP0P3 integration mode provides the optimal balance of performance and efficiency, especially for satellite and aerial imagery. It combines the benefits of preprocessing enhancement (P0) with targeted feature extraction at P3 level, making it ideal for production satellite segmentation workflows.
If you use this work in your research, please cite:
@misc{sompote2024dinov3yolosegment,
author = {Sompote},
title = {DinoV3-YOLO-Segment: Enhanced Instance Segmentation with Vision Transformer Integration},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/Sompote/DinoV3-YOLO-Segment}}
}
π Revolutionizing Instance Segmentation with Systematic Vision Transformer Integration
Made with β€οΈ by the AI Research Group, Department of Civil Engineering
King Mongkut's University of Technology Thonburi (KMUTT)
π₯ Get Started Now β’ π― Explore Models β’ ποΈ View Integration
Python
99.6%