AgentSkillsCN

using-ultralytics

专家系统,用于 Ultralytics YOLOv8/v9/v10。提供关于训练、检测、分割与部署的文档。

SKILL.md
--- frontmatter
name: using-ultralytics
description: Expert system for Ultralytics YOLOv8/v9/v10. Provides documentation on training, detection, segmentation, and deployment.

Ultralytics (YOLO) Skill

Expert system for Ultralytics YOLO models (Object Detection, Segmentation, Classification).

When to Use This Skill

This skill should be triggered when:

  • Training YOLO models (v8, v9, v10, v11)
  • Running inference (detection, segmentation, pose estimation)
  • Exporting models to ONNX, TensorRT, CoreML, etc.
  • Configuring datasets (COCO, custom YAML)
  • Configuring datasets (COCO, custom YAML)
  • Debugging training pipelines or performance issues
  • Training Config Requests: "Set batch size to 128", "Train on CPU", "Use optimizer SGD"

Logic Flow & Decision Tree

0. Configuration Gatekeeper (The OOM Stopper)

When: User proposes specific training parameters (Batch Size, Device, Image Size). Action:

  1. PAUSE. Perform a "Mental Simulation" of resource usage.
  2. Calculate (Heuristic):
    • YOLOv8x + Batch 12840GB+ VRAM Needed.
    • CPU Training + Large Model = Extremely Slow (Days).
  3. BLOCK/WARN:

    "Training YOLOv8x with Batch 128 requires ~40GB VRAM (A100 class). Your environment (Laptop GPU/CPU) will crash (OOM). Recommendation: Batch 4 or 8."

Pre-Flight Checks (Mandatory)

Before starting any training run, you MUST:

  1. Check GPU Resources (CUDA/ROCm):

    • Verify device availability: torch.cuda.is_available()
    • Check VRAM capacity: nvidia-smi or torch.cuda.get_device_properties(0).total_memory
    • Auto-Batch Suggestion:
      • < 6GB VRAM: batch=4 or batch=8
      • 6GB - 12GB VRAM: batch=16
      • 12GB VRAM: batch=32+

      • Tip: Use batch=-1 for YOLOv8's auto-batch feature if unsure.
  2. Verify Data Leakage:

    • Ensure NO overlap between Train and Val image files.

Quick Reference

Common Patterns

Pattern 1: Train Model (CLI)

bash
yolo detect train data=coco128.yaml model=yolov8n.pt epochs=100 imgsz=640

Pattern 2: Predict (CLI)

bash
yolo detect predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg'

Pattern 3: Export Model

bash
yolo export model=yolov8n.pt format=onnx

Pattern 4: Train (Python)

python
from ultralytics import YOLO

model = YOLO("yolov8n.pt")
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)

Pattern 5: Predict (Python)

python
from ultralytics import YOLO

model = YOLO("yolov8n.pt")
results = model("path/to/image.jpg")

Pattern 6: Segmentation Training

python
model = YOLO("yolov8n-seg.pt")
model.train(data="coco8-seg.yaml", epochs=100)

Reference Files

This skill includes comprehensive documentation in references/:

  • guides.md - Step-by-step guides for common tasks.
  • models.md - Details on available model architectures.
  • datasets.md - How to format and use datasets.
  • tasks.md - Explanation of tasks (Detect, Segment, Classify, Pose, OBB).
  • modes.md - Modes of operation (Train, Val, Predict, Export, Track).
  • detect.md - Specifics for object detection.

Use view_file to read these files for in-depth information.

usage

For Beginners

Start with references/tasks.md to understand the capabilities (Detect, Segment, etc.) and references/modes.md for the workflow (Train -> Val -> Predict).

For Custom Training

Refer to references/datasets.md to ensure your data YAML and directory structure are correct before starting training.

For Deployment

Check references/guides.md (or export documentation) for details on optimizing models for different hardware using yolo export.