Giter Site home page Giter Site logo

reflectPad存在两个问题 about forward HOT 9 CLOSED

tencent avatar tencent commented on April 28, 2024
reflectPad存在两个问题

from forward.

Comments (9)

zhaoyiluo avatar zhaoyiluo commented on April 28, 2024

Hello @Ehrich-wen

针对您遇到的两个问题,想来确认几个点:

1、关于动态输入,请问您这边在构建项目的时候有打开编译选项 -DENABLE_DYNAMIC_BATCH=ON 么?Forward 是支持动态输入的,但需要在构建的时候打开该选项,否则程序在运行时会出错的。

我目前在打开该选项后做了测试,构建引擎时 max_batch_size==10,推理时 batch_size==5,Forward 测试结果与 LibTorch 测试结果相吻合,在 FP32 精度下误差仍保持在 1e-3 范围内。

2、这个问题是可能存在的,但由于我们这边没有 A100 显卡,暂时无法验证这个问题,先做了记录。

我目前在自己的工作环境下做了测试(T4 和 1050Ti),能保证该 op 的正确性。

希望以上信息能帮助到您 :)

from forward.

Ehrich-wen avatar Ehrich-wen commented on April 28, 2024

您好!感谢您的回复!
我这里输入的图片尺寸是动态的(w,h),batch是固定的,其中代码上有这样一段:

nvinfer1::DimsExprs ReflectionPadding2DPlugin::getOutputDimensions(
    int outputIndex, const nvinfer1::DimsExprs* inputs, int nbInputs,
    nvinfer1::IExprBuilder& exprBuilder) {
  nvinfer1::DimsExprs output(inputs[0]);
  output.d[2] = exprBuilder.constant(inputs[0].d[2]->getConstantValue() + padding_size_[2] +
                                     padding_size_[3]);
  output.d[3] = exprBuilder.constant(inputs[0].d[3]->getConstantValue() + padding_size_[0] +
                                     padding_size_[1]);

  return output;
}

这里的inputs[0].d[2]->getConstantValue()的写法应该是有问题的,因为当d[2]和d[3]都不是constant就会报错。TensorRT在parse onnx模型以及build trt engine的时候,会执行getOutputDimensions,此时d[2]和d[3]应该都不是constant。

from forward.

Ehrich-wen avatar Ehrich-wen commented on April 28, 2024

不好意思,关于第二个问题,测试显卡应该是P100,也是在动态输入w,h的情况下。我在2080TI上跑是正常的,在P100上定位了第一个ReflectPad的输入和输出,其中输入与2080TI是对齐的,但是输出差异非常大。我仔细的看了ReflectPad,始终没有找到原因。

from forward.

Ehrich-wen avatar Ehrich-wen commented on April 28, 2024

TensorRT 8.2.1GA提供了Pad的Reflect模式,改版本可以解决第二个问题。

from forward.

zhaoyiluo avatar zhaoyiluo commented on April 28, 2024

@Ehrich-wen ,感谢您的反馈~

关于第一点有两小点补充:

(1)针对 TF,Torch,Keras 框架的模型,在解析模型及构建 TRT 流程时,走的流程是:从输出节点逐个回溯模型内部的节点,直至解析到输入节点,这时候会生成一个中间件,这个中间件会被用来构建 TRT 模型;针对 ONNX 框架的模型,Forward 并没有采取上述流程,而是直接调用了 nvonnxparser::IParser::parseFromFile,由 TensorRT 直接负责对模型进行解析并构造推理引擎;

(2)Forward 目前仅支持 batch_size 为动态输入,且 batch_size 需要位于张量的第零维度,这解释了我们在 ReflectionPadding2DPlugin 中默认其他维度的数据为常量,直接调用了 inputs[0].d[2]->getConstantValue()inputs[0].d[3]->getConstantValue();结合动态 W 和 H 维度的情况来说,是我们目前还不支持这样的行为。

关于第二点的一些补充:

基于您之前问题描述的细节,我推测您这边使用的是 ONNX 模型,基于上述的说明,我推测这个是 TRT7 中存在的问题,并在 TRT8 中进行了修复,因此升级 TRT 版本可以解决这个问题。

欢迎继续追问哈~

from forward.

Ehrich-wen avatar Ehrich-wen commented on April 28, 2024

好的,非常感谢你的解答!我用的是onnx模型
关于第一个问题,我在ReflectPadding上修改了getOutputDimensions,并且同时支持了b以及hw的动态输入来解决。
关于第二个问题,我升级8.2.1之后就没再用这个自定义插件,后续我再测试一下。
再次感谢!

from forward.

zhaoyiluo avatar zhaoyiluo commented on April 28, 2024

好的,非常感谢你的解答!我用的是onnx模型 关于第一个问题,我在ReflectPadding上修改了getOutputDimensions,并且同时支持了b以及hw的动态输入来解决。 关于第二个问题,我升级8.2.1之后就没再用这个自定义插件,后续我再测试一下。 再次感谢!

使用愉快!:)

from forward.

github-actions avatar github-actions commented on April 28, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

from forward.

github-actions avatar github-actions commented on April 28, 2024

This issue was closed because it has been stalled for 5 days with no activity.

from forward.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.