Comments (9)
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.
您好!感谢您的回复!
我这里输入的图片尺寸是动态的(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.
不好意思,关于第二个问题,测试显卡应该是P100,也是在动态输入w,h的情况下。我在2080TI上跑是正常的,在P100上定位了第一个ReflectPad的输入和输出,其中输入与2080TI是对齐的,但是输出差异非常大。我仔细的看了ReflectPad,始终没有找到原因。
from forward.
TensorRT 8.2.1GA提供了Pad的Reflect模式,改版本可以解决第二个问题。
from forward.
@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.
好的,非常感谢你的解答!我用的是onnx模型
关于第一个问题,我在ReflectPadding上修改了getOutputDimensions,并且同时支持了b以及hw的动态输入来解决。
关于第二个问题,我升级8.2.1之后就没再用这个自定义插件,后续我再测试一下。
再次感谢!
from forward.
好的,非常感谢你的解答!我用的是onnx模型 关于第一个问题,我在ReflectPadding上修改了getOutputDimensions,并且同时支持了b以及hw的动态输入来解决。 关于第二个问题,我升级8.2.1之后就没再用这个自定义插件,后续我再测试一下。 再次感谢!
使用愉快!:)
from forward.
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.
This issue was closed because it has been stalled for 5 days with no activity.
from forward.
Related Issues (20)
- 使用这个Forward框架进行推断的时候会有精度损失吗? HOT 6
- 关于fwd-torch的几个路径的问题 HOT 2
- Segmentation fault (core dumped) when transfer keras model to trt. HOT 4
- Help to support tensorflow slim "Flatten" pattern to Tensorrt. HOT 10
- 编译VC项目时出错 HOT 14
- vs2017怎么跑demo? HOT 8
- Is have docker with all dependencies? HOT 3
- Will forward framework support paddlepaddle in the future? HOT 4
- win_python_keras版本加载模型时报错 HOT 4
- 编译出错 找不到cublas_device库 HOT 7
- keras.layer里Embedding的trt实现 HOT 8
- Keras中Flatten层的支持 HOT 2
- 对‘fwd::TrtForwardEngine::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用 HOT 9
- 是否考虑重新写一个模型序列化?? HOT 3
- 与trtorch等项目的优劣对比 HOT 3
- make报错 HOT 22
- 编译fwd-pytroch时提示缺少头文件 HOT 1
- 优化模型时报错 HOT 2
- [TRT] (Unnamed Layer* 0) [Convolution]: at least 4 dimensions are required for input HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forward.