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

边栏推荐
- How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
- Programmers' position in the Internet industry | daily anecdotes
- CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
- Codeforces Round #804 (Div. 2)
- Project manager, can you draw prototypes? Does the project manager need to do product design?
- The video in win10 computer system does not display thumbnails
- Coreldraw2022 new version new function introduction cdr2022
- ISP学习(2)
- [buuctf.reverse] 159_[watevrCTF 2019]Watshell
- 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
猜你喜欢
![[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity](/img/ac/93a64e59592e3d083a771b993d6884.jpg)
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity

Postman关联

Flink kakfa data read and write to Hudi

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

Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago

Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system

8. Static file

Easyrecovery reliable and toll free data recovery computer software

A blog to achieve embedded entry

Coreldraw2022 new version new function introduction cdr2022
随机推荐
Selection sort
coreldraw2022新版本新功能介绍cdr2022
Bubble sort
A blog to achieve embedded entry
Lagrange polynomial
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
How does vs change the project type?
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Distributed transaction solution
SQL injection vulnerability (MSSQL injection)
Delete subsequence < daily question >
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
Mysql database storage engine
Tengine kernel parameters
How to estimate the population with samples? (mean, variance, standard deviation)
Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
cdc 能全量拉去oracle 表嘛
Microservice resource address