Example #1
0
 def test_process_single_batch_motion_large_depth(self):
     image_0 = torch.Tensor([[[0, 0], [2, 2]], [[1, 1], [3, 3]],
                             [[2, 2], [4, 4]]])
     ego_motion_vectors = [torch.Tensor([10, 10, 10, 0, 0, 0])]
     disp_map_0 = torch.Tensor([[1e-8, 1e-8], [1e-8, 1e-8]])
     calib_0 = torch.Tensor([[50, 0, 20], [0, 60, 10], [0, 0, 1]])
     image_input = torch.stack([image_0, image_0], dim=0)
     disp_input = torch.stack([disp_map_0, disp_map_0], dim=0)
     calib_input = torch.stack([calib_0, calib_0], dim=0)
     loss, out_images = process_single_batch(image_input,
                                             ego_motion_vectors, disp_input,
                                             calib_input)
     self.assertTrue(near_tensor_equality(image_0, out_images[0], tol=1e-2))
     self.assertTrue(near_tensor_equality(loss, torch.Tensor([0])))
Example #2
0
 def test_cam_to_image_mask(self):
     image = torch.Tensor([[[0, 0, 0], [0, 5, 0]], [[1, 6, 1], [1, 1, 1]],
                           [[2, 7, 2], [2, 2, 2]]])
     proj_mat = torch.Tensor([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                              [0, 0, 0, 1]])
     cam_coords = torch.Tensor([[0, 1, 2, 0, 1, 2], [1, 1, 1, 2, 2, 2],
                                [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]])
     output_image, mask = cam_to_image(proj_mat, cam_coords, image)
     expected_mask = torch.Tensor([[1., 1., 1.], [0., 0., 0.]])
     expected_out = torch.Tensor([[[0., 5., 0.], [0., 0., 0.]],
                                  [[1., 1., 1.], [0., 0., 0.]],
                                  [[2., 2., 2.], [0., 0., 0.]]])
     self.assertTrue(near_tensor_equality(output_image, expected_out))
     self.assertTrue(near_tensor_equality(mask, expected_mask))
Example #3
0
 def test_six_dof_vec_to_matrix_simple(self):
     vec6 = torch.Tensor([1, 5, 10, np.pi, 0, 0])
     mat = six_dof_vec_to_matrix(vec6)
     print(mat)
     expected_mat = torch.Tensor([[1, 0, 0, 1], [0, -1, 0, 5],
                                  [0, 0, -1, 10], [0, 0, 0, 1]])
     self.assertTrue(near_tensor_equality(mat, expected_mat))
Example #4
0
 def test_six_dof_vec_to_matrix_base(self):
     vec6 = torch.Tensor([0, 0, 0, 0, 0, 0])
     mat = six_dof_vec_to_matrix(vec6)
     print(mat)
     expected_mat = torch.Tensor([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                                  [0, 0, 0, 1]])
     self.assertTrue(near_tensor_equality(mat, expected_mat))
Example #5
0
 def test_euler_to_mat_rot_x(self):
     # rotate around z by pi/2
     r = torch.Tensor([0, 0, old_div(np.pi, 2)])
     mat = euler_to_mat(r)
     print(mat)
     expected_mat = torch.Tensor([[0, -1, 0], [1, 0, 0], [0, 0, 1]])
     self.assertTrue(near_tensor_equality(mat, expected_mat))
Example #6
0
 def test_euler_to_mat_rot_x(self):
     # rotate around x by pi
     r = torch.Tensor([np.pi, 0, 0])
     mat = euler_to_mat(r)
     print(mat)
     expected_mat = torch.Tensor([[1, 0, 0], [0, -1, 0], [0, 0, -1]])
     self.assertTrue(near_tensor_equality(mat, expected_mat))
Example #7
0
 def test_rescale_boxes_no_offset(self):
     boxes = torch.Tensor([[0, 0, 1, 1], [2, 2, 4, 4]])
     scale = [1, 2]
     scaled_boxes = rescale_boxes(boxes, scale)
     expected_boxes = torch.Tensor([[0., 0., 2., 1.], [4., 2., 8., 4.]])
     # print expected_boxes
     self.assertTrue(near_tensor_equality(scaled_boxes, expected_boxes))
Example #8
0
 def test_batch_box_IOU(self):
     t1 = torch.Tensor([[0, 0, 1, 1], [2, 2, 8, 8], [-1, -1, 0, 0]])
     t2 = torch.Tensor([[0, 0, 1, 1], [3, 3, 9, 9]])
     ious = batch_box_IOU(t1, t2)
     expected_matrix = torch.Tensor([[1.0000, 0.0000], [0.0000, 0.5319],
                                     [0.0000, 0.0000]])
     self.assertTrue(near_tensor_equality(ious, expected_matrix))
Example #9
0
 def test_euc_distance_cost(self):
     t1 = torch.Tensor([[0, 0, 1, 1], [2, 2, 8, 8], [-1, -1, 0, 0]])
     t2 = torch.Tensor([[0, 0, 1, 1], [3, 3, 9, 9]])
     distmat = euc_distance_cost(t1, t2)
     expected_matrix = torch.Tensor([[0.0000, 60.5000], [40.5000, 2.0000],
                                     [2.0000, 84.5000]])
     self.assertTrue(near_tensor_equality(distmat, expected_matrix))
Example #10
0
 def test_cam_to_image_non_square(self):
     image = torch.Tensor([[[0, 0, 0], [0, 5, 0]], [[1, 6, 1], [1, 1, 1]],
                           [[2, 7, 2], [2, 2, 2]]])
     proj_mat = torch.Tensor([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                              [0, 0, 0, 1]])
     cam_coords = torch.Tensor([[0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1],
                                [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]])
     output_image, _ = cam_to_image(proj_mat, cam_coords, image)
     self.assertTrue(near_tensor_equality(output_image, image))
Example #11
0
 def test_rescale_boxes_with_offset(self):
     boxes = torch.Tensor([[0, 0, 1, 1], [2, 2, 4, 4]])
     scale = [1, 2]
     offset = [40, 30]
     scaled_boxes = rescale_boxes(boxes, scale, offset)
     expected_boxes = torch.Tensor([[30., 40., 32., 41.],
                                    [34., 42., 38., 44.]])
     # print scaled_boxes
     self.assertTrue(near_tensor_equality(scaled_boxes, expected_boxes))
Example #12
0
    def test_image_to_cam_base(self):
        image = torch.Tensor([[[0, 0], [2, 2]], [[1, 1], [3, 3]],
                              [[2, 2], [4, 4]]])
        disp = torch.Tensor([[1, 1], [5, 5]])
        intrin = torch.Tensor([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

        output_coords = image_to_cam(image, disp, intrin)
        expected_output_coords = torch.Tensor([[0., 1., 0., 0.2],
                                               [0., 0., 0.2, 0.2],
                                               [1., 1., 0.2, 0.2]])
        self.assertTrue(
            near_tensor_equality(expected_output_coords, output_coords))
Example #13
0
 def test_euler_to_mat_base(self):
     # test base case: no rotation
     r = torch.Tensor([0, 0, 0])
     mat = euler_to_mat(r)
     expected_mat = torch.Tensor([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
     self.assertTrue(near_tensor_equality(mat, expected_mat))
Example #14
0
 def test_batch_box_area(self):
     boxes = torch.Tensor([[0, 0, 1, 1], [2, 2, 8, 8], [0, 0, 0, 0]])
     areas = batch_box_area(boxes)
     expected_areas = torch.tensor([[1., 36., 0.]]).transpose(0, 1)
     self.assertTrue(near_tensor_equality(areas, expected_areas))
Example #15
0
 def test_batch_box_IOU_edge_cases(self):
     t1 = torch.Tensor([[0, 0, 0, 0]])
     t2 = torch.Tensor([[0, 0, 0, 0]])
     ious = batch_box_IOU(t1, t2)
     expected_matrix = torch.Tensor([[0.]])
     self.assertTrue(near_tensor_equality(ious, expected_matrix))