PaddleYOLO v5-m 动态图转静态图出现 targets读取错误
请提出你的问题 Please ask your question
paddlepaddle == 2.3.2
使用官方提供的paddleYOLO 代码,数据集coco,使用yolov5_m_300e_coco.yml device:cpu,batchsize:2 使用了动态图转静态图方法,具体做法: 在PaddleYOLO/ppdet/engine/trainer.py model.train() 下面增加model = paddle.jit.to_static(model) 错误: File "D:\paddle\yolov5\PaddleYOLO\ppdet\modeling\losses\yolo_loss.py", line 286, in build_targets gt_class = targets['gt_class'][idx][:gt_num] * 1.0 print("idx,gt_num:",idx,gt_num) img_idx = np.repeat(np.array([[idx]]), gt_num, axis=0) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE print("img_idx.size,gt_class.size,gt_bbox.size:", img_idx.shape, gt_class.shape, gt_bbox.shape) gt_labels.append( File "<array_function internals>", line 6, in repeat
File "C:\Users\Anaconda3\envs\paddle\lib\site-packages\numpy\core\fromnumeric.py", line 479, in repeat
return _wrapfunc(a, 'repeat', repeats, axis=axis)
File "C:\Users\Anaconda3\envs\paddle\lib\site-packages\numpy\core\fromnumeric.py", line 58, in _wrapfunc
return bound(*args, **kwds)
ValueError: setting an array element with a sequence.
经过查找,发现错误出现在yolo_loss.py 的 gt_nums = [len(bbox) for bbox in targets['gt_bbox']] gt_nums 打印结果是: [var cast_2.tmp_0 : LOD_TENSOR.shape(1,).dtype(int32).stop_gradient(False), var cast_3.tmp_0 : LOD_TENSOR.shape(1,).dtype(int32).stop_gradient(False)] 在yolo_loss.py 的 gt_num = gt_nums[idx] ,gt_num打印结果是无数据 在动态图模式下,gt_nums是:[3,34] 这种形状
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~
Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the API,FAQ,Github Issue and AI community to get the answer.Have a nice day!
已收到问题,正在分析中~
@duwenzhao 从你打印的gt_nums 信息来看,都是Tensor类型,说明bbox.shape[0] 在静态图下都是-1,表示组网期未知。因此在取len(bbox)时,会触发转为paddle.shape(bbox)[0]。
建议把np.repeat 替换为 paddle.repeat试下