tensorflow集成tensorRT及原理分析

版本号: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 节点优化过的图。我们看看这个函数的参数:

Input_graph_def:冻结住的 TensorFlow 图

Outputs:输出节点名字的字符串列表,比如:[“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

构建阶段在图层图上执行以下优化:

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.

通过输出合并链接层

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 该文章为转载文章,作者简介:汪剑,现在在出门问问负责推荐与个性化。曾在微软雅虎工作,从事过搜索和推荐相关工作。 T...
    名字真的不重要阅读 5,387评论 0 3
  • 新书讯——长江文艺出版社重点推介 长篇小说 《双凤记》 作者:长江文艺出版社 《双凤记》是继《白鹿原》之后又一部书...
    流云满树阅读 1,376评论 1 1
  • 清晨天空飘着零星的雪花, 地面上铺了一层薄薄的柳絮。 注定是验证未经严寒怎能体会到温暖, 中午阳光冲出云霄把灿烂的...
    阿山老师阅读 653评论 0 0
  • 我所有奔跑的行装 并不想将它们早早地收藏 我所有还存留的梦想 并不想将它们围上城墙 奔跑的路上 道阻且长 就算是最...
    风吹雨落田阅读 183评论 0 0
  • 都说感情的世界——认真,你就输了;但写作的世界——点评,你就赚了。点评,可以提高你的总结能力、思考能力、分析能力、...
    蜗牛笔耕阅读 142评论 0 0