Ultralytics YOLO

8.4.36 · active · verified Thu Apr 09

Ultralytics YOLO is a cutting-edge deep learning library for state-of-the-art computer vision tasks including object detection, instance segmentation, pose estimation, and image classification, built around the YOLO architecture. It maintains a rapid release cadence, frequently delivering stability improvements and new features, with the current stable version being 8.4.36.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates loading a pretrained YOLOv8 nano model, performing inference on an image, and exporting the model to ONNX format. While training is commented out for brevity, the `model.train()` method is the standard way to fine-tune or train models from scratch.

from ultralytics import YOLO
import os

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Use the model for training (example with dummy data for brevity)
# For a real run, ensure 'coco128.yaml' or your custom data path is valid
# You might need to download a dataset like coco128 first.
# For a quick local test, you can uncomment and try to train on a tiny dataset:
# try:
#     results = model.train(data='coco128.yaml', epochs=1, imgsz=640)
# except Exception as e:
#     print(f"Training failed (might be missing dataset or GPU): {e}")

# Use the model for prediction on an image
image_path = 'https://ultralytics.com/images/bus.jpg'
results = model(image_path)

# Process results
for r in results:
    print(f"Detected {len(r.boxes)} objects.")
    # r.show()  # Uncomment to display the image with detections

# Export the model to ONNX format
model.export(format='onnx')

view raw JSON →