Exemple #1
0
 def test_pairwise_iou_0_degree_cuda(self):
     device = torch.device("cuda")
     boxes1 = torch.tensor(
         [[0.5, 0.5, 1.0, 1.0, 0.0], [0.5, 0.5, 1.0, 1.0, 0.0]],
         dtype=torch.float32,
         device=device,
     )
     boxes2 = torch.tensor(
         [
             [0.5, 0.5, 1.0, 1.0, 0.0],
             [0.25, 0.5, 0.5, 1.0, 0.0],
             [0.5, 0.25, 1.0, 0.5, 0.0],
             [0.25, 0.25, 0.5, 0.5, 0.0],
             [0.75, 0.75, 0.5, 0.5, 0.0],
             [1.0, 1.0, 1.0, 1.0, 0.0],
         ],
         dtype=torch.float32,
         device=device,
     )
     expected_ious = torch.tensor(
         [
             [1.0, 0.5, 0.5, 0.25, 0.25, 0.25 / (2 - 0.25)],
             [1.0, 0.5, 0.5, 0.25, 0.25, 0.25 / (2 - 0.25)],
         ],
         dtype=torch.float32,
         device=device,
     )
     ious = pairwise_iou(RotatedBoxes(boxes1), RotatedBoxes(boxes2))
     self.assertTrue(torch.allclose(ious, expected_ious))
Exemple #2
0
 def test_pairwise_iou_orthogonal_cuda(self):
     device = torch.device("cuda")
     boxes1 = torch.tensor([[5, 5, 10, 6, 55]],
                           dtype=torch.float32,
                           device=device)
     boxes2 = torch.tensor([[5, 5, 10, 6, -35]],
                           dtype=torch.float32,
                           device=device)
     iou = (6.0 * 6.0) / (6.0 * 6.0 + 4.0 * 6.0 + 4.0 * 6.0)
     expected_ious = torch.tensor([[iou]],
                                  dtype=torch.float32,
                                  device=device)
     ious = pairwise_iou(RotatedBoxes(boxes1), RotatedBoxes(boxes2))
     self.assertTrue(torch.allclose(ious, expected_ious))
Exemple #3
0
 def test_pairwise_iou_large_close_boxes_cuda(self):
     device = torch.device("cuda")
     boxes1 = torch.tensor(
         [[299.500000, 417.370422, 600.000000, 364.259186, 27.1828]],
         dtype=torch.float32,
         device=device,
     )
     boxes2 = torch.tensor(
         [[299.500000, 417.370422, 600.000000, 364.259155, 27.1828]],
         dtype=torch.float32,
         device=device,
     )
     iou = 364.259155 / 364.259186
     expected_ious = torch.tensor([[iou]],
                                  dtype=torch.float32,
                                  device=device)
     ious = pairwise_iou(RotatedBoxes(boxes1), RotatedBoxes(boxes2))
     self.assertTrue(torch.allclose(ious, expected_ious))
Exemple #4
0
 def test_pairwise_iou_45_degrees_cuda(self):
     device = torch.device("cuda")
     boxes1 = torch.tensor(
         [
             [1, 1, math.sqrt(2), math.sqrt(2), 45],
             [1, 1, 2 * math.sqrt(2), 2 * math.sqrt(2), -45],
         ],
         dtype=torch.float32,
         device=device,
     )
     boxes2 = torch.tensor([[1, 1, 2, 2, 0]],
                           dtype=torch.float32,
                           device=device)
     expected_ious = torch.tensor([[0.5], [0.5]],
                                  dtype=torch.float32,
                                  device=device)
     ious = pairwise_iou(RotatedBoxes(boxes1), RotatedBoxes(boxes2))
     self.assertTrue(torch.allclose(ious, expected_ious))
Exemple #5
0
 def test_pairwise_iou_many_boxes_cuda(self):
     device = torch.device("cuda")
     num_boxes1 = 100
     num_boxes2 = 200
     boxes1 = torch.stack([
         torch.tensor([5 + 20 * i, 5 + 20 * i, 10, 10, 0],
                      dtype=torch.float32,
                      device=device) for i in range(num_boxes1)
     ])
     boxes2 = torch.stack([
         torch.tensor(
             [5 + 20 * i, 5 + 20 * i, 10, 1 + 9 * i / num_boxes2, 0],
             dtype=torch.float32,
             device=device,
         ) for i in range(num_boxes2)
     ])
     expected_ious = torch.zeros(num_boxes1,
                                 num_boxes2,
                                 dtype=torch.float32,
                                 device=device)
     for i in range(min(num_boxes1, num_boxes2)):
         expected_ious[i][i] = (1 + 9 * i / num_boxes2) / 10.0
     ious = pairwise_iou(RotatedBoxes(boxes1), RotatedBoxes(boxes2))
     self.assertTrue(torch.allclose(ious, expected_ious))