Fix no object for segment

Handle case when no bounding boxes are detected during segmentation
pull/126/head
triple Mu 1 year ago committed by GitHub
commit 90c3aeba1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      infer-seg.py
  2. 2
      models/torch_utils.py

@ -42,6 +42,11 @@ def main(args: argparse.Namespace) -> None:
device=device)
bboxes, scores, labels, masks = seg_postprocess(
data, bgr.shape[:2], args.conf_thres, args.iou_thres)
if bboxes is None:
# if no bounding box or others save original image
if not args.show:
cv2.imwrite(str(save_image), draw)
continue
masks = masks[:, dh:H - dh, dw:W - dw, :]
indices = (labels % len(MASK_COLORS)).long()
mask_colors = torch.asarray(MASK_COLORS, device=device)[indices]

@ -18,6 +18,8 @@ def seg_postprocess(
bboxes, scores, labels, maskconf = outputs.split([4, 1, 1, 32], 1)
scores, labels = scores.squeeze(), labels.squeeze()
idx = scores > conf_thres
if idx.sum() == 0: # no bounding boxes or seg were created
return None, None, None, None
bboxes, scores, labels, maskconf = \
bboxes[idx], scores[idx], labels[idx], maskconf[idx]
idx = batched_nms(bboxes, scores, labels, iou_thres)

Loading…
Cancel
Save