当前位置:网站首页>Yolov5 tensorrt acceleration
Yolov5 tensorrt acceleration
2022-07-06 04:47:00 【Recurss】
Video tutorial
https://www.bilibili.com/video/BV113411J7nk?p=1
Github Warehouse address
https://github.com/Monday-Leo/Yolov5_Tensorrt_Win10
Environmental Science
Tensorrt 8.2.1.8
Cuda 10.2 Cudnn 8.2.1
Cuda Install Links :http://t.csdn.cn/AXNks
Opencv 3.4.6
Cmake 3.17.1
Cmake Installation tutorial :http://t.csdn.cn/f2TYW
VS 2017
GTX1650
Opencv Configuration method
1、 stay OpenCV The official website download is applicable to Windows Platform 3.4.6 edition
2、 Run the downloaded executable , take OpenCV Extract to the specified directory , for example D:\propencv
3、 My computer -> attribute -> Advanced system setup -> environment variable , Find... In the system variable Path( If not , Create your own ), And double-click edit , take opencv Fill in the path and save , Such as D:\opencv\build\x64\vc15\bin
Tensorrt Configuration method
1、 stay tensorrt The official website download is applicable to Windows Version of the platform
2、 take TensorRT/lib All of them lib Copied to the cuda/v10.2/lib/x64 Next , take TensorRT/lib All of them dll Copied to the cuda/v10.2/bin Next , take TensorRT/include All of them .h File copy to cuda/v10.2/include Next
3、 My computer -> attribute -> Advanced system setup -> environment variable , Find... In the system variable Path( If not , Create your own ), And double-click edit , take TensorRT/lib Fill in the path and save , Such as G:\TensorRT-8.2.1.8\lib
Open the warehouse CMakeLists.txt, modify Opencv、Tensorrt、dirent.h The catalog of , among dirent.h In this warehouse include in , Must be an absolute path . modify arch=compute_75;code=sm_75, Reference resources https://developer.nvidia.com/zh-cn/cuda-gpus,GPU by GTX1650, Ability to calculate 7.5, So this is set to arch=compute_75;code=sm_75.
cmake_minimum_required(VERSION 2.6)
project(yolov5)
#change to your own path
##################################################
set(OpenCV_DIR "D:\\opencv\\build")
set(TRT_DIR "D:\\TensorRT-8.2.1.8")
set(Dirent_INCLUDE_DIRS "D:\\Pycharm.project\\Yolov5_Tensorrt_Win10-master\\include")
##################################################
add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
# setup CUDA
find_package(CUDA REQUIRED)
message(STATUS " libraries: ${CUDA_LIBRARIES}")
message(STATUS " include path: ${CUDA_INCLUDE_DIRS}")
include_directories(${CUDA_INCLUDE_DIRS})
include_directories(${Dirent_INCLUDE_DIRS})
#change to your GPU own compute_XX
###########################################################################################
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-std=c++11;-g;-G;-gencode;arch=compute_75;code=sm_75)
###########################################################################################
####
enable_language(CUDA) # add this line, then no need to setup cuda path in vs
####
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${TRT_DIR}\\include)
# -D_MWAITXINTRIN_H_INCLUDED for solving error: identifier "__builtin_ia32_mwaitx" is undefined
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -D_MWAITXINTRIN_H_INCLUDED")
# setup opencv
find_package(OpenCV QUIET
NO_MODULE
NO_DEFAULT_PATH
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_PACKAGE_REGISTRY
NO_CMAKE_BUILDS_PATH
NO_CMAKE_SYSTEM_PATH
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${TRT_DIR}\\lib)
add_executable(yolov5 ${PROJECT_SOURCE_DIR}/yolov5.cpp ${PROJECT_SOURCE_DIR}/yololayer.cu ${PROJECT_SOURCE_DIR}/yololayer.h ${PROJECT_SOURCE_DIR}/preprocess.cu)
target_link_libraries(yolov5 "nvinfer" "nvinfer_plugin")
target_link_libraries(yolov5 ${OpenCV_LIBS})
target_link_libraries(yolov5 ${CUDA_LIBRARIES})
target_link_libraries(yolov5 Threads::Threads)
download yolov5 6.0 Source code and this warehouse code
git clone -b v6.0 https://github.com/ultralytics/yolov5.git
git clone https://github.com/Monday-Leo/Yolov5_Tensorrt_Win10
Generate WTS Model
Put... In the warehouse gen_wts.py And just downloaded yolov5s.pt Copy to yolov5 6.0 Under the directory of 
function gen_wts.py
python gen_wts.py -w yolov5s.pt -o yolov5s.wts
Generate wts file

Cmake The process
Create a new one in the directory build Folder

open Cmake, Select this warehouse directory , And the new build Catalog , Then click on the bottom left configure Button .

Choose your own Visual Studio edition , Such as 2017, In the second box, select x64, After clicking on finish
Running results
*
In turn, click Generate and Open Project

compile

Place the top of the interface Debug Change it to Release, Right click yolov5 project , Click regenerate .
Compilation successfully opened build/Release, You can see the generated exe Executable file .

What will be generated in the first step yolov5s.wts Copy the model to exe In the folder of , Open in this directory cmd Input
yolov5 -s yolov5s.wts yolov5s.engine s
The normal operation , At this time, the program will wts Convert to engine Serialization model , Need to wait for the forecast 10-20 About minutes . Generate engine After completion , Will appear under the folder yolov5s.engine Model . Put the pictures Copy folder to exe Under the folder , Try to predict correctly , Input :
yolov5 -d yolov5s.engine ./pictures

边栏推荐
- 团队协作出了问题,项目经理怎么办?
- MPLS experiment
- Programmers' position in the Internet industry | daily anecdotes
- Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
- [数学建模] 微分方程--捕鱼业的持续发展
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
- ue5 小知识点 开启lumen的设置
- Platformio create libopencm3 + FreeRTOS project
- RTP GB28181 文件测试工具
猜你喜欢

The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder

Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码

ISP learning (2)

SQL注入漏洞(MSSQL注入)

yolov5 tensorrt加速

Flody的应用

行业专网对比公网,优势在哪儿?能满足什么特定要求?

Postman前置脚本-全局变量和环境变量

Introduction of several RS485 isolated communication schemes

Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
随机推荐
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
[NOIP2008 提高组] 笨小猴
MPLS experiment
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
Introduction of several RS485 isolated communication schemes
MySQL reported an error datetime (0) null
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
After learning classes and objects, I wrote a date class
Use sentinel to interface locally
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
ISP learning (2)
SharedPreferences source code analysis
Nestjs配置文件上传, 配置中间件以及管道的使用
Quick sort
Scala function advanced
Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
Can CDC pull the Oracle table in full
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码