# YOLOv8 Detection

Run real-time object detection with Ultralytics YOLOv8 and YOLOv11.

{% hint style="success" %}
All examples can be run on GPU servers rented through [CLORE.AI Marketplace](https://clore.ai/marketplace).
{% endhint %}

{% hint style="info" %}
**Update: YOLOv11 (2025) — 22% Faster**

YOLOv11 is now available via the same `ultralytics` package. It delivers **22% faster inference** and improved mAP over YOLOv8, with the same simple API. New features include Oriented Bounding Box (OBB) detection. Upgrade by running `pip install -U ultralytics`.
{% endhint %}

## Renting on CLORE.AI

1. Visit [CLORE.AI Marketplace](https://clore.ai/marketplace)
2. Filter by GPU type, VRAM, and price
3. Choose **On-Demand** (fixed rate) or **Spot** (bid price)
4. Configure your order:
   * Select Docker image
   * Set ports (TCP for SSH, HTTP for web UIs)
   * Add environment variables if needed
   * Enter startup command
5. Select payment: **CLORE**, **BTC**, or **USDT/USDC**
6. Create order and wait for deployment

### Access Your Server

* Find connection details in **My Orders**
* Web interfaces: Use the HTTP port URL
* SSH: `ssh -p <port> root@<proxy-address>`

## What is YOLOv8?

YOLOv8 is a high-performance YOLO model offering:

* Object detection
* Instance segmentation
* Pose estimation
* Image classification
* Object tracking

## What is YOLOv11?

YOLOv11 (2025) is the latest generation, adding:

* **22% faster inference** vs YOLOv8
* Higher mAP across all model sizes
* **Oriented Bounding Box (OBB)** detection — new task
* Improved architecture (C3k2 blocks, SPPF, C2PSA)
* Same `ultralytics` package, drop-in replacement

### Supported Tasks (YOLOv11)

| Task       | Suffix   | Description                                         |
| ---------- | -------- | --------------------------------------------------- |
| `detect`   | *(none)* | Object detection with bounding boxes                |
| `segment`  | `-seg`   | Instance segmentation with masks                    |
| `classify` | `-cls`   | Image classification                                |
| `pose`     | `-pose`  | Human pose estimation                               |
| `obb`      | `-obb`   | **NEW** Oriented bounding boxes (rotated detection) |

## Model Sizes

### YOLOv8 Models

| Model   | Size  | mAP  | Speed (RTX 3090) |
| ------- | ----- | ---- | ---------------- |
| YOLOv8n | 3.2M  | 37.3 | \~1ms            |
| YOLOv8s | 11.2M | 44.9 | \~2ms            |
| YOLOv8m | 25.9M | 50.2 | \~4ms            |
| YOLOv8l | 43.7M | 52.9 | \~6ms            |
| YOLOv8x | 68.2M | 53.9 | \~8ms            |

### YOLOv11 Models

| Model   | Size  | mAP  | Speed (RTX 3090) |
| ------- | ----- | ---- | ---------------- |
| yolo11n | 2.6M  | 39.5 | \~0.8ms          |
| yolo11s | 9.4M  | 47.0 | \~1.5ms          |
| yolo11m | 20.1M | 51.5 | \~3.2ms          |
| yolo11l | 25.3M | 53.4 | \~4.7ms          |
| yolo11x | 56.9M | 54.7 | \~6.5ms          |

### YOLOv8 vs YOLOv11 Comparison

| Metric                | YOLOv8x | yolo11x | Improvement      |
| --------------------- | ------- | ------- | ---------------- |
| Parameters            | 68.2M   | 56.9M   | **-17% smaller** |
| mAP50-95 (COCO)       | 53.9    | 54.7    | **+0.8 mAP**     |
| Inference (RTX 3090)  | \~8ms   | \~6.5ms | **+22% faster**  |
| FPS (RTX 3090, 640px) | \~150   | \~183   | **+22% faster**  |
| OBB Task              | ❌       | ✅       | **New in v11**   |

## Quick Deploy

**Docker Image:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
```

**Ports:**

```
22/tcp
7860/http
```

**Command (YOLOv11):**

```bash
pip install ultralytics gradio && \
python -c "
import gradio as gr
from ultralytics import YOLO
from PIL import Image

model = YOLO('yolo11m.pt')

def detect(image):
    results = model(image)
    return Image.fromarray(results[0].plot())

demo = gr.Interface(fn=detect, inputs=gr.Image(type='pil'), outputs=gr.Image(), title='YOLOv11 Detection')
demo.launch(server_name='0.0.0.0', server_port=7860)
"
```

## Accessing Your Service

After deployment, find your `http_pub` URL in **My Orders**:

1. Go to **My Orders** page
2. Click on your order
3. Find the `http_pub` URL (e.g., `abc123.clorecloud.net`)

Use `https://YOUR_HTTP_PUB_URL` instead of `localhost` in examples below.

## Installation

```bash
pip install ultralytics
```

Same package for both YOLOv8 and YOLOv11. Upgrade to get YOLOv11:

```bash
pip install -U ultralytics
```

## YOLOv11 Object Detection

### Basic Detection with yolo11m

```python
from ultralytics import YOLO
from PIL import Image

# Load YOLOv11 medium model
model = YOLO('yolo11m.pt')

# Run inference
results = model('image.jpg')

# Show results
results[0].show()

# Save results
results[0].save('output.jpg')
```

### Get Detections

```python
results = model('image.jpg')

for result in results:
    boxes = result.boxes
    for box in boxes:
        # Coordinates
        x1, y1, x2, y2 = box.xyxy[0].tolist()

        # Confidence
        conf = box.conf[0].item()

        # Class
        cls = int(box.cls[0].item())
        name = model.names[cls]

        print(f"{name}: {conf:.2f} at ({x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f})")
```

### Batch Processing

```python
from ultralytics import YOLO
import os

model = YOLO('yolo11m.pt')

input_dir = './images'
output_dir = './detected'
os.makedirs(output_dir, exist_ok=True)

# Process all images
results = model(input_dir, save=True, project=output_dir)
```

## YOLOv11 Tasks

### Instance Segmentation

```python
from ultralytics import YOLO

# Load YOLOv11 segmentation model
model = YOLO('yolo11m-seg.pt')

results = model('image.jpg')

for result in results:
    masks = result.masks  # Segmentation masks
    if masks is not None:
        for mask in masks.data:
            # mask is a binary tensor
            pass
```

### Pose Estimation

```python
from ultralytics import YOLO

# Load YOLOv11 pose model
model = YOLO('yolo11m-pose.pt')

results = model('image.jpg')

for result in results:
    keypoints = result.keypoints
    if keypoints is not None:
        for kp in keypoints.data:
            # 17 keypoints: nose, eyes, ears, shoulders, elbows, wrists, hips, knees, ankles
            pass
```

### Classification

```python
from ultralytics import YOLO

# Load YOLOv11 classification model
model = YOLO('yolo11m-cls.pt')

results = model('image.jpg')
for result in results:
    # Top-1 class and confidence
    top1 = result.probs.top1
    top1conf = result.probs.top1conf.item()
    print(f"Class: {result.names[top1]} ({top1conf:.2f})")
```

### Oriented Bounding Box (OBB) — NEW in YOLOv11

OBB detects objects at any rotation angle — perfect for aerial/satellite imagery, document scanning, and text detection.

```python
from ultralytics import YOLO

# Load YOLOv11 OBB model
model = YOLO('yolo11m-obb.pt')

results = model('aerial_image.jpg')

for result in results:
    obb = result.obb
    if obb is not None:
        for box in obb:
            # Rotated box: x_center, y_center, width, height, angle
            xywhr = box.xywhr[0].tolist()
            conf = box.conf[0].item()
            cls = int(box.cls[0].item())
            print(f"{result.names[cls]}: {conf:.2f} rotated box: {xywhr}")
```

## Video Processing

### Process Video

```python
from ultralytics import YOLO

model = YOLO('yolo11m.pt')

# Process video
results = model('video.mp4', save=True)
```

### Real-Time Webcam

```python
from ultralytics import YOLO
import cv2

model = YOLO('yolo11n.pt')  # Use nano model for real-time

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    results = model(frame)
    annotated = results[0].plot()

    cv2.imshow('YOLOv11', annotated)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
```

### Save Processed Video

```python
from ultralytics import YOLO
import cv2

model = YOLO('yolo11m.pt')

cap = cv2.VideoCapture('input.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break

    results = model(frame)
    annotated = results[0].plot()
    out.write(annotated)

cap.release()
out.release()
```

## Object Tracking

```python
from ultralytics import YOLO

model = YOLO('yolo11m.pt')

# Track objects in video
results = model.track('video.mp4', save=True, tracker='bytetrack.yaml')

# Access tracking IDs
for result in results:
    boxes = result.boxes
    if boxes.id is not None:
        track_ids = boxes.id.tolist()
```

## Custom Training

### Prepare Dataset

```yaml

# dataset.yaml
path: /workspace/dataset
train: images/train
val: images/val

names:
  0: cat
  1: dog
  2: bird
```

### Train YOLOv11

```python
from ultralytics import YOLO

# Load pretrained YOLOv11 model
model = YOLO('yolo11n.pt')

# Train
results = model.train(
    data='dataset.yaml',
    epochs=100,
    imgsz=640,
    batch=16,
    device=0
)
```

### Training Arguments

```python
model.train(
    data='dataset.yaml',
    epochs=100,
    imgsz=640,
    batch=16,
    device=0,
    workers=8,
    patience=50,         # Early stopping
    save=True,
    save_period=10,      # Save every N epochs
    cache=True,          # Cache images
    amp=True,            # Mixed precision
    lr0=0.01,
    lrf=0.01,
    momentum=0.937,
    weight_decay=0.0005,
    warmup_epochs=3.0,
    box=7.5,
    cls=0.5,
    dfl=1.5,
    augment=True,
    hsv_h=0.015,
    hsv_s=0.7,
    hsv_v=0.4,
    flipud=0.0,
    fliplr=0.5,
    mosaic=1.0,
    mixup=0.0,
)
```

## Export Model

```python
from ultralytics import YOLO

model = YOLO('yolo11m.pt')

# Export to different formats
model.export(format='onnx')           # ONNX
model.export(format='tensorrt')       # TensorRT
model.export(format='openvino')       # OpenVINO
model.export(format='coreml')         # CoreML
model.export(format='tflite')         # TensorFlow Lite
```

## API Server

```python
from fastapi import FastAPI, UploadFile
from fastapi.responses import JSONResponse
from ultralytics import YOLO
from PIL import Image
import io

app = FastAPI()
model = YOLO('yolo11m.pt')

@app.post("/detect")
async def detect(file: UploadFile):
    contents = await file.read()
    image = Image.open(io.BytesIO(contents))

    results = model(image)

    detections = []
    for box in results[0].boxes:
        detections.append({
            "class": model.names[int(box.cls[0])],
            "confidence": float(box.conf[0]),
            "bbox": box.xyxy[0].tolist()
        })

    return JSONResponse(content={"detections": detections})

@app.post("/segment")
async def segment(file: UploadFile):
    contents = await file.read()
    image = Image.open(io.BytesIO(contents))

    model_seg = YOLO('yolo11m-seg.pt')
    results = model_seg(image)

    # Return annotated image
    annotated = results[0].plot()
    # ... convert and return

# Run: uvicorn server:app --host 0.0.0.0 --port 8000
```

## Performance Optimization

### TensorRT Export

```python
model = YOLO('yolo11m.pt')
model.export(format='tensorrt', half=True)

# Use exported model
model_trt = YOLO('yolo11m.engine')
results = model_trt('image.jpg')
```

### Batch Inference

```python

# Process multiple images at once
images = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg']
results = model(images, batch=4)
```

## Performance Benchmarks

### YOLOv11 FPS (640px input)

| Model   | GPU      | FPS    |
| ------- | -------- | ------ |
| yolo11n | RTX 3090 | \~1100 |
| yolo11s | RTX 3090 | \~730  |
| yolo11m | RTX 3090 | \~370  |
| yolo11x | RTX 3090 | \~183  |
| yolo11x | RTX 4090 | \~305  |

### YOLOv8 FPS (640px input) — Previous Generation

| Model   | GPU      | FPS   |
| ------- | -------- | ----- |
| YOLOv8n | RTX 3090 | \~900 |
| YOLOv8s | RTX 3090 | \~600 |
| YOLOv8m | RTX 3090 | \~300 |
| YOLOv8x | RTX 3090 | \~150 |
| YOLOv8x | RTX 4090 | \~250 |

## Troubleshooting

### Out of Memory

```python

# Use smaller model
model = YOLO('yolo11n.pt')

# Or reduce image size
results = model('image.jpg', imgsz=320)
```

### Slow Processing

* Use TensorRT export
* Use smaller model (yolo11n or yolo11s)
* Reduce image size

### Low Accuracy

* Use larger model (yolo11x instead of yolo11n)
* Train on custom data
* Increase image size

## Cost Estimate

Typical CLORE.AI marketplace rates (as of 2025):

| GPU       | Hourly Rate | Daily Rate | 4-Hour Session |
| --------- | ----------- | ---------- | -------------- |
| RTX 3060  | \~$0.03     | \~$0.70    | \~$0.12        |
| RTX 3090  | \~$0.06     | \~$1.50    | \~$0.25        |
| RTX 4090  | \~$0.10     | \~$2.30    | \~$0.40        |
| A100 40GB | \~$0.17     | \~$4.00    | \~$0.70        |
| A100 80GB | \~$0.25     | \~$6.00    | \~$1.00        |

*Prices vary by provider and demand. Check* [*CLORE.AI Marketplace*](https://clore.ai/marketplace) *for current rates.*

**Save money:**

* Use **Spot** market for flexible workloads (often 30-50% cheaper)
* Pay with **CLORE** tokens
* Compare prices across different providers

## Next Steps

* [Segment Anything](https://docs.clore.ai/guides/image-processing/segment-anything) - Advanced segmentation
* Detectron2 - More detection options
* [Real-ESRGAN](https://docs.clore.ai/guides/image-processing/real-esrgan-upscaling) - Enhance detected objects


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clore.ai/guides/computer-vision/yolov8-detection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
