示例#1
0
 def test_jit(self, device, dtype):
     scale_factor = torch.tensor([[0.5, 0.5]], 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.Scale(scale_factor)
     trans_traced = torch.jit.trace(kornia.Scale(scale_factor), img)
     assert_close(trans(img), trans_traced(img), atol=1e-4, rtol=1e-4)
示例#2
0
 def test_jit(self, device):
     scale_factor = torch.tensor([[0.5, 0.5]]).to(device)
     batch_size, channels, height, width = 2, 3, 64, 64
     img = torch.ones(batch_size, channels, height, width).to(device)
     trans = kornia.Scale(scale_factor)
     trans_traced = torch.jit.trace(kornia.Scale(scale_factor), img)
     assert_allclose(trans(img), trans_traced(img))
示例#3
0
 def test_scale_factor_2(self, device):
     # prepare input data
     inp = torch.tensor([[[0., 0., 0., 0.], [0., 1., 1., 0.],
                          [0., 1., 1., 0.], [0., 0., 0., 0.]]]).to(device)
     # prepare transformation
     scale_factor = torch.tensor([[2., 2.]]).to(device)
     transform = kornia.Scale(scale_factor)
     assert_allclose(transform(inp).sum().item(), 12.25)
示例#4
0
 def test_scale_factor_05(self):
     # prepare input data
     inp = torch.tensor([[[1., 1., 1., 1.], [1., 1., 1., 1.],
                          [1., 1., 1., 1.], [1., 1., 1., 1.]]])
     expected = torch.tensor([[[0., 0., 0., 0.], [0., 1., 1., 0.],
                               [0., 1., 1., 0.], [0., 0., 0., 0.]]])
     # prepare transformation
     scale_factor = torch.tensor([0.5])
     transform = kornia.Scale(scale_factor)
     assert_allclose(transform(inp), expected)
示例#5
0
 def test_scale_factor_2(self, device, dtype):
     # prepare input data
     inp = torch.tensor(
         [[[0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 1.0, 0.0], [0.0, 1.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]]],
         device=device,
         dtype=dtype,
     )
     # prepare transformation
     scale_factor = torch.tensor([[2.0, 2.0]], device=device, dtype=dtype)
     transform = kornia.Scale(scale_factor)
     assert_close(transform(inp).sum().item(), 12.25, atol=1e-4, rtol=1e-4)
示例#6
0
 def test_scale_factor_05_batch2_broadcast(self, device):
     # prepare input data
     inp = torch.tensor([[[1., 1., 1., 1.], [1., 1., 1., 1.],
                          [1., 1., 1., 1.],
                          [1., 1., 1., 1.]]]).repeat(2, 1, 1, 1).to(device)
     expected = torch.tensor([[[0., 0., 0., 0.], [0., 1., 1., 0.],
                               [0., 1., 1., 0.], [0., 0., 0.,
                                                  0.]]]).to(device)
     # prepare transformation
     scale_factor = torch.tensor([[0.5, 0.5]]).to(device)
     transform = kornia.Scale(scale_factor)
     assert_allclose(transform(inp), expected)
示例#7
0
 def test_scale_factor_05_batch2(self, device, dtype):
     # prepare input data
     inp = torch.tensor([[[1., 1., 1., 1.], [1., 1., 1., 1.],
                          [1., 1., 1., 1.], [1., 1., 1., 1.]]],
                        device=device,
                        dtype=dtype).repeat(2, 1, 1, 1)
     expected = torch.tensor([[[0., 0., 0., 0.], [0., 1., 1., 0.],
                               [0., 1., 1., 0.], [0., 0., 0., 0.]]],
                             device=device,
                             dtype=dtype).repeat(2, 1, 1, 1)
     # prepare transformation
     scale_factor = torch.tensor([[0.5, 0.5]], device=device, dtype=dtype)
     transform = kornia.Scale(scale_factor)
     assert_allclose(transform(inp), expected, atol=1e-4, rtol=1e-4)
示例#8
0
 def test_scale_factor_05(self, device, dtype):
     # prepare input data
     inp = torch.tensor(
         [[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]]],
         device=device,
         dtype=dtype,
     )
     expected = torch.tensor(
         [[[0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 1.0, 0.0], [0.0, 1.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]]],
         device=device,
         dtype=dtype,
     )
     # prepare transformation
     scale_factor = torch.tensor([[0.5, 0.5]], device=device, dtype=dtype)
     transform = kornia.Scale(scale_factor)
     assert_close(transform(inp), expected, atol=1e-4, rtol=1e-4)