1. 每次用yolo v8 都要用python ,对于我这种写软件的太不方便了,下面尝试编译dll 调用, 我已经有做好的模型.best.pt
参考视频方法:
yolov8 TensorRT C++ 部署_哔哩哔哩_bilibili
【yolov8】tensorrt部署保姆级教程,c++版_哔哩哔哩_bilibili
需要工具:
1.vs2019
2.tensorRt 8.0+
3.opencv 4.0+
TensorRt的链接: GitHub - wang-xinyu/tensorrtx: Implementation of popular deep learning networks with TensorRT network definition API
TensorRt官方下载
https://developer.nvidia.com/nvidia-tensorrt-8x-download
opencv 我之前就已经编译好了 , 自行编译
cmake list:
cmake_minimum_required(VERSION 3.10)
project(yolov8)
add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)set(CMAKE_CUDA_COMPILER C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\bin\\nvcc)
enable_language(CUDA)include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/plugin)# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
message("embed_platform on")
include_directories(C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\include)
link_directories(C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\lib\\x64)
else()
message("embed_platform off")
# cuda
include_directories(C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\include)
link_directories(C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\lib\\x64)# tensorrt
include_directories(C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\include)
link_directories(C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\lib)
# include_directories(/home/lindsay/TensorRT-7.2.3.4/include)
# link_directories(/home/lindsay/TensorRT-7.2.3.4/lib)
endif()add_library(myplugins SHARED ${PROJECT_SOURCE_DIR}/plugin/yololayer.cu)
target_link_libraries(myplugins nvinfer cudart)find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.cu)
add_executable(yolov8_det ${PROJECT_SOURCE_DIR}/yolov8_det.cpp ${SRCS})target_link_libraries(yolov8_det nvinfer)
target_link_libraries(yolov8_det cudart)
target_link_libraries(yolov8_det myplugins)
target_link_libraries(yolov8_det ${OpenCV_LIBS})add_executable(yolov8_seg ${PROJECT_SOURCE_DIR}/yolov8_seg.cpp ${SRCS})
target_link_libraries(yolov8_seg nvinfer cudart myplugins ${OpenCV_LIBS})
开始编译 cmake
把
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\extras\visual_studio_integration\MSBuildExtensions
这下面所有文件复制到
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\BuildCustomizations
弄完之后记得重启电脑
buld完了之后把engin.props 和 opencv.props 还有 tensor8.5.3.1 添加进C++的VS项目里面
报错:
1.转.pt 文件的时候No module named 'ultralytics.yolo'
解决:pip install ultralytics==8.0.100
2. cuda_utils.h 报错不存在
myplugins 文件属性添加
3.报错direct.h 不存在,用everything查找全盘,发现yolov9里面有个direct.h,直接移植到cuda的include目录就可以了
4.threadIdx、blockDim、blockIdx未定义标识符
这时直接运行程序看看是否可以运行,能运行就不用管不能运行加头文件 #include <device_launch_parameters.h>
5 .atomicAdd未定义标识符,同上,当不能运行时加头文件 #include <sm_20_atomic_funct>