diff --git a/deploy/python/visualize.py b/deploy/python/visualize.py index 6093572818225138af3984b1f07d4c1963ca3d5b..d659702743cee95719ea0b57a2e50e6c8f62b383 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 5f15461fa7fac5b2b8ba2b642fc8082fdaa15e53..9104b7d2aaf11ed494074d1eda9f10f8a3c3855c 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 1088880d29748eb3cb758a8bc61b92a6ca54e0ee..09199409283c05dca7c40dae8175f2d9ad7f27a6 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]