Home

Awesome

Pretrained-YOLOv9-Network-For-Object-Detection

This repository provides multiple pretrained YOLO v9[1] object detection networks for MATLAB®, trained on the COCO 2017[2] dataset. These object detectors can detect 80 different object categories including person, car, traffic light, etc. The input should be a single image.

Creator: MathWorks Development

Includes Codegen support: ✔

Includes Simulink support script: ✔

Includes Import support script: ✔

Includes transfer learning script: ❌

Refer to Pretrained YOLOv8 Network For Object Detection (or) trainYOLOXObjectDetector for training latest YOLOs on custom dataset.

License

The software and model weights are released under the GNU Affero General Public License v3.0. For alternative licensing, contact Ultralytics Licensing.

Requirements

Getting Started

Download or clone this repository to your machine and open it in MATLAB®.

Setup

Add path to the cloned directory.

addpath(genpath(pwd));

Download the pretrained network

Use the code below to download the pretrained network.

% Load YOLO v9 medium model
modelName = 'Yolov9m';
model = helper.downloadPretrainedYOLOv9(modelName);
net = model.net;

modelName of the pretrained YOLO v9 deep learning model, specified as one of these:

Following is the description of various YOLO v9 models available in this repo:

ModelDescription
Yolov9tTiny pretrained YOLO v9 model optimized for speed and efficiency.
Yolov9sSmall pretrained YOLO v9 model balances speed and accuracy, suitable for applications requiring real-time performance with good detection quality.
Yolov9mMedium pretrained YOLO v9 model offers higher accuracy with moderate computational demands.
Yolov9cCompact pretrained YOLO v9 model prioritizes maximum detection accuracy for high-end systems, at the cost of computational intensity.
Yolov9eExtensive YOLOv9 model is the most accurate but requires significant computational resources, ideal for high-end systems prioritizing detection performance.

Detect Objects Using Pretrained YOLO v9

To perform object detection on an example image using the pretrained model, you can execute the runInference.m script. Alternatively, utilize the code provided below for the same purpose.

% Read test image.
I = imread(fullfile('data/Input','inputTeam.jpg'));

% Load pretrained medium variant of YOLOv9 object detector.
det = yolov9ObjectDetector('Yolov9m');

% Perform detection using pretrained model.
[bboxes, scores, labelIds] = detect(det, I);

% Visualize detection results.
helper.plotObjectDetections(I,bboxes,scores,labelIds);

Results

Metrics and Evaluation

Size and Accuracy Metrics

ModelInput image resolutionSize (MB)mAP
Yolov9t640 x 6407.538.3
Yolov9s640 x 6402546.8
Yolov9m640 x 64067.251.4
Yolov9c640 x 6408553.0
Yolov9e640 x 64019055.6

mAP for models trained on the COCO dataset is computed as average over IoU of .5:.95.

Deployment

Code generation enables you to generate code and deploy YOLO v9 on multiple embedded platforms. The list of supported platforms is shown below:

TargetSupportNotes
GPU Coderrun gpuCodegenYOLOv9.m
MATLAB Coderrun codegenYOLOv9.m

To deploy YOLO v9 to GPU Coder, run gpuCodegenYOLOv9.m. This script calls the yolov9Predict.m entry point function and generate CUDA code for it. It will run the generated MEX and give an output. For more information about codegen, see Deep Learning with GPU Coder.

Simulink

Simulink is a block diagram environment used to design systems with multidomain models, simulate before moving to hardware, and deploy without writing code. For more information about Simulink, see Get Started with Simulink

% Read test image.
I = imread(fullfile('data/Input','inputTeam.jpg'));

% Open Simulink model.
open('yolov9SimulinkSupport.slx')

To run the simulation, click Run from the Simulation tab.

The output will be logged to the workspace variable out from the Simulink model.

Network Overview

YOLO v9 is one of the best performing object detectors and is considered as an improvement to the existing YOLO variants such as YOLO v5, YOLOX and YOLO v8.

Following are the key features of the YOLO v9 object detector compared to its predecessors:

References

[1] https://github.com/ultralytics/ultralytics

[2] Lin, T., et al. "Microsoft COCO: Common objects in context. arXiv 2014." arXiv preprint arXiv:1405.0312 (2014).

Copyright 2024 The MathWorks, Inc.