tensorRT_Pro 项目实践

参考:https://github.com/shouxieai/tensorRT_Pro/blob/main/tutorial/README.zh-cn.md

前提:

https://www.cnblogs.com/odesey/p/17619218.html

https://www.cnblogs.com/odesey/p/17619240.html

  • ubuntu20.04
  • opencv4.2
  • cuda11.8
  • cuDNN v8.9.0 (July 11th, 2023), for CUDA 11.x
  • TensorRT-8.6.1
  • protobuf-3.19.4

配置 tensorRT_Pro

git clone https://github.com/shouxieai/tensorRT_Pro.git
cd tensorRT_Pro

# 适配Protobuf版本
#切换终端目录到onnx下
cd onnx

修改 make_pb.sh :

# 请修改protoc为你要使用的版本protoc
protoc=/home/h/programs/protobuf/bin/protoc

执行生成pb文件,并自动复制。使用make_pb.sh脚本

bash make_pb.sh

修改 CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
project(pro)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/workspace)

# # 如果要支持python则设置python路径
# set(HAS_PYTHON OFF)
# set(PythonRoot "/home/h/programs/miniconda3")
# set(PythonName "python3.9")

# 如果你是不同显卡,请设置为显卡对应的号码参考这里:https://developer.nvidia.com/zh-cn/cuda-gpus#compute, 3060: 86
set(CUDA_GEN_CODE "-gencode=arch=compute_86,code=sm_86")

# 如果你的opencv找不到,可以自己指定目录
set(OpenCV_DIR   "/home/h/programs/cv/build")

set(CUDA_TOOLKIT_ROOT_DIR     "/home/h/programs/cuda-11.8")
set(CUDNN_DIR    "/home/h/programs/cudnn-linux-x86_64-8.9.0.131_cuda11-archive")
set(TENSORRT_DIR "/home/h/programs/TensorRT-8.6.1.6")

# set(CUDA_TOOLKIT_ROOT_DIR     "/data/sxai/lean/cuda-10.2")
# set(CUDNN_DIR    "/data/sxai/lean/cudnn7.6.5.32-cuda10.2")
# set(TENSORRT_DIR "/data/sxai/lean/TensorRT-7.0.0.11")

# set(CUDA_TOOLKIT_ROOT_DIR  "/data/sxai/lean/cuda-11.1")
# set(CUDNN_DIR    "/data/sxai/lean/cudnn8.2.2.26")
# set(TENSORRT_DIR "/data/sxai/lean/TensorRT-7.2.1.6")

# 因为protobuf,需要用特定版本,所以这里指定路径
set(PROTOBUF_DIR "/home/h/programs/protobuf")

修改 .vscode/c_cpp_properties.json

{
	"configurations": [
		{
			"name": "Linux",
			"includePath": [
				"${workspaceFolder}/src/**",
				"/home/h/programs/protobuf/include/**",
				"/home/h/programs/cv/build/**",
				"/home/h/programs/cuda-11.8/include/**",
				"/home/h/programs/TensorRT-8.6.1.6/include/**",
				"/home/h/programs/cudnn-linux-x86_64-8.9.0.131_cuda11-archive/include/**",
				"/home/h/programs/miniconda3/include/python3.9/**"
			],
			"defines": ["__CUDACC__", "HAS_PYTHON"],
			"compilerPath": "/usr/bin/gcc", 
			"cStandard": "gnu11",
			"cppStandard": "gnu++11",
			"intelliSenseMode": "linux-gcc-x64",
			"configurationProvider": "ms-vscode.makefile-tools",
			"browse": {
				"path": [
					"${workspaceFolder}/src/**",
					"/home/h/programs/protobuf/include/**",
					"/home/h/programs/cv/build/**",
					"/home/h/programs/cuda-11.8/include/**",
					"/home/h/programs/TensorRT-8.6.1.6/include/**",
					"/home/h/programs/cudnn-linux-x86_64-8.9.0.131_cuda11-archive/include/**",
					"/home/h/programs/miniconda3/include/python3.9/**"
				],
				"limitSymbolsToIncludedHeaders": false,
				"databaseFilename": ""
			}
		}
	],
	"version": 4
}

编译:

cd tensorRT_Pro
mkdir build && cd build
cmake ..
make yolo -j64

[2023-08-12 15:46:00][info][app_yolo.cpp:132]:===================== test YoloV7 FP32 yolov7 ==================================
[2023-08-12 15:46:00][warn][trt_builder.cpp:33]:NVInfer: The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
[2023-08-12 15:46:00][info][trt_infer.cpp:177]:Infer 0x7f54ec000c80 detail
[2023-08-12 15:46:00][info][trt_infer.cpp:178]: Base device: [ID 0][arch 8.6][GMEM 9.71 GB/11.76 GB]
[2023-08-12 15:46:00][warn][trt_builder.cpp:33]:NVInfer: The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
[2023-08-12 15:46:00][info][trt_infer.cpp:179]: Max Batch Size: 1
[2023-08-12 15:46:00][info][trt_infer.cpp:180]: Inputs: 1
[2023-08-12 15:46:00][info][trt_infer.cpp:184]: 0.images : shape {1 x 3 x 640 x 640}, Float32
[2023-08-12 15:46:00][info][trt_infer.cpp:187]: Outputs: 1
[2023-08-12 15:46:00][info][trt_infer.cpp:191]: 0.output : shape {1 x 25200 x 85}, Float32
[2023-08-12 15:46:00][warn][trt_builder.cpp:33]:NVInfer: The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
[2023-08-12 15:46:10][info][app_yolo.cpp:83]:yolov7.FP32.trtmodel[YoloV7] average: 14.00 ms / image, FPS: 71.42
[2023-08-12 15:46:10][info][app_yolo.cpp:109]:Save to yolov7_YoloV7_FP32_result/car.jpg, 7 object, average time 14.00 ms
[2023-08-12 15:46:10][info][app_yolo.cpp:109]:Save to yolov7_YoloV7_FP32_result/zgjr.jpg, 4 object, average time 14.00 ms
[2023-08-12 15:46:10][info][app_yolo.cpp:109]:Save to yolov7_YoloV7_FP32_result/gril.jpg, 2 object, average time 14.00 ms
[2023-08-12 15:46:10][info][app_yolo.cpp:109]:Save to yolov7_YoloV7_FP32_result/group.jpg, 18 object, average time 14.00 ms
[2023-08-12 15:46:10][info][app_yolo.cpp:109]:Save to yolov7_YoloV7_FP32_result/yq.jpg, 2 object, average time 14.00 ms
[2023-08-12 15:46:10][info][app_yolo.cpp:109]:Save to yolov7_YoloV7_FP32_result/zand.jpg, 4 object, average time 14.00 ms
[2023-08-12 15:46:10][info][yolo.cpp:289]:Engine destroy.
[100%] Built target yolo

tensorRT_Pro 项目实践_第1张图片

你可能感兴趣的:(Tensorrt,C++,模型部署)