YOLOv10 on Custom Dataset

What is YOLO?

You Only Look Once (YOLO) is a state-of-the-art, real-time object detection algorithm .

YOLOv10 Architecture

What makes YOLO popular?

  • Speed
  • Detection accuracy
  • Good generalization
  • Open-source

Google Colab is an excellent platform for running deep learning models due to its free access to GPUs and ease of use. This guide will walk you through the process of running the latest version, YOLOv10, on Google Colab.

Before You Start

To make sure that you have access to GPU. You can use nvidia-smi command to do that. In case of any problems navigate to Edit -> Notebook settings -> Hardware accelerator, set it to GPU, and then click Save.

!nvidia-smi
Enter fullscreen mode
Exit fullscreen mode

Install Required Packages

Clone the GitHub repository.

!git clone https://github.com/THU-MIG/yolov10.git
Enter fullscreen mode
Exit fullscreen mode
cd yolov10
Enter fullscreen mode
Exit fullscreen mode
!pip install .
Enter fullscreen mode
Exit fullscreen mode

Upload Data To Colab

Step 1: Mount Google Drive

from google.colab import drive
drive.mount('/content/drive')
Enter fullscreen mode
Exit fullscreen mode

Step 2: Upload Files Directly

from google.colab import files
uploaded = files.upload()
Enter fullscreen mode
Exit fullscreen mode

Step 3: Organize Data for YOLOv10

Images:

  • The images directory contains subdirectories for train and val (validation) sets.
  • Each subdirectory contains the corresponding images for training and validation.

Labels:

  • The labels directory mirrors the images directory structure.
  • Each text file in the labels/train and labels/val subdirectories contains the annotations for the corresponding images.

Annotations Format:

/my_dataset /images /train image1.jpg image2.jpg ... /val image1.jpg image2.jpg ... /labels /train image1.txt image2.txt ... /val image1.txt image2.txt ... data.yaml
Enter fullscreen mode
Exit fullscreen mode

Data Configuration File (data.yaml):

train: /content/my_dataset/images/train
val: /content/my_dataset/images/val nc: N # N for number of classes
names: ['class1', 'class2', ..., 'classN']
Enter fullscreen mode
Exit fullscreen mode

Download Pre-trained Weights

import os
import urllib.request # Create a directory for the weights in the current working directory
weights_dir = os.path.join(os.getcwd(), "weights")
os.makedirs(weights_dir, exist_ok=True) # URLs of the weight files
urls = [ "https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10n.pt", "https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10s.pt", "https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10m.pt", "https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10b.pt", "https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10x.pt", "https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10l.pt"
] # Download each file
for url in urls: file_name = os.path.join(weights_dir, os.path.basename(url)) urllib.request.urlretrieve(url, file_name) print(f"Downloaded {file_name}")
Enter fullscreen mode
Exit fullscreen mode

Train Custom Model

!yolo task=detect mode=train epochs=100 batch=4 plots=True model=weights/yolov10n.pt data=data.yaml
Enter fullscreen mode
Exit fullscreen mode

Inference on Image

!yolo task=detect mode=predict conf=0.25 save=True model=runs/detect/train/weights/best.pt source=img.jpg
Enter fullscreen mode
Exit fullscreen mode

Inference on Video

!yolo task=detect mode=predict conf=0.25 save=True model=runs/detect/train/weights/best.pt source=video.mp4 
Enter fullscreen mode
Exit fullscreen mode

Summary

This guide covers running YOLOv10 on Google Colab by setting up the environment, installing necessary libraries, and running inference with pre-trained weights. It also explains how to upload and organize data in Colab for YOLOv8, including the required directory structure and configuration files. These steps enable efficient training and inference for object detection models using Colab’s resources.


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top