未验证 提交 99579e6a 编写于 作者: G Guanghua Yu 提交者: GitHub

remove condition block && some todo (#2882)

上级 0adc553a
...@@ -38,10 +38,10 @@ def visualize_box_mask(im, results, labels, threshold=0.5): ...@@ -38,10 +38,10 @@ def visualize_box_mask(im, results, labels, threshold=0.5):
im = Image.open(im).convert('RGB') im = Image.open(im).convert('RGB')
else: else:
im = Image.fromarray(im) 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 = draw_mask(
im, results['boxes'], results['masks'], labels, threshold=threshold) 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) im = draw_box(im, results['boxes'], labels, threshold=threshold)
if 'segm' in results: if 'segm' in results:
im = draw_segm( im = draw_segm(
......
...@@ -446,9 +446,6 @@ class SOLOv2Head(nn.Layer): ...@@ -446,9 +446,6 @@ class SOLOv2Head(nn.Layer):
y = paddle.zeros(shape=paddle.shape(cate_preds), dtype='float32') y = paddle.zeros(shape=paddle.shape(cate_preds), dtype='float32')
inds = paddle.where(cate_preds > self.score_threshold, cate_preds, y) inds = paddle.where(cate_preds > self.score_threshold, cate_preds, y)
inds = paddle.nonzero(inds) 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]) cate_preds = paddle.reshape(cate_preds, shape=[-1])
# Prevent empty and increase fake data # Prevent empty and increase fake data
ind_a = paddle.cast(paddle.shape(kernel_preds)[0], 'int64') ind_a = paddle.cast(paddle.shape(kernel_preds)[0], 'int64')
...@@ -530,6 +527,5 @@ class SOLOv2Head(nn.Layer): ...@@ -530,6 +527,5 @@ class SOLOv2Head(nn.Layer):
align_corners=False, align_corners=False,
align_mode=0), align_mode=0),
axis=[0]) axis=[0])
# TODO: support bool type seg_masks = paddle.cast(seg_masks > self.mask_threshold, 'uint8')
seg_masks = paddle.cast(seg_masks > self.mask_threshold, 'int32')
return seg_masks, cate_labels, cate_scores return seg_masks, cate_labels, cate_scores
...@@ -60,14 +60,6 @@ class BBoxPostProcess(object): ...@@ -60,14 +60,6 @@ class BBoxPostProcess(object):
else: else:
bbox_pred, bbox_num = self.decode(head_out, rois, im_shape, bbox_pred, bbox_num = self.decode(head_out, rois, im_shape,
scale_factor) 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 return bbox_pred, bbox_num
def get_pred(self, bboxes, bbox_num, im_shape, scale_factor): def get_pred(self, bboxes, bbox_num, im_shape, scale_factor):
...@@ -155,10 +147,6 @@ class MaskPostProcess(object): ...@@ -155,10 +147,6 @@ class MaskPostProcess(object):
gx = paddle.expand(img_x, [N, img_y.shape[1], img_x.shape[2]]) 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]]) 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) grid = paddle.stack([gx, gy], axis=3)
img_masks = F.grid_sample(masks, grid, align_corners=False) img_masks = F.grid_sample(masks, grid, align_corners=False)
return img_masks[:, 0] return img_masks[:, 0]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册