Unveiling YOLOv10: The Next Generation in Object Detection

givkashi
3 min readMay 29, 2024

--

In the ever-evolving field of computer vision, the YOLO (You Only Look Once) series has been a standout for real-time object detection. The latest iteration, YOLOv10, promises to push the boundaries even further with enhanced features and performance. In this post, we will explore YOLOv10, its installation, and how to leverage its pre-trained models for object detection tasks.

Comparisons with others in terms of latency-accuracy (left) and size-accuracy (right) trade-offs.

Key Features of YOLOv10

YOLOv10 introduces several groundbreaking features that make it a robust choice for object detection:

  • Improved Accuracy and Speed: YOLOv10 strikes a balance between high accuracy and low latency, making it ideal for real-time applications.
  • Advanced Architectures: Incorporates cutting-edge model architectures for better feature extraction and object classification.
  • Enhanced Training Techniques: Utilizes sophisticated training techniques to improve the robustness and performance of the model.
  • Versatile Deployment: Supports deployment across various platforms, including cloud, mobile, and edge devices.

For a comprehensive overview of YOLOv10’s features, refer to the Ultralytics documentation.

Setting Up YOLOv10

Getting started with YOLOv10 is straightforward. Follow these steps to install the necessary dependencies and download the pre-trained weights.

Install YOLOv10

First, ensure you have the required packages. We will use the supervision library and install YOLOv10 from the GitHub repository.

import os
HOME = os.getcwd()
print(HOME)
!pip install -q supervision
!pip install -q git+https://github.com/THU-MIG/yolov10.git

Download Pre-trained Weights

Next, download the pre-trained weights for YOLOv10. These weights are trained on large datasets and are ready for inference.

!mkdir -p {HOME}/weights
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10n.pt
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10s.pt
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10m.pt
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10b.pt
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10x.pt
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10l.pt
!ls -lh {HOME}/weights

Download Example Data

For demonstration purposes, let’s download a sample image. You can use your own images or videos as well.

!mkdir -p {HOME}/data
!wget -P {HOME}/data -q https://media.roboflow.com/notebooks/examples/dog.jpeg
!ls -lh {HOME}/data

Inference with Pre-trained COCO Model

Command Line Interface (CLI)

Using the CLI, you can perform inference with the pre-trained COCO model.

# %cd {HOME}
!yolo task=detect mode=predict conf=0.25 save=True \
model={HOME}/weights/yolov10n.pt \
source={HOME}/data/dog.jpeg

Displaying the Result

# %cd {HOME}
from IPython.display import Image

Image(filename='runs/detect/predict/dog.jpeg', height=600)

Python SDK

Alternatively, you can use the Python SDK for inference. Here’s a detailed guide on how to do it:

from ultralytics import YOLOv10

model = YOLOv10(f'{HOME}/weights/yolov10n.pt')
results = model(source=f'{HOME}/data/dog.jpeg', conf=0.25)

print(results[0].boxes.xyxy)
print(results[0].boxes.conf)
print(results[0].boxes.cls)

Displaying the Result with Annotations

Let’s visualize the detection results with bounding boxes and labels:

import cv2
import supervision as sv
from ultralytics import YOLOv10

model = YOLOv10(f'{HOME}/weights/yolov10n.pt')
image = cv2.imread(f'{HOME}/data/dog.jpeg')
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)

bounding_box_annotator = sv.BoundingBoxAnnotator()
label_annotator = sv.LabelAnnotator()

annotated_image = bounding_box_annotator.annotate(
scene=image, detections=detections)
annotated_image = label_annotator.annotate(
scene=annotated_image, detections=detections)

sv.plot_image(annotated_image)

By following these steps, you can harness the power of YOLOv10 for your object detection tasks. Whether you’re working on a hobby project or a complex application, YOLOv10 offers the accuracy and speed you need to achieve your goals. For more details and advanced usage, refer to the YOLOv10 GitHub repository.

Code:

--

--