示例#1
0
 def test_gradcheck(self, device, dtype):
     # generate input data
     batch_size, num_points = 2, 3
     eye_size = 3
     points_src = torch.rand(batch_size, num_points, 2, 3, device=device, dtype=dtype)
     dst_homo_src = utils.create_random_homography(batch_size, eye_size).to(device=device, dtype=dtype)
     # evaluate function gradient
     points_src = utils.tensor_to_gradcheck_var(points_src)  # to var
     dst_homo_src = utils.tensor_to_gradcheck_var(dst_homo_src)  # to var
     assert gradcheck(kornia.feature.perspective_transform_lafs, (dst_homo_src, points_src), raise_exception=True)
示例#2
0
 def test_gradcheck(self):
     # generate input data
     batch_size, num_points, num_dims = 2, 3, 2
     eye_size = num_dims + 1
     points_src = torch.rand(batch_size, num_points, num_dims)
     dst_homo_src = utils.create_random_homography(batch_size, eye_size)
     # evaluate function gradient
     points_src = utils.tensor_to_gradcheck_var(points_src)  # to var
     dst_homo_src = utils.tensor_to_gradcheck_var(dst_homo_src)  # to var
     assert gradcheck(kornia.transform_points, (dst_homo_src, points_src,),
                      raise_exception=True)
示例#3
0
    def test_transform_points(self, batch_size, num_points, device, dtype):
        # generate input data
        eye_size = 3
        lafs_src = torch.rand(batch_size, num_points, 2, 3, device=device, dtype=dtype)

        dst_homo_src = utils.create_random_homography(batch_size, eye_size).to(device=device, dtype=dtype)

        # transform the points from dst to ref
        lafs_dst = kornia.feature.perspective_transform_lafs(dst_homo_src, lafs_src)

        # transform the points from ref to dst
        src_homo_dst = torch.inverse(dst_homo_src)
        lafs_dst_to_src = kornia.feature.perspective_transform_lafs(src_homo_dst, lafs_dst)

        # projected should be equal as initial
        assert_close(lafs_src, lafs_dst_to_src)
示例#4
0
    def test_transform_points(self, batch_size, num_points, num_dims, device, dtype):
        # generate input data
        eye_size = num_dims + 1
        points_src = torch.rand(batch_size, num_points, num_dims, device=device, dtype=dtype)

        dst_homo_src = utils.create_random_homography(batch_size, eye_size).to(device=device, dtype=dtype)
        dst_homo_src = dst_homo_src.to(device)

        # transform the points from dst to ref
        points_dst = kornia.geometry.linalg.transform_points(dst_homo_src, points_src)

        # transform the points from ref to dst
        src_homo_dst = torch.inverse(dst_homo_src)
        points_dst_to_src = kornia.geometry.linalg.transform_points(src_homo_dst, points_dst)

        # projected should be equal as initial
        assert_close(points_src, points_dst_to_src, atol=1e-4, rtol=1e-4)
示例#5
0
 def test_gradcheck(self, device):
     # generate input data
     batch_size, num_points, num_dims = 2, 3, 2
     points1 = torch.rand(batch_size,
                          num_points,
                          num_dims,
                          device=device,
                          dtype=torch.float64,
                          requires_grad=True)
     points2 = torch.rand(batch_size,
                          num_points,
                          num_dims,
                          device=device,
                          dtype=torch.float64)
     H = utils.create_random_homography(batch_size,
                                        3).type_as(points1).to(device)
     assert gradcheck(symmetric_transfer_error, (points1, points2, H),
                      raise_exception=True)
示例#6
0
    def test_transform_points(self, batch_size, num_points, num_dims,
                              device_type):
        # generate input data
        eye_size = num_dims + 1
        points_src = torch.rand(batch_size, num_points, num_dims)
        points_src = points_src.to(torch.device(device_type))

        dst_homo_src = utils.create_random_homography(batch_size, eye_size)
        dst_homo_src = dst_homo_src.to(torch.device(device_type))

        # transform the points from dst to ref
        points_dst = kornia.transform_points(dst_homo_src, points_src)

        # transform the points from ref to dst
        src_homo_dst = torch.inverse(dst_homo_src)
        points_dst_to_src = kornia.transform_points(src_homo_dst, points_dst)

        # projected should be equal as initial
        assert_allclose(points_src, points_dst_to_src)
示例#7
0
 def test_batch(self, device, dtype):
     batch_size = 5
     pts1 = torch.rand(batch_size, 3, 2, device=device, dtype=dtype)
     pts2 = torch.rand(batch_size, 3, 2, device=device, dtype=dtype)
     H = utils.create_random_homography(1, 3).type_as(pts1).to(device)
     assert symmetric_transfer_error(pts1, pts2, H).shape == (batch_size, 3)
示例#8
0
 def test_smoke(self, device, dtype):
     pts1 = torch.rand(1, 6, 2, device=device, dtype=dtype)
     pts2 = torch.rand(1, 6, 2, device=device, dtype=dtype)
     H = utils.create_random_homography(1, 3).type_as(pts1).to(device)
     assert symmetric_transfer_error(pts1, pts2, H).shape == (1, 6)