(self, gt_boxes, anchors)
| 34 | return iou |
| 35 | |
| 36 | def __call__(self, gt_boxes, anchors): |
| 37 | if len(gt_boxes) == 0: |
| 38 | default_matches = torch.zeros((len(anchors)), dtype=torch.int64).to(anchors.tensor.device) |
| 39 | default_match_labels = torch.zeros((len(anchors)), dtype=torch.int8).to(anchors.tensor.device) + self.labels[0] |
| 40 | return default_matches, default_match_labels |
| 41 | |
| 42 | gt_boxes_tensor = gt_boxes.tensor |
| 43 | anchors_tensor = anchors.tensor |
| 44 | |
| 45 | max_ious = torch.zeros((len(anchors))).to(anchors_tensor.device) |
| 46 | matched_inds = torch.zeros((len(anchors)), dtype=torch.long).to(anchors_tensor.device) |
| 47 | gt_ious = torch.zeros((len(gt_boxes))).to(anchors_tensor.device) |
| 48 | |
| 49 | for i in range(len(gt_boxes)): |
| 50 | ious = self._iou(anchors_tensor, gt_boxes_tensor[i]) |
| 51 | gt_ious[i] = ious.max() |
| 52 | matched_inds = torch.where(ious > max_ious, torch.zeros(1, dtype=torch.long, device=matched_inds.device)+i, matched_inds) |
| 53 | max_ious = torch.max(ious, max_ious) |
| 54 | del(ious) |
| 55 | |
| 56 | matched_vals = max_ious |
| 57 | matches = matched_inds |
| 58 | |
| 59 | match_labels = matches.new_full(matches.size(), 1, dtype=torch.int8) |
| 60 | |
| 61 | for (l, low, high) in zip(self.labels, self.thresholds[:-1], self.thresholds[1:]): |
| 62 | low_high = (matched_vals >= low) & (matched_vals < high) |
| 63 | match_labels[low_high] = l |
| 64 | |
| 65 | if self.allow_low_quality_matches: |
| 66 | self.set_low_quality_matches_(match_labels, matched_vals, matches, gt_ious) |
| 67 | |
| 68 | return matches, match_labels |
| 69 | |
| 70 | def set_low_quality_matches_(self, match_labels, matched_vals, matches, gt_ious): |
| 71 | for i in range(len(gt_ious)): |
nothing calls this directly
no test coverage detected