def test_additional_and_batch(self): ious = intersection_over_union(self.t12_bboxes1, self.t12_bboxes2, box_format="corners") all_true = torch.all( torch.abs(self.t12_correct_ious - ious.squeeze(1)) < self.epsilon) self.assertTrue(all_true)
def nms(bboxes, iou_threshold, threshold, box_format='corners'): assert type(bboxes) == list bboxes = [box for box in bboxes if box[1] > threshold] bboxes_after_nms = [] bboxes = sorted(bboxes, key=lambda x: x[1], reverse=True) while bboxes: chosen_box = bboxes.pop(0) bboxes = [box for box in bboxes if box[0] != chosen_box[0] or intersection_over_union(torch.tensor(chosen_box[2:]), torch.tensor(box[2:]), box_format=box_format) < iou_threshold] bboxes_after_nms.append(chosen_box) return bboxes_after_nms
def test_both_inside_cell_shares_entire_area(self): iou = intersection_over_union(self.t5_box1, self.t5_box2, box_format="midpoint") self.assertTrue((torch.abs(iou - self.t5_correct_iou) < self.epsilon))
def test_partially_outside_cell_shares_area(self): iou = intersection_over_union(self.t2_box1, self.t2_box2, box_format="midpoint") self.assertTrue((torch.abs(iou - self.t2_correct_iou) < self.epsilon))
def test_box_format_x1_y1_x2_y2(self): iou = intersection_over_union(self.t6_box1, self.t6_box2, box_format="corners") self.assertTrue((torch.abs(iou - self.t6_correct_iou) < self.epsilon))