Perform hard non-maximum-supression to filter out boxes with iou greater than threshold Args: box_scores (N, 5): boxes in corner-form and probabilities. iou_threshold: intersection over union threshold. top_k: keep top_k results. If k <= 0, keep all the results.
(box_scores, iou_threshold, top_k=-1, candidate_size=200)
| 31 | return overlap_area / (area0 + area1 - overlap_area + eps) |
| 32 | |
| 33 | def hard_nms(box_scores, iou_threshold, top_k=-1, candidate_size=200): |
| 34 | """ |
| 35 | Perform hard non-maximum-supression to filter out boxes with iou greater |
| 36 | than threshold |
| 37 | Args: |
| 38 | box_scores (N, 5): boxes in corner-form and probabilities. |
| 39 | iou_threshold: intersection over union threshold. |
| 40 | top_k: keep top_k results. If k <= 0, keep all the results. |
| 41 | candidate_size: only consider the candidates with the highest scores. |
| 42 | Returns: |
| 43 | picked: a list of indexes of the kept boxes |
| 44 | """ |
| 45 | scores = box_scores[:, -1] |
| 46 | boxes = box_scores[:, :-1] |
| 47 | picked = [] |
| 48 | indexes = np.argsort(scores) |
| 49 | indexes = indexes[-candidate_size:] |
| 50 | while len(indexes) > 0: |
| 51 | current = indexes[-1] |
| 52 | picked.append(current) |
| 53 | if 0 < top_k == len(picked) or len(indexes) == 1: |
| 54 | break |
| 55 | current_box = boxes[current, :] |
| 56 | indexes = indexes[:-1] |
| 57 | rest_boxes = boxes[indexes, :] |
| 58 | iou = iou_of( |
| 59 | rest_boxes, |
| 60 | np.expand_dims(current_box, axis=0), |
| 61 | ) |
| 62 | indexes = indexes[iou <= iou_threshold] |
| 63 | |
| 64 | return box_scores[picked, :] |
| 65 | |
| 66 | def predict(width, height, confidences, boxes, prob_threshold, iou_threshold=0.5, top_k=-1): |
| 67 | """ |