当前位置:网站首页>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
边栏推荐
- 11. Intranet penetration and automatic refresh
- [05-1, 05-02, 05-03] network protocol
- Coreldraw2022 new version new function introduction cdr2022
- Redis 排查大 key 的4種方法,優化必備
- Etcd database source code analysis -- etcdserver bootstrap initialization storage
- The kernel determines whether peripherals are attached to the I2C address
- Postman管理测试用例
- Fuzzy -- basic application method of AFL
- Redis has four methods for checking big keys, which are necessary for optimization
- Word cover underline
猜你喜欢
canal同步mysql数据变化到kafka(centos部署)
MPLS experiment
ETCD数据库源码分析——etcdserver bootstrap初始化存储
SQL注入漏洞(MSSQL注入)
Use sentinel to interface locally
acwing周赛58
RTP gb28181 document testing tool
Weng Kai C language third week 3.1 punch in
Selection of slow motion function
Zynq learning notes (3) - partial reconfiguration
随机推荐
也算是学习中的小总结
Postman断言
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
How does vs change the project type?
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
yolov5 tensorrt加速
11. Intranet penetration and automatic refresh
[FreeRTOS interrupt experiment]
Embedded development program framework
NPM command -- install dependent packages -- Usage / explanation
Redis 排查大 key 的4种方法,优化必备
flink sql 能同时读多个topic吗。with里怎么写
Dynamic programming (tree DP)
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
也算是學習中的小總結
树莓派3.5寸屏幕白屏显示连接
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
canal同步mysql数据变化到kafka(centos部署)