Skip to content

Commit

Permalink
Merge pull request #572 from hglee98/fix-mAP
Browse files Browse the repository at this point in the history
[!HOTFIX] handle when there is no prediction
  • Loading branch information
illian01 authored Oct 29, 2024
2 parents b2371dd + 4ec76b8 commit 6e86061
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- Fix keyword error of segmentation training by `@illian01` in [PR 551](https://github.com/Nota-NetsPresso/netspresso-trainer/pull/551)
- Fix typo when saving optimizer state_dict by `@hglee98` in [PR 553](https://github.com/Nota-NetsPresso/netspresso-trainer/pull/553)
- Fix not initialized save_dtype error by `@hglee98` in [PR 565](https://github.com/Nota-NetsPresso/netspresso-trainer/pull/565)
- Fix mAP error in case of certain classes object is not in the dataset `@hglee98` in [PR 571](https://github.com/Nota-NetsPresso/netspresso-trainer/pull/571)
- Fix mAP error in case of certain classes object is not in the dataset `@hglee98` in [PR 571](https://github.com/Nota-NetsPresso/netspresso-trainer/pull/571), [PR 572](https://github.com/Nota-NetsPresso/netspresso-trainer/pull/572)

## Breaking Changes:

Expand Down
8 changes: 8 additions & 0 deletions src/netspresso_trainer/metrics/detection/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,18 @@ def average_precisions_per_class(
for class_idx, class_id in enumerate(unique_classes):
is_class = prediction_class_ids == class_id
total_true = class_counts[class_idx]
total_predictions = is_class.sum()

if total_true == 0:
continue

if total_predictions == 0:
for iou_level_idx in range(matches.shape[1]):
average_precisions[
int(class_id), iou_level_idx
] = 0.0
continue

false_positives = (1 - matches[is_class]).cumsum(0)
true_positives = matches[is_class].cumsum(0)
recall = true_positives / (total_true + eps)
Expand Down

0 comments on commit 6e86061

Please sign in to comment.