使用Fluid对图像变长数据多次训练/预测存在的问题
Fluid构建一个网络分为两个过程:compile time和run time
- 对于变长数据的预测过程可以分为以下两步:
Compile time过程Fluid根据Python输入data_const的shape计算得到ProgramDesc,根据输入data的shape计算得到各个Var的shapeRun time根据实际feed的data_real进行计算,如果输入是变长数据,data_real与data_const的shape不同,可能会引起一些op的错误 - 已经发现的问题
目标检测相关的一些Reshape API使用的是输入
Compile time的shape,所以在输入变长数据时会出错 ReshapeOp相关的一些: https://github.com/PaddlePaddle/Paddle/blob/9e0a94f069329b430d0843327e474712e079a660/python/paddle/fluid/layers/detection.py#L266-L268 https://github.com/PaddlePaddle/Paddle/blob/9e0a94f069329b430d0843327e474712e079a660/python/paddle/fluid/layers/detection.py#L679-L680 https://github.com/PaddlePaddle/Paddle/blob/edc32c089605944eda860e3404f8aff152a4ff38/python/paddle/fluid/layers/detection.py#L691 https://github.com/PaddlePaddle/Paddle/blob/9e0a94f069329b430d0843327e474712e079a660/python/paddle/fluid/layers/detection.py#L1009-L1012 https://github.com/PaddlePaddle/Paddle/blob/edc32c089605944eda860e3404f8aff152a4ff38/python/paddle/fluid/layers/detection.py#L1102-L1106 https://github.com/PaddlePaddle/Paddle/blob/9e0a94f069329b430d0843327e474712e079a660/python/paddle/fluid/layers/detection.py#L1118-L1122
能更详细的描述一下问题吗?
在使用变长图像数据做训练/预测时,输入数据存在两个shape
- 是在compile_time指定用来做各个Opeator InferShape的静态的shape,记做
shape_attr - 是run_time根据实际灌进去的数据的动态变化的shape,记做
shape_tensor
在使用变长图像做输入数据时,这两者会有diff,这个diff主要会影响到reshape op
reshape op从shape_attr或者shape_tensor得到输出尺寸,所以如果只给了reshape静态的shape_attr,reshape是无法把各种尺寸的输入data reshape到统一尺寸shape_attr的;
https://github.com/PaddlePaddle/Paddle/blob/c58af84c66ddd59d1fba72cbe2044e7ba0cd9ace/paddle/fluid/operators/reshape_op.cc#L85-L87
所以需要引入动态的shape_tensor,训练/预测时实时根据输入的tensor来决定输出的尺寸;或者使用[0,-1...]这样的shape_attr自动推算,也可以避免compile_time shape_attr和run_time实际feed数据尺寸不兼容的问题
@panyx0718
参数基本上都是和数据大小无关的,所以静态shape和动态shape必须结果是一致的。 一般的op只需要动态的shape。
是不是只有reshape, set_shape少量op是可能会依赖静态shape,而且容许动态shape和静态shape不一致?这样完善reshape这种op的报错机制就行?
Since you haven't replied for more than a year, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过一年未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。