Non-Maximum Suppression for 3D Euler boxes. Additionally, only the top-k boxes will be kept for each category to avoid redundant boxes in the visualization. Args: pred_results (:obj:`InstanceData`): Results predicted by the model. iou_thr (float): IoU thresho
(pred_results, iou_thr=0.15, score_thr=0.075, topk_per_class=10)
| 77 | |
| 78 | |
| 79 | def nms_filter(pred_results, iou_thr=0.15, score_thr=0.075, topk_per_class=10): |
| 80 | """Non-Maximum Suppression for 3D Euler boxes. Additionally, only the top-k |
| 81 | boxes will be kept for each category to avoid redundant boxes in the |
| 82 | visualization. |
| 83 | |
| 84 | Args: |
| 85 | pred_results (:obj:`InstanceData`): |
| 86 | Results predicted by the model. |
| 87 | iou_thr (float): IoU thresholds for NMS. Defaults to 0.15. |
| 88 | score_thr (float): Score thresholds. |
| 89 | Instances with scores below thresholds will not be kept. |
| 90 | Defaults to 0.075. |
| 91 | topk_per_class (int): Number of instances kept per category. |
| 92 | Defaults to 10. |
| 93 | |
| 94 | Returns: |
| 95 | numpy.ndarray[float], np.ndarray[int]: |
| 96 | Filtered boxes with shape (N, 9) and labels with shape (N,). |
| 97 | """ |
| 98 | boxes = pred_results.bboxes_3d |
| 99 | boxes_tensor = boxes.tensor.cpu().numpy() |
| 100 | iou = boxes.overlaps(boxes, boxes, eps=1e-5) |
| 101 | score = pred_results.scores_3d.cpu().numpy() |
| 102 | label = pred_results.labels_3d.cpu().numpy() |
| 103 | selected_per_class = dict() |
| 104 | |
| 105 | n = boxes_tensor.shape[0] |
| 106 | idx = list(range(n)) |
| 107 | idx.sort(key=lambda x: score[x], reverse=True) |
| 108 | selected_idx = [] |
| 109 | for i in idx: |
| 110 | if selected_per_class.get(label[i], 0) >= topk_per_class: |
| 111 | continue |
| 112 | if score[i] < score_thr: |
| 113 | continue |
| 114 | bo = False |
| 115 | for j in selected_idx: |
| 116 | if iou[i][j] > iou_thr: |
| 117 | bo = True |
| 118 | break |
| 119 | if not bo: |
| 120 | selected_idx.append(i) |
| 121 | if label[i] not in selected_per_class: |
| 122 | selected_per_class[label[i]] = 1 |
| 123 | else: |
| 124 | selected_per_class[label[i]] += 1 |
| 125 | |
| 126 | return boxes_tensor[selected_idx], label[selected_idx] |
| 127 | |
| 128 | |
| 129 | def draw_camera(camera_pose, camera_size=0.5, return_points=False): |
no test coverage detected