1,插件支持-转化TensorRT模型时不支持的算子

我们在做模型结构设计时,有时候自己会设计一些layer来满足任务需求,但是这些layer在使用Tensorrt优化时,TensorRT可能并不支持,如ROI Align,这时候就需要通过Plugin的形式自己去实现,如上图所示的custom layer。实现过程包括如下两个步骤:
首先需要重载一个IPlugin的基类,生成自己的Plugin的实现,告诉GPU或TensorRT需要做什么操作,要构建的Plugin是什么样子,其实就是类似于开发一个应用软件的插件,需要在上面实现什么功能。
其次要将插件替换网络中自己实现的layer。
现在tensorRT支持的层有:
-  Activation: ReLU, tanh and sigmoid 
-  Concatenation : Link together multiple tensors across the channel dimension. 
-  Convolution: 3D,2D 
-  Deconvolution 
-  Fully-connected: with or without bias 
-  ElementWise: sum, product or max of two tensors 
-  Pooling: max and average 
-  Padding 
-  Flatten 
-  LRN: cross-channel only 
-  SoftMax: cross-channel only 
-  RNN: RNN, GRU, and LSTM 
-  Scale: Affine transformation and/or exponentiation by constant values 
-  Shuffle: Reshuffling of tensors , reshape or transpose data 
-  Squeeze: Removes dimensions of size 1 from the shape of a tensor 
-  Unary: Supported operations are exp, log, sqrt, recip, abs and neg 
-  Plugin: integrate custom layer implementations that TensorRT does not natively support. 
基本上比较经典的层比如,卷积,反卷积,全连接,RNN,softmax等,在tensorRT中都是有对应的实现方式的,tensorRT是可以直接解析的。
但是由于现在深度学习技术发展日新月异,各种不同结构的自定义层(比如:STN)层出不穷,所以tensorRT是不可能全部支持当前存在的所有层的。那对于这些自定义的层该怎么办?
tensorRT中有一个 Plugin 层,这个层提供了 API 可以由用户自己定义tensorRT不支持的层。 如下图:

这就解决了适应不同用户的自定义层的需求。

build engine:创建解析器、工作空间、数据类型,序列化,释放
不同的设备引擎不通用,只能在同一个设备使用。例如:在服务器优化引擎,放到nano设备上,不行
pluginfoctory:如果网络层并不是直接支持的,自定义网络层
plugin:输入输出,初始化
2、实用工具Netron:
 
 
Netron是神经网络,深度学习和机器学习模型的可视化工具(viewer)。
Netron 支持目前大多数主流深度学习框架的模型,如下所示:
-  ONNX(.onnx,.pb) 
-  Keras(.h5,.keras) 
-  CoreML(.mlmodel) 
-  TensorFlow Lite(.tflite) 
-  Netron对Caffe(.caffemodel) 
-  Caffe2(predict_net.pb) 
-  MXNet(.model,-symbol.json) 
-  TensorFlow.js(model.json,.pb) 
-  TensorFlow(.pb,.meta) 

Yolov5l可视化网络结构图:















![[附源码]Python计算机毕业设计SSM基于的考研信息共享平台(程序+LW)](https://img-blog.csdnimg.cn/db0f4d73fad344888ac1dd92ef3ee7b6.png)




