How to use the kornia.feature function in kornia

To help you get started, we’ve selected a few kornia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kornia / kornia / test / feature / test_responces_local_features.py View on Github external
def test_jit(self, device):
        @torch.jit.script
        def op_script(input, k):
            return kornia.feature.harris_response(input, k)
        k = torch.tensor(0.04)
        img = torch.rand(2, 3, 4, 5, device=device)
        actual = op_script(img, k)
        expected = kornia.feature.harris_response(img, k)
        assert_allclose(actual, expected)
github kornia / kornia / test / feature / test_harris.py View on Github external
def test_shape(self):
        inp = torch.ones(1, 3, 4, 4)
        sobel = kornia.feature.CornerHarris(k=0.04)
        assert sobel(inp).shape == (1, 3, 4, 4)
github kornia / kornia / test / feature / test_responces_local_features.py View on Github external
def test_shape(self, device):
        inp = torch.ones(1, 3, 4, 4, device=device)
        harris = kornia.feature.CornerHarris(k=0.04).to(device)
        assert harris(inp).shape == (1, 3, 4, 4)
github kornia / kornia / test / feature / test_laf.py View on Github external
def test_shape(self):
        inp = torch.ones(1, 3, 2, 3)
        rotmat = kornia.feature.get_laf_scale(inp)
        assert rotmat.shape == (1, 3, 1, 1)
github kornia / kornia / test / feature / test_laf.py View on Github external
def test_conversion(self):
        inp = torch.tensor([[10, -20, 0.01, 0, 0.01]]).float()
        inp = inp.view(1, 1, 5)
        expected = torch.tensor([[10, 0, 10.], [0, 10, -20]]).float()
        expected = expected.view(1, 1, 2, 3)
        laf = kornia.feature.ellipse_to_laf(inp)
        assert_allclose(laf, expected)
github kornia / kornia / test / feature / test_responces_local_features.py View on Github external
def test_gradcheck(self, device):
        batch_size, channels, height, width = 1, 2, 5, 4
        img = torch.rand(batch_size, channels, height, width, device=device)
        img = utils.tensor_to_gradcheck_var(img)  # to var
        assert gradcheck(kornia.feature.gftt_response, (img),
                         raise_exception=True, nondet_tol=1e-4)
github kornia / kornia / test / feature / test_laf.py View on Github external
def test_gradcheck(self):
        batch_size, channels, height, width = 1, 2, 2, 3
        laf = torch.rand(batch_size, channels, height, width)
        scale = torch.rand(batch_size)
        scale = utils.tensor_to_gradcheck_var(scale)  # to var
        laf = utils.tensor_to_gradcheck_var(laf)  # to var
        assert gradcheck(kornia.feature.scale_laf,
                         (laf, scale),
                         raise_exception=True, atol=1e-4)
github kornia / kornia / test / feature / test_laf.py View on Github external
def test_shape(self):
        inp = torch.rand(5, 3, 2, 3)
        img = torch.rand(5, 3, 10, 10)
        assert (5, 3) == kornia.feature.laf_is_inside_image(inp, img).shape
github kornia / kornia / test / feature / test_laf.py View on Github external
def test_gradcheck(self):
        batch_size, channels, height, width = 1, 2, 2, 3

        laf = torch.rand(batch_size, channels, height, width)
        img = torch.rand(batch_size, 3, 10, 32)
        img = utils.tensor_to_gradcheck_var(img)  # to var
        laf = utils.tensor_to_gradcheck_var(laf)  # to var
        assert gradcheck(kornia.feature.denormalize_laf,
                         (laf, img,),
                         raise_exception=True)
github kornia / kornia / kornia / geometry / linalg.py View on Github external
trans_01 (torch.Tensor): tensor for perspective transformations of shape
          :math:`(B, 3, 3)`.
        lafs_1 (torch.Tensor): tensor of lafs of shape :math:`(B, N, 2, 3)`.
    Returns:
        torch.Tensor: tensor of N-dimensional points.

    Shape:
        - Output: :math:`(B, N, 2, 3)`

    Examples:

        >>> lafs_1 = torch.rand(2, 4, 2, 3)  # BxNx2x3
        >>> trans_01 = torch.eye(3).view(1, 3, 3)  # Bx3x3
        >>> lafs_0 = kornia.perspective_transform_lafs(trans_01, lafs_1)  # BxNx2x3
    """
    kornia.feature.laf.raise_error_if_laf_is_not_valid(lafs_1)
    if not torch.is_tensor(trans_01):
        raise TypeError("Input type is not a torch.Tensor")
    if not trans_01.device == lafs_1.device:
        raise TypeError("Tensor must be in the same device")
    if not trans_01.shape[0] == lafs_1.shape[0]:
        raise ValueError("Input batch size must be the same for both tensors")
    if (not (trans_01.shape[-1] == 3)) or (not (trans_01.shape[-2] == 3)):
        raise ValueError("Tranformation should be homography")
    bs, n, _, _ = lafs_1.size()
    # First, we convert LAF to points
    threepts_1 = kornia.feature.laf.laf_to_three_points(lafs_1)
    points_1 = threepts_1.permute(0, 1, 3, 2).reshape(bs, n * 3, 2)

    # First, transform the points
    points_0 = transform_points(trans_01, points_1)
    # Back to LAF format