Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP metric, fix metric for CUDA execution #673

Merged
merged 8 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed `torch.sort` currently does not support bool dtype on CUDA ([#665](https://github.com/PyTorchLightning/metrics/pull/665))


- Fixed initialization of tensors to be on correct device for `MAP` metric ([#673](https://github.com/PyTorchLightning/metrics/pull/673))


## [0.6.1] - 2021-12-06

Expand Down
10 changes: 7 additions & 3 deletions torchmetrics/detection/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ def _evaluate_image(
nb_iou_thrs = len(self.iou_thresholds)
nb_gt = len(gt)
nb_det = len(det)
gt_matches = torch.zeros((nb_iou_thrs, nb_gt), dtype=torch.bool)
det_matches = torch.zeros((nb_iou_thrs, nb_det), dtype=torch.bool)
gt_matches = torch.zeros((nb_iou_thrs, nb_gt), dtype=torch.bool, device=self.device)
det_matches = torch.zeros((nb_iou_thrs, nb_det), dtype=torch.bool, device=self.device)
gt_ignore = ignore_area_sorted
det_ignore = torch.zeros((nb_iou_thrs, nb_det), dtype=torch.bool)
det_ignore = torch.zeros((nb_iou_thrs, nb_det), dtype=torch.bool, device=self.device)
if torch.numel(ious) > 0:
for idx_iou, t in enumerate(self.iou_thresholds):
for idx_det in range(nb_det):
Expand Down Expand Up @@ -565,6 +565,10 @@ def _calculate(self, class_ids: List) -> Tuple[Dict, MAPMetricResults, MARMetric
recall = -torch.ones((nb_iou_thrs, nb_classes, nb_bbox_areas, nb_max_det_thrs))
scores = -torch.ones((nb_iou_thrs, nb_rec_thrs, nb_classes, nb_bbox_areas, nb_max_det_thrs))

# move tensors if necessary
self.max_detection_thresholds = self.max_detection_thresholds.to(self.device)
self.rec_thresholds = self.rec_thresholds.to(self.device)

# retrieve E at each category, area range, and max number of detections
for idx_cls in range(nb_classes):
for idx_bbox_area in range(nb_bbox_areas):
Expand Down