window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署

一、准备工具

1.1、visual studio下载安装

参考:vs2019社区版下载教程(详细)_Redamancy_06的博客-CSDN博客_vs2019社区版

1.2、显卡驱动+cuda+cudnn安装

参考:win10系统+3060显卡驱动+cuda11.5+cudnn8.3安装_Bubble_water的博客-CSDN博客

一定要安装好visual studio软件之后再安装cuda(或者重装cuda),并且选择visual studio integration,否则后期配置会出现麻烦还需要自己复制一些东西去解决问题

1.3、tensorrt安装

参考:有道云笔记

1.4、cmake下载安装

cmake版本3.25.1,可以根据自己的情况选择安装自己需要的版本

官方网址:

https://cmake.org/download

下载地址:

https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-windows-x86_64.msiwindow10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第1张图片https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-windows-x86_64.msi

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第2张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第3张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第4张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第5张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第6张图片

 1.5、opencv下载:

自己源码编译,参考:win10+vs2017+opencv4.0.1+opencv_contrib-4.0.1详细教程_Bubble_water的博客-CSDN博客

或者直接下载官方编译好的文件,按照自己需要的版本下载:

Releases · opencv/opencv · GitHub
 

二、yolov5和tensorrtx源码下载
2.1、将下载下来的yolov5和tensorrtx仓库切换到6.2版本
yolov5仓库:https://github.com/ultralytics/yolov5,将其下载下来

将https://github.com/tronkko/dirent源码下载下来,cmakelist.txt里面会需要这个文件

切换到v6.2tag:

git checkout v6.2

如下图所示:

window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第7张图片

 2.2、tensorrtx仓库:https://github.com/wang-xinyu/tensorrtx,将其下载下来

切换到yolov5-v6.2tag:

git checkout yolov5-v6.2

如下图所示:

window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第8张图片

 四、cmake编译工程

4.1、修改tensorrtx\yolov5\CMakeLists.txt里面的内容如下:

cmake_minimum_required(VERSION 2.6)

project(yolov5) #1
set(OpenCV_DIR "E:\\workspace\\dll\\opencv4\\build")  #2
set(OpenCV_INCLUDE_DIRS ${OpenCV_DIR}\\include) #3
set(OpenCV_LIB_DIRS ${OpenCV_DIR}\\x64\\vc16\\lib) #4
set(OpenCV_Debug_LIBS "opencv_world454d.lib") #5
set(OpenCV_Release_LIBS "opencv_world454.lib") #6
set(TRT_DIR "E:\\workspace\\dll\\tensorrt\\TensorRT-8.2.5.1\\TensorRT-8.2.5.1")  #7
set(TRT_INCLUDE_DIRS ${TRT_DIR}\\include) #8
set(TRT_LIB_DIRS ${TRT_DIR}\\lib) #9
set(Dirent_INCLUDE_DIRS "E:\\yolov5\\dirent\\include") #10

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})

####
enable_language(CUDA)  # add this line, then no need to setup cuda path in vs
####
include_directories(${PROJECT_SOURCE_DIR}/include) #11
include_directories(${TRT_INCLUDE_DIRS}) #12
link_directories(${TRT_LIB_DIRS}) #13
include_directories(${OpenCV_INCLUDE_DIRS}) #14
link_directories(${OpenCV_LIB_DIRS}) #15
include_directories(${Dirent_INCLUDE_DIRS}) #16


# -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 "    lib path: ${OpenCV_LIB_DIRS}")
message(STATUS "    Debug libraries: ${OpenCV_Debug_LIBS}")
message(STATUS "    Release libraries: ${OpenCV_Release_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")



#add_executable(yolov5 ${PROJECT_SOURCE_DIR}/yolov5.cpp ${PROJECT_SOURCE_DIR}/common.hpp ${PROJECT_SOURCE_DIR}/yololayer.cu ${PROJECT_SOURCE_DIR}/yololayer.h)   #17

add_executable(yolov5 ${PROJECT_SOURCE_DIR}/yolov5.cpp ${PROJECT_SOURCE_DIR}/yololayer.cu ${PROJECT_SOURCE_DIR}/yololayer.h ${PROJECT_SOURCE_DIR}/preprocess.cu ${PROJECT_SOURCE_DIR}/preprocess.h)   #4  ${PROJECT_SOURCE_DIR}/preprocess.cu ${PROJECT_SOURCE_DIR}/preprocess.h  这是后来加的用于解决错误2,下面也有说明

target_link_libraries(yolov5 "nvinfer" "nvinfer_plugin") #18
target_link_libraries(yolov5 debug ${OpenCV_Debug_LIBS}) #19
target_link_libraries(yolov5 optimized ${OpenCV_Release_LIBS}) #20
target_link_libraries(yolov5 ${CUDA_LIBRARIES}) #21
target_link_libraries(yolov5 Threads::Threads)  

4.2、cmake运行

window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第9张图片

 选择自己的vs编译器版本和系统版本

window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第10张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第11张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第12张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第13张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第14张图片

 window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第15张图片

 将tensorrtx\yolov5\gen_wts.py复制到https://github.com/ultralytics/yolov5训练源码文件夹下面

运行

#python gen_wts.py文件路径 -w pt权重文件路径

python gen_wts.py -w yolov5s.pt

运行结果如下:

window10+TensorRT-8.2.5.1+yolov5 v6.2 c++部署_第16张图片

 打开自己刚才build下面的Release文件夹,运行

需要将opencv_world454.dll放到Release文件夹下面,将wts序列化保持成tensorrt的engine格式

命令如下:

 ./yolov5.exe -s "E:\yolov5\yolov5\yolov5s.wts" yolov5s.engine s

 检测测试,说明成功了。接下来就是自己根据自己的情况进行封装程序了

 

 

 参考:

  • tensorrtx/run_on_windows.md at master · wang-xinyu/tensorrtx · GitHub
  • Tensorrtx+yolov5+windows10+vs2015+cuda11.1关键问题及步骤记录_如雾如电的博客-CSDN博客
  • windows上配置TensorRT yolov5 -6.0部署 tensorrtx视频流推理_野马AS的博客-CSDN博客
  • win10 tensorrtx yolov5使用方法_三毛的二哥的博客-CSDN博客_tensorrtx yolov5
  • win10 使用TensorRT部署 yolov5-v4.0(C++)_SongpingWang的博客-CSDN博客_yolov5 4.0
  • 【TensorRT】记一次使用C++接口TensorRT部署yolov5 v6.1模型的过程-pudn.com
  • Win10—YOLOv5实战+TensorRT部署+VS2019编译(小白教程~易懂易上手)---超详细_畅想未来2020的博客-CSDN博客_win yolo5编译
  • windows上配置TensorRT yolov5 -6.1部署 tensorrtx视频流推理-CFANZ编程社区
  • yolov5部署之七步完成tensorRT模型推理加速_Christo3的博客-CSDN博客_yolov5 tensorrt
  • YoloV5在tensorRT上加速(Windows)(C++)(webcam)_点PY的博客-CSDN博客_yolov5中webcam是什么

你可能感兴趣的:(深度学习,c++,windows,开发语言)