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

边栏推荐
- Basic explanation of turtle module - draw curve
- ISP learning (2)
- Leetcode 186 Flip the word II in the string (2022.07.05)
- 力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
- [try to hack] John hash cracking tool
- Crazy God said redis notes
- flink sql 能同时读多个topic吗。with里怎么写
- Redis has four methods for checking big keys, which are necessary for optimization
- Can Flink SQL read multiple topics at the same time. How to write in with
- [network] channel attention network and spatial attention network
猜你喜欢

Digital children < daily question> (Digital DP)

麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东

Flody的应用

Database - MySQL storage engine (deadlock)

Basic knowledge and examples of binary tree

图论的扩展

11. Intranet penetration and automatic refresh

View workflow
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/be/8710605c8da8d1553af974f0dc46bc.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package

Orm-f & Q object
随机推荐
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
[buuctf.reverse] 159_[watevrCTF 2019]Watshell
Basic explanation of turtle module - draw curve
【LGR-109】洛谷 5 月月赛 II & Windy Round 6
Microservice resource address
Platformio create libopencm3 + FreeRTOS project
On the solution of es8316's audio burst
Supreme Court, judgment standard of divorce cases
Knowledge consolidation source code implementation 3: buffer ringbuffer
动态规划(树形dp)
也算是学习中的小总结
Coreldraw2022 new version new function introduction cdr2022
Visio draw fan
Redis 排查大 key 的4种方法,优化必备
web工程导入了mysql驱动jar包却无法加载到驱动的问题
Basic knowledge and examples of binary tree
关于imx8mp的es8316的芯片调试
Weng Kai C language third week 3.1 punch in
SQL注入漏洞(MSSQL注入)
[NOIP2009 普及组] 分数线划定