YOLOv11 C++ TensorRT

引用

YOLOv11 C++ TensorRT项目是一个用C++实现并使用NVIDIA TensorRT进行优化的高性能对象检测解决方案。该项目利用 YOLOv11 模型提供快速准确的对象检测,并利用 TensorRT 最大限度地提高推理效率和性能。

📢 更新

主要特点:

模型转换:将 ONNX 模型转换为 TensorRT 引擎文件以加速推理。

视频推理:有效地对视频文件进行对象检测。

图像推理:对单个图像执行对象检测。

高效率:针对使用 NVIDIA GPU 的实时物体检测进行了优化。

使用 CUDA 进行预处理:支持 CUDA 的预处理,可实现更快的输入处理。

YOLOv11 模型的基准推理时间

📂 项目结构

YOLOv11-TensorRT/

├── CMakeLists.txt # Build configuration for the project

├── include/ # Header files

├── src/

│ ├── main.cpp # Main entry point for the application

│ ├── yolov11.cpp # YOLOv11 implementation

│ └── preprocess.cu # CUDA preprocessing code

├── assets/ # Images and benchmarks for README

└── build/ # Compiled binaries

🛠️ 设置

先决条件

CMake(版本 3.18 或更高版本)

TensorRT(V8.6.1.6:用于使用 YOLOv11 进行优化推理。)

CUDA 工具包(V11.7:用于 GPU 加速)

OpenCV(V4.10.0:用于图像和视频处理)

NVIDIA GPU(计算能力 7.5 或更高)

安装

cd YOLOv11-TensorRT

更新 CMakeLists.txt 中的 TensorRT 和 OpenCV 路径:

set(TENSORRT_PATH "F:/Program Files/TensorRT-8.6.1.6") # Adjust this to your path

构建项目:

mkdir build

cd build

cmake ..

make -j$(nproc)

🚀 使用方法

将 Yolov11 转换为 ONNX 模型

from ultralytics import YOLO

Load the YOLO model

model = YOLO("yolo11s.pt")

#Export the model to ONNX format

export_path = model.export(format="onnx")

将 ONNX 模型转换为 TensorRT 引擎

要将 ONNX 模型转换为 TensorRT 引擎文件,请使用以下命令:

./YOLOv11TRT convert path_to_your_model.onnx path_to_your_engine.engine.

path_to_your_model.onnx:ONNX 模型文件的路径。

path_to_your_engine.engine:TensorRT 引擎文件的保存路径。

对视频进行推理

要对视频运行推理,请使用以下命令:

./YOLOv11TRT infer_video path_to_your_video.mp4 path_to_your_engine.engine

path_to_your_video.mp4:输入视频文件的路径。

path_to_your_engine.engine:TensorRT 引擎文件的路径。

对视频进行推理

对图像运行推理 要在图像上运行推理,请使用以下命令:

./YOLOv11TRT infer_image path_to_your_image.jpg path_to_your_engine.engine

path_to_your_image.jpg:输入图像文件的路径。

path_to_your_engine.engine:TensorRT 引擎文件的路径。

⚙️ 配置

CMake 配置

在 CMakeLists.txt 中,如果 TensorRT 和 OpenCV 安装在非默认位置,请更新它们的路径:

设置TensorRT安装路径

#Define the path to TensorRT installation

set(TENSORRT_PATH "F:/Program Files/TensorRT-8.6.1.6") # Update this to the actual path for TensorRT

确保该路径指向安装 TensorRT 的目录。

故障排除

找不到 nvinfer.lib:确保 TensorRT 已正确安装且 nvinfer.lib 位于指定路径中。更新 CMakeLists.txt 以包含 TensorRT 库的正确路径。

链接器错误:验证所有依赖项(OpenCV、CUDA、TensorRT)是否正确安装,以及它们的路径是否在 CMakeLists.txt 中正确设置。

运行时错误:确保您的系统具有正确的 CUDA 驱动程序,并且 TensorRT 运行时库可访问。将 TensorRT 的 bin 目录添加到您的系统 PATH。

相关推荐
Dilettante25816 小时前
编译期魔法:自定义 Webpack Loader 将函数调用结果"内联"为静态字符串
webpack·前端工程化
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_3 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星3 天前
虚函数表:C++ 多态背后的那个男人
c++
sunny_4 天前
⚡️ vite-plugin-oxc:从 Babel 到 Oxc,我为 Vite 写了一个高性能编译插件
前端·webpack·架构
端平入洛5 天前
delete又未完全delete
c++
用户83040713057016 天前
SPA 首屏加载速度慢怎么解决?
vue.js·webpack
端平入洛6 天前
auto有时不auto
c++
codingWhat6 天前
手把手系列之—— 自定义 Loader 和 Plugin
webpack·前端工程化
哇哈哈20216 天前
信号量和信号
linux·c++