【问题标题】:Speed no improvement in TensorrtTensorrt 速度没有提升
【发布时间】:2019-06-04 09:42:39
【问题描述】:

我有 Openpose 的Tensorflow graph

使用 convert-to-uff 命令将图形转换为 uff 格式。

输出是

NOTE: UFF has been tested with TensorFlow 1.12.0. Other versions are not guaranteed to work
UFF Version 0.6.3
=== Automatically deduced input nodes ===
[name: "image"
op: "Placeholder"
attr {
  key: "dtype"
  value {
    type: DT_FLOAT
  }
}
attr {
  key: "shape"
  value {
    shape {
      dim {
        size: -1
      }
      dim {
        size: -1
      }
      dim {
        size: -1
      }
      dim {
        size: 3
      }
    }
  }
}
]
=========================================

=== Automatically deduced output nodes ===
[name: "Openpose/concat_stage7"
op: "ConcatV2"
input: "Mconv7_stage6_L2/BiasAdd"
input: "Mconv7_stage6_L1/BiasAdd"
input: "Openpose/concat_stage7/axis"
attr {
  key: "N"
  value {
    i: 2
  }
}
attr {
  key: "T"
  value {
    type: DT_FLOAT
  }
}
attr {
  key: "Tidx"
  value {
    type: DT_INT32
  }
}
]
==========================================

Using output node Openpose/concat_stage7
Converting to UFF graph
No. nodes: 463
UFF Output written to cmu/cmu_openpose.uff

我怎么知道转换正确,所有节点都转换了?

问题是运行Tensorrt引擎的速度没有提升/

我使用的是 Tensorrt 5.1.5 GA。

【问题讨论】:

    标签: tensorflow tensorrt


    【解决方案1】:

    TensorRT 通过组合层和优化来优化网络 内核选择以提高延迟、吞吐量和功率效率 和内存消耗。如果应用程序指定,它将 另外优化网络以在较低精度下运行,进一步 提高性能并减少内存需求。

    TensorRT 开发人员指南中所述,它不仅通过以较低的精度运行,还通过组合层和优化内核选择来改进 DL 模型 还有。

    如果您的 GPU 不支持混合精度,这并不意味着 TensorRT 没有用处。 TensorRT 将进行层融合并运行各种内核以选择最有效的内核。

    如果您没有看到任何改进,可能还有其他原因。也许你使用 cmu/cmu_openpose.uff 引擎的方式。

    【讨论】:

      【解决方案2】:

      你对 tensorRt 的理解是不正确的。 tensorRt inference 可能比 tensorflow inference 更快的主要原因来自:

      1. 积极地将多个层内核融合到一个内核中。即https://miro.medium.com/max/1155/0*7WA6t51EZ46355m6。
      2. 自动调整并为您的输入大小选择最快的内核实现。
      3. 降低的精度推理。

      如果你的网络有很多内存繁重的操作:tf.slice、tf.split、tf.concat,或者很多元素操作(例如,tf.exp(tf.exp( a + b - c)),那么 tensorRt 几乎没有什么可以做的,因为未实现融合内核(无法融合两个连续的 exp 操作)或几乎没有针对内存操作进行优化。

      也就是说,它还取决于模型的输入大小。 启动 cuda 内核会产生开销(比如 0.1 毫秒)。如果输入大小是 10x10 而不是 1000x1000,那么计算时间与内核启动时间相比是微不足道的。如果所需的计算量很小,你不会看到使用 tensorRt 的很多好处。

      我转换了您的模型并在 TitanXp (FP32) 上使用 TensoRt5.1.5 对其进行推理。这是我得到的:

      B=1 TensorRT avg per image 0.4569686s over 1000 iter.
      B=1 Tensorflow avg per image 0.5385810s over 1000 iter.
      

      图像尺寸为 1x3x1200x1920(批次 x 通道 x 高度 x 宽度)。

      【讨论】:

        【解决方案3】:

        我对 TensorRT 做了更多的阅读和理解。 对于那些有同样问题的人,让我描述一下我的理解。如果我的理解有误,请评论。

        我的 uff 转换很好。没有错误。我在 Tensorboard 上查看了图表,所有输入/输出都很好。

        我的 GPU 是 Quadro P4000。该显卡仅支持精度 FP32。

        TensorRT 的处理速度并不比使用 FP32 在 GPU 上运行 Tensorflow 更快,除非 graphsurgeon 修改了图形。

        优点是将 TensorRT 引擎转换为 FP16 或 INT8 格式。那么就可以看到使用TensorRT的优势了。

        在 FP32 格式中,使用 TensorRT 与在 GPU 上运行的 Tensorflow 相比没有优势。

        【讨论】:

        • In FP32 format, there is no advantage of using TensorRT over Tensorflow running on GPU. 这根本不是真的!检查上面的答案。
        猜你喜欢
        • 2011-05-14
        • 2013-05-22
        • 2020-07-21
        • 2013-05-23
        • 1970-01-01
        • 1970-01-01
        • 2013-04-24
        • 2017-04-24
        • 2012-06-06
        相关资源
        最近更新 更多