def test_toy(self, device): inp = torch.zeros(1, 1, 32, 32, device=device) inp[:, :, :16, :] = 1 ori = OriNet(True).to(device=device, dtype=inp.dtype).eval() ang = ori(inp) expected = torch.tensor([70.58], device=device) assert_allclose(kornia.rad2deg(ang), expected, atol=1e-2, rtol=1e-3)
def test_toy(self, device): ori = PatchDominantGradientOrientation(19).to(device) inp = torch.zeros(1, 1, 19, 19, device=device) inp[:, :, :10, :] = 1 ang = ori(inp) expected = torch.tensor([90.], device=device) assert_allclose(kornia.rad2deg(ang), expected)
def test_deg2rad(batch_shape, device, dtype): # generate input data x_deg = 180. * torch.rand(batch_shape, device=device, dtype=dtype) # convert radians/degrees x_rad = kornia.deg2rad(x_deg) x_rad_to_deg = kornia.rad2deg(x_rad) assert_allclose(x_deg, x_rad_to_deg, atol=1e-4, rtol=1e-4) assert gradcheck(kornia.deg2rad, (tensor_to_gradcheck_var(x_deg), ), raise_exception=True)
def test_rad2deg(batch_shape, device, dtype): # generate input data x_rad = kornia.pi * torch.rand(batch_shape, device=device, dtype=dtype) # convert radians/degrees x_deg = kornia.rad2deg(x_rad) x_deg_to_rad = kornia.deg2rad(x_deg) # compute error assert_allclose(x_rad, x_deg_to_rad) # evaluate function gradient assert gradcheck(kornia.rad2deg, (tensor_to_gradcheck_var(x_rad), ), raise_exception=True)
def test_deg2rad(batch_shape, device_type): # generate input data x_deg = 180. * torch.rand(batch_shape) x_deg = x_deg.to(torch.device(device_type)) # convert radians/degrees x_rad = kornia.deg2rad(x_deg) x_rad_to_deg = kornia.rad2deg(x_rad) # compute error error = utils.compute_mse(x_deg, x_rad_to_deg) assert pytest.approx(error.item(), 0.0) assert gradcheck(kornia.deg2rad, (utils.tensor_to_gradcheck_var(x_deg),), raise_exception=True)
def test_rad2deg(batch_shape, device_type): # generate input data x_rad = kornia.pi * torch.rand(batch_shape) x_rad = x_rad.to(torch.device(device_type)) # convert radians/degrees x_deg = kornia.rad2deg(x_rad) x_deg_to_rad = kornia.deg2rad(x_deg) # compute error error = utils.compute_mse(x_rad, x_deg_to_rad) # evaluate function gradient assert gradcheck(kornia.rad2deg, (utils.tensor_to_gradcheck_var(x_rad),), raise_exception=True)
def get_laf_orientation(LAF: torch.Tensor) -> torch.Tensor: """Returns orientation of the LAFs, in degrees. Args: LAF: (torch.Tensor): tensor [BxNx2x3]. Returns: torch.Tensor: tensor BxNx1 . Shape: - Input: :math: `(B, N, 2, 3)` - Output: :math: `(B, N, 1)` Example: >>> input = torch.ones(1, 5, 2, 3) # BxNx2x3 >>> output = get_laf_orientation(input) # BxNx1 """ raise_error_if_laf_is_not_valid(LAF) angle_rad: torch.Tensor = torch.atan2(LAF[..., 0, 1], LAF[..., 0, 0]) return kornia.rad2deg(angle_rad).unsqueeze(-1)