From 8f26de72350ec3d4a8042609ceca400553166325 Mon Sep 17 00:00:00 2001 From: Feng Ni Date: Tue, 19 Jan 2021 14:58:07 +0800 Subject: [PATCH] [Dygraph] fix dy FCOS deploy (#2095) * fix dy fcos deploy * fix dy fcos deploy, dtype float --- dygraph/ppdet/modeling/heads/fcos_head.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dygraph/ppdet/modeling/heads/fcos_head.py b/dygraph/ppdet/modeling/heads/fcos_head.py index 8c9da63be..1776d8c38 100644 --- a/dygraph/ppdet/modeling/heads/fcos_head.py +++ b/dygraph/ppdet/modeling/heads/fcos_head.py @@ -200,19 +200,21 @@ class FCOSHead(nn.Layer): self.scales_regs.append(scale_reg) def _compute_locatioins_by_level(self, fpn_stride, feature): - shape_fm = feature.shape + shape_fm = paddle.shape(feature) + shape_fm.stop_gradient = True h, w = shape_fm[2], shape_fm[3] shift_x = paddle.arange(0, w * fpn_stride, fpn_stride) shift_y = paddle.arange(0, h * fpn_stride, fpn_stride) shift_x = paddle.unsqueeze(shift_x, axis=0) shift_y = paddle.unsqueeze(shift_y, axis=1) - shift_x = paddle.expand_as(shift_x, feature[0, 0, :, :]) - shift_y = paddle.expand_as(shift_y, feature[0, 0, :, :]) + shift_x = paddle.expand(shift_x, shape=[h, w]) + shift_y = paddle.expand(shift_y, shape=[h, w]) shift_x.stop_gradient = True shift_y.stop_gradient = True shift_x = paddle.reshape(shift_x, shape=[-1]) shift_y = paddle.reshape(shift_y, shape=[-1]) - location = paddle.stack([shift_x, shift_y], axis=-1) + fpn_stride / 2 + location = paddle.stack( + [shift_x, shift_y], axis=-1) + float(fpn_stride) / 2 location.stop_gradient = True return location -- GitLab