| 289 | ) |
| 290 | |
| 291 | def reduce_boxes(self,scores,boxes,names,iou_threshold = 0.5): |
| 292 | # print("debug!!!!$$$$$$$$$$$$$$$$$$$") |
| 293 | # print(scores) |
| 294 | # print(boxes) |
| 295 | # print(names) |
| 296 | keep_boxes = torch.ones(len(boxes), dtype=torch.bool) |
| 297 | for i in range(len(boxes)): |
| 298 | for j in range(i+1, len(boxes)): |
| 299 | if iou(boxes[i], boxes[j]) > iou_threshold and keep_boxes[i] and keep_boxes[j]: |
| 300 | if scores[i] > scores[j]: |
| 301 | keep_boxes[j] = False |
| 302 | else: |
| 303 | keep_boxes[i] = False |
| 304 | # print("keep_boxes",keep_boxes) |
| 305 | scores = torch.tensor(scores) if not isinstance(scores, torch.Tensor) else scores |
| 306 | filtered_scores = scores[keep_boxes] |
| 307 | filtered_boxes = boxes[keep_boxes] |
| 308 | filtered_names = [name for i, name in enumerate(names) if keep_boxes[i]] |
| 309 | |
| 310 | return filtered_scores,filtered_boxes,filtered_names |
| 311 | |
| 312 | |
| 313 | def refine_bbox_dict(self,boxes, names): |