From 99579e6a04d0245d38f4535aa4bb81c07a7d3506 Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Fri, 7 May 2021 12:46:34 +0800 Subject: [PATCH] remove condition block && some todo (#2882) --- deploy/python/visualize.py | 4 ++-- ppdet/modeling/heads/solov2_head.py | 6 +----- ppdet/modeling/post_process.py | 12 ------------ 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/deploy/python/visualize.py b/deploy/python/visualize.py index 609357281..d65970274 100644 --- a/deploy/python/visualize.py +++ b/deploy/python/visualize.py @@ -38,10 +38,10 @@ def visualize_box_mask(im, results, labels, threshold=0.5): im = Image.open(im).convert('RGB') else: im = Image.fromarray(im) - if 'masks' in results and 'boxes' in results: + if 'masks' in results and 'boxes' in results and len(results['boxes']) > 0: im = draw_mask( im, results['boxes'], results['masks'], labels, threshold=threshold) - if 'boxes' in results: + if 'boxes' in results and len(results['boxes']) > 0: im = draw_box(im, results['boxes'], labels, threshold=threshold) if 'segm' in results: im = draw_segm( diff --git a/ppdet/modeling/heads/solov2_head.py b/ppdet/modeling/heads/solov2_head.py index 5f15461fa..9104b7d2a 100644 --- a/ppdet/modeling/heads/solov2_head.py +++ b/ppdet/modeling/heads/solov2_head.py @@ -446,9 +446,6 @@ class SOLOv2Head(nn.Layer): y = paddle.zeros(shape=paddle.shape(cate_preds), dtype='float32') inds = paddle.where(cate_preds > self.score_threshold, cate_preds, y) inds = paddle.nonzero(inds) - if paddle.shape(inds)[0] == 0: - out = paddle.full(shape=[1], fill_value=-1) - return out, out, out cate_preds = paddle.reshape(cate_preds, shape=[-1]) # Prevent empty and increase fake data ind_a = paddle.cast(paddle.shape(kernel_preds)[0], 'int64') @@ -530,6 +527,5 @@ class SOLOv2Head(nn.Layer): align_corners=False, align_mode=0), axis=[0]) - # TODO: support bool type - seg_masks = paddle.cast(seg_masks > self.mask_threshold, 'int32') + seg_masks = paddle.cast(seg_masks > self.mask_threshold, 'uint8') return seg_masks, cate_labels, cate_scores diff --git a/ppdet/modeling/post_process.py b/ppdet/modeling/post_process.py index 1088880d2..091994092 100644 --- a/ppdet/modeling/post_process.py +++ b/ppdet/modeling/post_process.py @@ -60,14 +60,6 @@ class BBoxPostProcess(object): else: bbox_pred, bbox_num = self.decode(head_out, rois, im_shape, scale_factor) - - # Prevent empty bbox_pred from decode or NMS. - # Bboxes and score before NMS may be empty due to the score threshold. - if bbox_pred.shape[0] == 0: - bbox_pred = paddle.to_tensor( - np.array( - [[-1, 0.0, 0.0, 0.0, 0.0, 0.0]], dtype='float32')) - bbox_num = paddle.to_tensor(np.array([1], dtype='int32')) return bbox_pred, bbox_num def get_pred(self, bboxes, bbox_num, im_shape, scale_factor): @@ -155,10 +147,6 @@ class MaskPostProcess(object): gx = paddle.expand(img_x, [N, img_y.shape[1], img_x.shape[2]]) gy = paddle.expand(img_y, [N, img_y.shape[1], img_x.shape[2]]) - # TODO: Because paddle.expand transform error when dygraph - # to static, use reshape to avoid mistakes. - gx = paddle.reshape(gx, [N, img_y.shape[1], img_x.shape[2]]) - gy = paddle.reshape(gy, [N, img_y.shape[1], img_x.shape[2]]) grid = paddle.stack([gx, gy], axis=3) img_masks = F.grid_sample(masks, grid, align_corners=False) return img_masks[:, 0] -- GitLab