版本號:cuda-10.0 && cudnn7.3 && tensorflow 1.13 && tensorRT5.0.2.6 && ?T4 GPU
使用:在tensorflow里graph換成tensorRT返回的graph。
tf.import_graph_def(self.convFP16Graph(output_graph_def), name="")
def convFP16Graph(self, inGraph):
? ? ? ? return self.convRTGraph("FP16", inGraph)

Create_inference_graph 函數將凍結住的 TensorFlow 圖作為輸入,返回一個經過 TensorRT 節(jié)點優(yōu)化過的圖。我們看看這個函數的參數:
Input_graph_def:凍結住的 TensorFlow 圖
Outputs:輸出節(jié)點名字的字符串列表,比如:[“resnet_v1_50/predictions/Resape_1”]
Max_batch_size:整數,輸入的 batch size,比如,16
Max_workspace_size_bytes:整數,能分配給 TensorRT 的最大 GPU 顯存大小
Precision_mode:字符串,可選的值為「FP32」, 「FP16」, 「INT8」
報錯W tensorflow/contrib/tensorrt/convert/convert_nodes.cc:3710] Validation failed for TensorRTInputPH_0 and input slot 0: Input tensor with shape [?,?,?,2048] has an unknown non-batch dimension at dim 1
在Create_inference_graph里面加上參數,is_dynamic_op=True 。ok
原理分析:
在使用的過程中,log里能明顯看出將nodes和edgs變少了很多。附上鏈接:https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html
構建階段在圖層圖上執(zhí)行以下優(yōu)化:
1.Elimination of layers whose outputs are not used:消除未使用輸出的層
2.Fusion of convolution, bias and ReLU operations:融合conv || bias || Relu 操作
3.Aggregation of operations with sufficiently similar parameters and the same source tensor:
聚合相似或相同參數的向量。(for example, the 1x1 convolutions in GoogleNet v5’s inception module)、
4.Merging of concatenation layers by directing layer outputs to the correct eventual destination.
通過輸出合并鏈接層