当前位置:网站首页>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

边栏推荐
- CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
- [数学建模] 微分方程--捕鱼业的持续发展
- The value of two date types is subtracted and converted to seconds
- Chip debugging of es8316 of imx8mp
- Summary of redis AOF and RDB knowledge points
- 优秀PM必须经历这3层蜕变!
- [FreeRTOS interrupt experiment]
- Flink kakfa data read and write to Hudi
- DMA use of stm32
- Sentinel sliding window traffic statistics
猜你喜欢

麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東

二叉树基本知识和例题

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

程序员在互联网行业的地位 | 每日趣闻

canal同步mysql数据变化到kafka(centos部署)

Meet diverse needs: jetmade creates three one-stop development packages to help efficient development

Selection of slow motion function

SQL注入漏洞(MSSQL注入)
![[05-1, 05-02, 05-03] network protocol](/img/25/2e9ccc3f31a1fd46c9ab643d48064b.jpg)
[05-1, 05-02, 05-03] network protocol

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
随机推荐
[HBZ sharing] how to locate slow queries in cloud database
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
Postman前置脚本-全局变量和环境变量
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
ETCD数据库源码分析——etcdserver bootstrap初始化存储
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
Can Flink SQL read multiple topics at the same time. How to write in with
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
Summary of three log knowledge points of MySQL
Flody的应用
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
IPv6 comprehensive experiment
麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
[NOIP2008 提高组] 笨小猴
Scala function advanced
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps