1+ ##
12## B站同步视频讲解
23- https://www.bilibili.com/video/BV1Xw411f7FW
34- 相关PPTX下载:http://zifuture.com:1556/fs/sxai/tensorRT.pptx
14153 . TensorRT.vcxproj文件中,修改` <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 10.0.targets" /> ` 为你配置的CUDA路径
15164 . TensorRT.vcxproj文件中,修改` <CodeGeneration>compute_61,sm_61</CodeGeneration> ` 为你显卡配备的计算能力
1617 - 根据型号参考这里:https://developer.nvidia.com/zh-cn/cuda-gpus#compute
17- 5 . 配置依赖,或者下载依赖到lean中 。配置VC++目录->包含目录和引用目录
18+ 5 . 配置依赖或者下载依赖到lean中 。配置VC++目录->包含目录和引用目录
18196 . 配置环境,调试->环境,设置PATH路径
19207 . 编译并运行案例
2021
@@ -27,7 +28,7 @@ image = cv2.imread("inference/car.jpg")
2728bboxes = yolo.commit(image).get()
2829```
2930
30- - Pytorch无缝对接
31+ - Pytorch的无缝对接
3132``` python
3233model = models.resnet18(True ).eval().to(device)
3334trt_model = tp.convert_torch_to_trt(model, input )
@@ -76,31 +77,7 @@ auto box = engine->commit(image).get();
7677## 效果图
7778
7879
79- ## YoloV5-ONNX推理支持-第一种,使用提供的onnx
80- - 这个yolov5m.onnx模型使用官方最新版本直接导出得到
81- - CMake
82- - 在CMakeLists.txt中配置依赖路径tensorRT、cuda、cudnn、protobuf
83- ```bash
84- git clone [email protected] :shouxieai/tensorRT_cpp.git 85- cd tensorRT_cpp
86-
87- mkdir build
88- cd build
89- cmake ..
90- make yolo -j32
91-
92- # 或者make alphapose -j32
93- ```
94-
95- - Makefile
96- - 在Makefile中配置好依赖的tensorRT、cuda、cudnn、protobuf
97- ```bash
98- git clone [email protected] :shouxieai/tensorRT_cpp.git 99- cd tensorRT_cpp
100- make yolo -j32
101- ```
102-
103- ## YoloV5-ONNX推理支持-第二种,自行从官方导出onnx
80+ ## YoloV5支持
10481- yolov5的onnx,你的pytorch版本>=1.7时,导出的onnx模型可以直接被当前框架所使用
10582- 你的pytorch版本低于1.7时,或者对于yolov5其他版本(2.0、3.0、4.0),可以对opset进行简单改动后直接被框架所支持
10683- 如果你想实现低版本pytorch的tensorRT推理、动态batchsize等更多更高级的问题,请打开我们[博客地址](http://zifuture.com:8090)后找到二维码进群交流
@@ -137,7 +114,7 @@ torch.onnx.export(dynamic_axes={'images': {0: 'batch'}, # shape(1,3,640,640)
1371143 . 导出onnx模型
138115```bash
139116cd yolov5
140- python export.py -- weights=yolov5s.pt -- dynamic -- opset=11
117+ python export.py -- weights=yolov5s.pt -- dynamic -- include=onnx -- opset=11
141118```
1421194 . 复制模型并执行
143120```bash
@@ -146,6 +123,7 @@ cd tensorRT_cpp
146123make yolo - j32
147124```
148125
126+
149127# # YoloX的支持
150128- https:// github.com/ Megvii- BaseDetection/ YOLOX
151129- 你可以选择直接make run,会从镜像地址下载onnx并推理运行看到效果。不需要自行导出
@@ -190,6 +168,7 @@ model.head.decode_in_inference = True
190168
1911693 . 导出onnx模型
192170```bash
171+
193172# 下载模型,或许你需要翻墙
194173# wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_m.pth
195174
@@ -335,6 +314,7 @@ auto int8process = [](int current, int count, vector<string>& images, shared_ptr
335314 }
336315};
337316
317+
338318// 编译模型指定为INT8
339319auto model_file = " yolov5m.int8.trtmodel" ;
340320TRT ::compile (
@@ -363,11 +343,11 @@ engine->print();
363343// 加载图像
364344auto image = imread(" demo.jpg" );
365345
366- // 获取模型的输入和输出tensor节点,可以根据名字或者索引获取第几个
346+ // 获取模型的输入和输出tensor节点,可以根据名字或者索引获取具体第几个
367347auto input = engine-> input (0 );
368348auto output = engine-> output(0 );
369349
370- // 把图像塞到input tensor中,这里是减去均值,除以标准差
350+ // 把图像塞到input tensor中,这里是减去均值,并除以标准差
371351float mean[] = {0 , 0 , 0 };
372352float std[] = {1 , 1 , 1 };
373353input -> set_norm_mat(i, image, mean, std);
@@ -409,6 +389,7 @@ int HSwish::enqueue(const std::vector<GTensor>& inputs, std::vector<GTensor>& ou
409389 return 0 ;
410390}
411391
392+
412393RegisterPlugin(HSwish);
413394```
414395
@@ -461,9 +442,9 @@ Engine 0x23dd7780 detail
461442[2021 - 07 - 22 14 :37 :42 ][info][_main.cpp:124 ]:outputs[0 ].size = 2
462443[2021 - 07 - 22 14 :37 :42 ][info][_main.cpp:124 ]:outputs[1 ].size = 5
463444[2021 - 07 - 22 14 :37 :42 ][info][_main.cpp:124 ]:outputs[2 ].size = 1
464- ```
465445
446+ ```
466447
467448# # 关于
468449- 我们的博客地址:http:// www.zifuture.com:8090 /
469- - 我们的B站地址:https:// space.bilibili.com/ 1413433465
450+ - 我们的B站地址: https:// space.bilibili.com/ 1413433465
0 commit comments