Example #1
0
 def test_jit(self, device):
     translation = torch.tensor([[1., 0.]]).to(device)
     batch_size, channels, height, width = 2, 3, 64, 64
     img = torch.ones(batch_size, channels, height, width).to(device)
     trans = kornia.Translate(translation)
     trans_traced = torch.jit.trace(kornia.Translate(translation), img)
     assert_allclose(trans(img), trans_traced(img))
Example #2
0
 def test_jit(self, device, dtype):
     translation = torch.tensor([[1.0, 0.0]], device=device, dtype=dtype)
     batch_size, channels, height, width = 2, 3, 64, 64
     img = torch.ones(batch_size, channels, height, width, device=device, dtype=dtype)
     trans = kornia.Translate(translation)
     trans_traced = torch.jit.trace(kornia.Translate(translation), img)
     assert_close(trans(img), trans_traced(img), atol=1e-4, rtol=1e-4)
Example #3
0
 def test_dxdy_batch_broadcast(self, device, dtype):
     # prepare input data
     inp = torch.tensor([[
         [1., 2.],
         [3., 4.],
         [5., 6.],
         [7., 8.],
     ]],
                        device=device,
                        dtype=dtype).repeat(2, 1, 1, 1)
     expected = torch.tensor([[[
         [0., 1.],
         [0., 3.],
         [0., 5.],
         [0., 7.],
     ]], [[
         [0., 1.],
         [0., 3.],
         [0., 5.],
         [0., 7.],
     ]]],
                             device=device,
                             dtype=dtype)
     # prepare transformation
     translation = torch.tensor([[1., 0.]], device=device, dtype=dtype)
     transform = kornia.Translate(translation, align_corners=True)
     assert_allclose(transform(inp), expected, atol=1e-4, rtol=1e-4)
Example #4
0
 def test_dxdy(self, device, dtype):
     # prepare input data
     inp = torch.tensor([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [7.0, 8.0]]], device=device, dtype=dtype)
     expected = torch.tensor([[[0.0, 1.0], [0.0, 3.0], [0.0, 5.0], [0.0, 7.0]]], device=device, dtype=dtype)
     # prepare transformation
     translation = torch.tensor([[1.0, 0.0]], device=device, dtype=dtype)
     transform = kornia.Translate(translation, align_corners=True)
     assert_close(transform(inp), expected, atol=1e-4, rtol=1e-4)
Example #5
0
 def test_dxdy(self, device):
     # prepare input data
     inp = torch.tensor([[
         [1., 2.],
         [3., 4.],
         [5., 6.],
         [7., 8.],
     ]]).to(device)
     expected = torch.tensor([[
         [0., 1.],
         [0., 3.],
         [0., 5.],
         [0., 7.],
     ]]).to(device)
     # prepare transformation
     translation = torch.tensor([[1., 0.]]).to(device)
     transform = kornia.Translate(translation, align_corners=True)
     assert_allclose(transform(inp), expected)
Example #6
0
 def test_dxdy(self):
     # prepare input data
     inp = torch.tensor([[
         [1., 2.],
         [3., 4.],
         [5., 6.],
         [7., 8.],
     ]])
     expected = torch.tensor([[
         [0., 1.],
         [0., 3.],
         [0., 5.],
         [0., 7.],
     ]])
     # prepare transformation
     translation = torch.tensor([[1., 0.]])
     transform = kornia.Translate(translation)
     assert_allclose(transform(inp), expected)
Example #7
0
 def test_dxdy_batch_broadcast(self, device):
     # prepare input data
     inp = torch.tensor([[
         [1., 2.],
         [3., 4.],
         [5., 6.],
         [7., 8.],
     ]]).repeat(2, 1, 1, 1).to(device)
     expected = torch.tensor([[[
         [0., 1.],
         [0., 3.],
         [0., 5.],
         [0., 7.],
     ]], [[
         [0., 1.],
         [0., 3.],
         [0., 5.],
         [0., 7.],
     ]]]).to(device)
     # prepare transformation
     translation = torch.tensor([[1., 0.]]).to(device)
     transform = kornia.Translate(translation)
     assert_allclose(transform(inp), expected)