Skip to content

Commit 0e768f3

Browse files
committed
YOLOv12 with TensorRT backend
1 parent 944d1bb commit 0e768f3

19 files changed

+269
-44
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
# Last changes
55

6+
* YOLOv12 detector worked with TensorRT! Export pretrained Pytorch models [here (sunsmarterjie/yolov12)](https://github.com/sunsmarterjie/yolov12) to onnx format and run Multitarget-tracker with -e=6 example
7+
68
* TensorRT 10 is supported
79

810
* YOLOv11, YOLOv11-obb and YOLOv11-seg detector worked with TensorRT! Export pretrained Pytorch models [here (ultralytics/ultralytics)](https://github.com/ultralytics/ultralytics) to onnx format and run Multitarget-tracker with -e=6 example

data/settings_yolov12.ini

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
[detection]
2+
3+
#-----------------------------
4+
# opencv_dnn = 12
5+
# darknet_cudnn = 10
6+
# tensorrt = 11
7+
detector_backend = 11
8+
9+
#-----------------------------
10+
# Target and backend for opencv_dnn detector
11+
# DNN_TARGET_CPU
12+
# DNN_TARGET_OPENCL
13+
# DNN_TARGET_OPENCL_FP16
14+
# DNN_TARGET_MYRIAD
15+
# DNN_TARGET_CUDA
16+
# DNN_TARGET_CUDA_FP16
17+
ocv_dnn_target = DNN_TARGET_CPU
18+
19+
# DNN_BACKEND_DEFAULT
20+
# DNN_BACKEND_HALIDE
21+
# DNN_BACKEND_INFERENCE_ENGINE
22+
# DNN_BACKEND_OPENCV
23+
# DNN_BACKEND_VKCOM
24+
# DNN_BACKEND_CUDA
25+
# DNN_BACKEND_INFERENCE_ENGINE_NGRAPH
26+
# DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
27+
ocv_dnn_backend = DNN_BACKEND_OPENCV
28+
29+
#-----------------------------
30+
nn_weights = C:/work/home/mtracker/Multitarget-tracker/data/coco/yolov12m.onnx
31+
nn_config = C:/work/home/mtracker/Multitarget-tracker/data/coco/yolov12m.onnx
32+
class_names = C:/work/home/mtracker/Multitarget-tracker/data/coco/coco.names
33+
34+
#-----------------------------
35+
confidence_threshold = 0.5
36+
37+
max_crop_ratio = 0
38+
max_batch = 1
39+
gpu_id = 0
40+
41+
#-----------------------------
42+
# YOLOV3
43+
# YOLOV4
44+
# YOLOV5
45+
net_type = YOLOV11
46+
47+
#-----------------------------
48+
# INT8
49+
# FP16
50+
# FP32
51+
inference_precision = FP16
52+
53+
54+
[tracking]
55+
56+
#-----------------------------
57+
# DistCenters = 0 // Euclidean distance between centers, pixels
58+
# DistRects = 1 // Euclidean distance between bounding rectangles, pixels
59+
# DistJaccard = 2 // Intersection over Union, IoU, [0, 1]
60+
# DistHist = 3 // Bhatacharia distance between histograms, [0, 1]
61+
62+
distance_type = 0
63+
64+
#-----------------------------
65+
# KalmanLinear = 0
66+
# KalmanUnscented = 1
67+
68+
kalman_type = 0
69+
70+
#-----------------------------
71+
# FilterCenter = 0
72+
# FilterRect = 1
73+
# FilterRRect = 2
74+
75+
filter_goal = 0
76+
77+
#-----------------------------
78+
# TrackNone = 0
79+
# TrackKCF = 1
80+
# TrackMIL = 2
81+
# TrackMedianFlow = 3
82+
# TrackGOTURN = 4
83+
# TrackMOSSE = 5
84+
# TrackCSRT = 6
85+
# TrackDAT = 7
86+
# TrackSTAPLE = 8
87+
# TrackLDES = 9
88+
# TrackDaSiamRPN = 10
89+
# Used if filter_goal == FilterRect
90+
91+
lost_track_type = 0
92+
93+
#-----------------------------
94+
# MatchHungrian = 0
95+
# MatchBipart = 1
96+
97+
match_type = 0
98+
99+
#-----------------------------
100+
# Use constant acceleration motion model:
101+
# 0 - unused (stable)
102+
# 1 - use acceleration in Kalman filter (experimental)
103+
use_aceleration = 0
104+
105+
#-----------------------------
106+
# Delta time for Kalman filter
107+
delta_time = 0.4
108+
109+
#-----------------------------
110+
# Accel noise magnitude for Kalman filter
111+
accel_noise = 0.2
112+
113+
#-----------------------------
114+
# Distance threshold between region and object on two frames
115+
dist_thresh = 0.8
116+
117+
#-----------------------------
118+
# If this value > 0 than will be used circle with this radius
119+
# If this value <= 0 than will be used ellipse with size (3*vx, 3*vy), vx and vy - horizontal and vertical speed in pixelsa
120+
min_area_radius_pix = -1
121+
122+
#-----------------------------
123+
# Minimal area radius in ration for object size. Used if min_area_radius_pix < 0
124+
min_area_radius_k = 0.8
125+
126+
#-----------------------------
127+
# If the object do not assignment more than this frames then it will be removed
128+
max_skip_frames = 50
129+
130+
#-----------------------------
131+
# The maximum trajectory length
132+
max_trace_len = 50
133+
134+
#-----------------------------
135+
# Detection abandoned objects
136+
detect_abandoned = 0
137+
# After this time (in seconds) the object is considered abandoned
138+
min_static_time = 5
139+
# After this time (in seconds) the abandoned object will be removed
140+
max_static_time = 25
141+
# Speed in pixels. If speed of object is more that this value than object is non static
142+
max_speed_for_static = 10

example/examples.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ class YoloTensorRTExample final : public VideoExample
655655
YOLOv10,
656656
YOLOv11,
657657
YOLOv11_OBB,
658-
YOLOv11Mask
658+
YOLOv11Mask,
659+
YOLOv12
659660
};
660661
YOLOModels usedModel = YOLOModels::YOLOv9;
661662
switch (usedModel)

src/Detector/OCVDNNDetector.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ bool OCVDNNDetector::Init(const config_t& config)
167167
dictNetType["YOLOV11"] = ModelType::YOLOV11;
168168
dictNetType["YOLOV11_OBB"] = ModelType::YOLOV11_OBB;
169169
dictNetType["YOLOV11Mask"] = ModelType::YOLOV11Mask;
170+
dictNetType["YOLOV12"] = ModelType::YOLOV12;
170171

171172
auto netType = dictNetType.find(net_type->second);
172173
if (netType != dictNetType.end())
@@ -333,6 +334,9 @@ void OCVDNNDetector::DetectInCrop(const cv::UMat& colorFrame, const cv::Rect& cr
333334
case ModelType::YOLOV11:
334335
ParseYOLOv11(crop, detections, tmpRegions);
335336
break;
337+
case ModelType::YOLOV12:
338+
ParseYOLOv11(crop, detections, tmpRegions);
339+
break;
336340

337341
case ModelType::YOLOV5_OBB:
338342
case ModelType::YOLOV8_OBB:

src/Detector/OCVDNNDetector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class OCVDNNDetector final : public BaseDetector
4747
YOLOV10,
4848
YOLOV11,
4949
YOLOV11_OBB,
50-
YOLOV11Mask
50+
YOLOV11Mask,
51+
YOLOV12
5152
};
5253

5354
cv::dnn::Net m_net;

src/Detector/tensorrt_yolo/YoloONNXv10_bb.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
///
88
class YOLOv10_bb_onnx : public YoloONNX
99
{
10+
public:
11+
YOLOv10_bb_onnx(std::vector<std::string>& inputTensorNames, std::vector<std::string>& outputTensorNames)
12+
{
13+
inputTensorNames.push_back("images");
14+
outputTensorNames.push_back("output0");
15+
}
16+
1017
protected:
1118
///
1219
/// \brief GetResult

src/Detector/tensorrt_yolo/YoloONNXv11_bb.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
///
88
class YOLOv11_bb_onnx : public YoloONNX
99
{
10+
public:
11+
YOLOv11_bb_onnx(std::vector<std::string>& inputTensorNames, std::vector<std::string>& outputTensorNames)
12+
{
13+
inputTensorNames.push_back("images");
14+
outputTensorNames.push_back("output0");
15+
}
16+
1017
protected:
1118
///
1219
/// \brief GetResult

src/Detector/tensorrt_yolo/YoloONNXv11_instance.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
///
88
class YOLOv11_instance_onnx : public YoloONNX
99
{
10+
public:
11+
YOLOv11_instance_onnx(std::vector<std::string>& inputTensorNames, std::vector<std::string>& outputTensorNames)
12+
{
13+
inputTensorNames.push_back("images");
14+
outputTensorNames.push_back("output0");
15+
outputTensorNames.push_back("output1");
16+
}
17+
1018
protected:
1119
///
1220
/// \brief GetResult

src/Detector/tensorrt_yolo/YoloONNXv11_obb.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
///
88
class YOLOv11_obb_onnx : public YoloONNX
99
{
10+
public:
11+
YOLOv11_obb_onnx(std::vector<std::string>& inputTensorNames, std::vector<std::string>& outputTensorNames)
12+
{
13+
inputTensorNames.push_back("images");
14+
outputTensorNames.push_back("output0");
15+
}
16+
1017
protected:
1118
///
1219
/// \brief GetResult
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "YoloONNX.hpp"
4+
5+
///
6+
/// \brief The YOLOv12_bb_onnx class
7+
///
8+
class YOLOv12_bb_onnx : public YOLOv11_bb_onnx
9+
{
10+
public:
11+
YOLOv12_bb_onnx(std::vector<std::string>& inputTensorNames, std::vector<std::string>& outputTensorNames)
12+
: YOLOv11_bb_onnx(inputTensorNames, outputTensorNames)
13+
{
14+
}
15+
16+
};

0 commit comments

Comments
 (0)