- 标题:mask_rcnn模型预测时报错
- 版本、环境信息:
1)PaddlePaddle版本:paddle1.7.1
2)GPU:nvidia V100, cuda7/cudnn9.0
4)系统环境:Linux 14
- 复现信息:
训练时不固定输入大小,但因业务需要,在导出模型时需固定了输入op的大小为(3, 800, 1344),故如下代码修改了模型,导致预测时报错。但同样是固定输入大小,faster/cascade rcnn可以顺利infer,但mask_rcnn/retinanet不能,请问是什么原因呢?
prog.global_block().var(op.name).desc.set_shape(tensor_shape)
# # 动态infer,修改所有shape
block_desc = prog.global_block().desc
for prog_op in prog.global_block().ops:
prog_op.desc.infer_shape(block_desc)
- 错误日志:
Traceback (most recent call last):
File "infer_demo.py", line 230, in <module>
infer(args)
File "infer_demo.py", line 163, in infer
return_numpy=False)
File "/root/miniconda3/lib/python3.7/site-packages/paddle/fluid/executor.py", line 783, in run
six.reraise(*sys.exc_info())
File "/root/miniconda3/lib/python3.7/site-packages/six.py", line 703, in reraise
raise value
File "/root/miniconda3/lib/python3.7/site-packages/paddle/fluid/executor.py", line 778, in run
use_program_cache=use_program_cache)
File "/root/miniconda3/lib/python3.7/site-packages/paddle/fluid/executor.py", line 831, in _run_impl
use_program_cache=use_program_cache)
File "/root/miniconda3/lib/python3.7/site-packages/paddle/fluid/executor.py", line 902, in _run_program
self._feed_data(program, feed, feed_var_name, scope)
File "/root/miniconda3/lib/python3.7/site-packages/paddle/fluid/executor.py", line 580, in _feed_data
check_feed_shape_type(var, cur_feed)
File "/root/miniconda3/lib/python3.7/site-packages/paddle/fluid/executor.py", line 230, in check_feed_shape_type
(var.name, len(var.shape), var.shape, feed_shape))
ValueError: The fed Variable 'image' should have dimensions = 4, shape = (-1, 3, 800, 1344), but received fed shape [1, 3, 1088, 800] on each device
2条答案
按热度按时间rjjhvcjd1#
如果希望在导出模型的时候固定输入长度,https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.3/docs/advanced_tutorials/deploy/EXPORT_MODEL.md#%E8%AE%BE%E7%BD%AE%E5%AF%BC%E5%87%BA%E6%A8%A1%E5%9E%8B%E7%9A%84%E8%BE%93%E5%85%A5%E5%A4%A7%E5%B0%8F 可以参考这里的文档,指定image_shape即可
在预测的时候由于rcnn和retinanet都是keep_ratio的方式进行resize,因此如果希望保持定长的话需要对resize的图片做padding。从报错信息来看resize的逻辑应该只是判断了短边resize到800然后长边不大于1344,而此时800,1344是固定height是800,width是1344的
unftdfkk2#
预测时希望是keep ratio的,不希望固定尺度,只是业务需要(框架转换/端移植等),需要读取输入变量的shape值(不能为None/-1),所以给了一个(800,1334)随意的值;奇怪的是,faster_rcnn/cascade模型,就算实际预测的大小和网络定义shape不同,也不会报错,但是mask_rcnn/retinanet都会报错。这是为啥?