you only look once (YOLO) [🚧 WIP]#

Ultralytics supports a wide range of YOLO models, from early versions like YOLOv3 to the latest YOLO11. the latest version of the acclaimed real-time object detection and image segmentation model YOLO11 models pretrained on the COCO dataset for Detection, Segmentation, and Pose Estimation. Additionally, Classification models pretrained on the ImageNet dataset are available. Tracking mode is compatible with all Detection, Segmentation, and Pose models. All Models are automatically downloaded from the latest Ultralytics release upon first use.

import cv2
import numpy as np
import matplotlib.pyplot as plt
from ultralytics import YOLO
from IPython.display import display, Image
import torch
import random
# Set random seeds for reproducibility
random.seed(42)
np.random.seed(42)
torch.manual_seed(42)
<torch._C.Generator at 0x12ea420b0>
# Initialize detection model
model_det = YOLO("yolov8n.pt") 
!yolo task=detect mode=predict model=yolov8n.pt conf=0.25 source='https://ultralytics.com/images/bus.jpg' save=True
Ultralytics 8.3.4 🚀 Python-3.12.4 torch-2.4.1 CPU (Apple M3 Max)
YOLOv8n summary (fused): 168 layers, 3,151,904 parameters, 0 gradients, 8.7 GFLOPs

Downloading https://ultralytics.com/images/bus.jpg to 'bus.jpg'...
100%|█████████████████████████████████████████| 134k/134k [00:00<00:00, 215MB/s]
image 1/1 /Users/n0man/Code/n03an.me/notebooks/va/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 29.8ms
Speed: 1.6ms preprocess, 29.8ms inference, 1.0ms postprocess per image at shape (1, 3, 640, 480)
Results saved to /Users/n0man/Code/n03an.me/runs/detect/predict7
💡 Learn more at https://docs.ultralytics.com/modes/predict
# Run detection
def detect_objects(image_path):
    results = model_det(image_path)
    # Visualize results
    plt.figure(figsize=(12, 8))
    plt.imshow(results[0].plot()[:, :, ::-1])  # Convert BGR to RGB
    plt.title("Object Detection")
    plt.axis('off')
    plt.show()
# Run detection
detect_objects("images/bus.jpg")
detect_objects("images/bike.png")
detect_objects("images/park.jpg")
image 1/1 /Users/n0man/Code/n03an.me/notebooks/va/images/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 38.1ms
Speed: 2.1ms preprocess, 38.1ms inference, 0.3ms postprocess per image at shape (1, 3, 640, 480)
../_images/88d81e0cbf3a94b215452bb154a93119311341dfc2332839c53391156bad8bdd.png
image 1/1 /Users/n0man/Code/n03an.me/notebooks/va/images/bike.png: 640x640 1 person, 1 bicycle, 1 dog, 31.7ms
Speed: 1.6ms preprocess, 31.7ms inference, 0.3ms postprocess per image at shape (1, 3, 640, 640)
../_images/458ea08eb67bc23be058d074976bc323a24754cc67e89ee8f5cbb31c1a48d226.png
image 1/1 /Users/n0man/Code/n03an.me/notebooks/va/images/park.jpg: 384x640 8 persons, 1 bicycle, 1 dog, 27.8ms
Speed: 0.9ms preprocess, 27.8ms inference, 0.8ms postprocess per image at shape (1, 3, 384, 640)
../_images/b13633f0c71193403a87f54227133c4be6bacd4501e1f4fe6635e346d060bbef.png