Skip to content

Commit

Permalink
Refactor detection FMetric (#4130)
Browse files Browse the repository at this point in the history
* Refactor detection FMetric

* Update

* Update

* Refactor FMeasure

* Update

* Update

* update

* Update changelog

* Add scores to MaskRCNN result output filter
  • Loading branch information
eugene123tw authored Dec 1, 2024
1 parent 5305b5d commit 33f27f3
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 366 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ All notable changes to this project will be documented in this file.
(<https://github.com/openvinotoolkit/training_extensions/pull/4073>)
- Upgrade OpenVINO to 2024.5 and NNCF to 2.14.0
(<https://github.com/openvinotoolkit/training_extensions/pull/4123>)
- Improve FMetric computation
(<https://github.com/openvinotoolkit/training_extensions/pull/4130>)

### Bug fixes

Expand Down
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
Loading

0 comments on commit 33f27f3

Please sign in to comment.