tensorrt 相关知识
tensorrt 是nvidia 公司推出的一款能够加速深度学习网络推理的SDK。
具体怎样加速的,什么类型的网络结构能够起到加速的作用等等不做赘述。
参考的版本来自https://github.com/wang-xinyu/tensorrtx/tree/master/yolov5
实现步骤:
1.根据实际业务需求,利用pytorch yolov5-6.2 版本进行模型训练,网址链接为:https://github.com/ultralytics/yolov5得到.pt 文件。
2. .pt 文件转换成 .wts 文件。通过 运行 这个脚本gen_wts.py 。
3.编译运行yolov5 文件夹下的源代码,生成可执行文件。终端运行命令行demo 跑通:
sudo ./yolov5 -s yolov5s.wts yolov5s.engine s
sudo ./yolov5 -d yolov5s.engine ../images
关键代码解读,顺序是按照tensorrt 的执行流程展开:
1.cudaSetDevice(DEVICE);//设置GPU id ,决定将当前程序跑在那块GPU下。
2.nvinfer1::IHostMemory *modelStream{nullptr}; //IHostMemory 是经tensorrt 优化后的序列化模型被保存的对象。
3.nvinfer1::IBuilder *builder =