Skip to content

Commit

Permalink
Add scores to MaskRCNN result output filter
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene123tw committed Nov 28, 2024
1 parent 8765ac0 commit c98825a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/otx/algo/instance_segmentation/segmentors/maskrcnn_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def postprocess(
for i, (pred, scale_factor, ori_shape) in enumerate(zip(result, scale_factors, ori_shapes)):
boxes = pred["boxes"]
labels = pred["labels"]
scores = pred["scores"]
_scale_factor = [1 / s for s in scale_factor] # (H, W)
boxes = boxes * boxes.new_tensor(_scale_factor[::-1]).repeat((1, int(boxes.size(-1) / 2)))
h, w = ori_shape
Expand All @@ -99,8 +100,10 @@ def postprocess(
keep_indices = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1]) > 0
boxes = boxes[keep_indices > 0]
labels = labels[keep_indices > 0]
scores = scores[keep_indices > 0]
result[i]["boxes"] = boxes
result[i]["labels"] = labels - 1 # Convert back to 0-indexed labels
result[i]["scores"] = scores
if "masks" in pred:
masks = pred["masks"][keep_indices]
masks = paste_masks_in_image(masks, boxes, ori_shape)
Expand Down

0 comments on commit c98825a

Please sign in to comment.