Esempio n. 1
0
 def test_hot_diag_norm(self, device, dtype):
     input = torch.tensor(
         [[[
             [0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 1.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 1.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0],
         ]]],
         device=device,
         dtype=dtype,
     )
     softargmax = kornia.ConvSoftArgmax2d((3, 3), (2, 2), (0, 0),
                                          temperature=10.0,
                                          normalized_coordinates=True,
                                          output_value=True)
     expected_val = torch.tensor([[[[0.1214, 0.0], [0.0, 0.1214]]]],
                                 device=device,
                                 dtype=dtype)
     expected_coord = torch.tensor(
         [[[[[-0.5, 0.5], [-0.5, 0.5]], [[-0.5, -0.5], [0.5, 0.5]]]]],
         device=device,
         dtype=dtype)
     coords, val = softargmax(input)
     assert_close(val, expected_val, atol=1e-4, rtol=1e-4)
     assert_close(coords, expected_coord, atol=1e-4, rtol=1e-4)
Esempio n. 2
0
 def test_cold_diag(self, device, dtype):
     input = torch.tensor(
         [[[
             [0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 1.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0],
             [0.0, 0.0, 0.0, 1.0, 0.0],
             [0.0, 0.0, 0.0, 0.0, 0.0],
         ]]],
         device=device,
         dtype=dtype,
     )
     softargmax = kornia.ConvSoftArgmax2d((3, 3), (2, 2), (0, 0),
                                          temperature=0.05,
                                          normalized_coordinates=False,
                                          output_value=True)
     expected_val = torch.tensor([[[[1.0, 0.0], [0.0, 1.0]]]],
                                 device=device,
                                 dtype=dtype)
     expected_coord = torch.tensor(
         [[[[[1.0, 3.0], [1.0, 3.0]], [[1.0, 1.0], [3.0, 3.0]]]]],
         device=device,
         dtype=dtype)
     coords, val = softargmax(input)
     assert_close(val, expected_val, atol=1e-4, rtol=1e-4)
     assert_close(coords, expected_coord, atol=1e-4, rtol=1e-4)
Esempio n. 3
0
 def test_cold_diag(self, device):
     input = torch.tensor([[[
         [0., 0., 0., 0., 0.],
         [0., 1., 0., 0., 0.],
         [0., 0., 0., 0., 0.],
         [0., 0., 0., 1., 0.],
         [0., 0., 0., 0., 0.],
     ]]]).to(device)
     softargmax = kornia.ConvSoftArgmax2d((3, 3), (2, 2), (0, 0),
                                          temperature=0.05,
                                          normalized_coordinates=False,
                                          output_value=True)
     expected_val = torch.tensor([[[[1., 0.], [0., 1.]]]]).to(device)
     expected_coord = torch.tensor([[[[[1., 3.], [1., 3.]],
                                      [[1., 1.], [3., 3.]]]]]).to(device)
     coords, val = softargmax(input)
     assert_allclose(val, expected_val)
     assert_allclose(coords, expected_coord)
 def test_hot_diag_norm(self):
     input = torch.tensor([[[
         [0., 0., 0., 0., 0.],
         [0., 1., 0., 0., 0.],
         [0., 0., 0., 0., 0.],
         [0., 0., 0., 1., 0.],
         [0., 0., 0., 0., 0.],
     ]]])
     softargmax = kornia.ConvSoftArgmax2d((3, 3), (2, 2), (0, 0),
                                          temperature=10.,
                                          normalized_coordinates=True,
                                          output_value=True)
     expected_val = torch.tensor([[[[0.1214, 0.], [0., 0.1214]]]])
     expected_coord = torch.tensor([[[[[-0.5, 0.5], [-0.5, 0.5]],
                                      [[-0.5, -0.5], [0.5, 0.5]]]]])
     coords, val = softargmax(input)
     assert_allclose(val, expected_val)
     assert_allclose(coords, expected_coord)
Esempio n. 5
0
 def test_smoke_batch_with_val(self, device):
     input = torch.zeros(2, 5, 3, 3).to(device)
     m = kornia.ConvSoftArgmax2d((3, 3), output_value=True)
     coords, val = m(input)
     assert coords.shape == (2, 5, 2, 3, 3)
     assert val.shape == (2, 5, 3, 3)
Esempio n. 6
0
 def test_smoke_batch(self, device):
     input = torch.zeros(2, 5, 3, 3).to(device)
     m = kornia.ConvSoftArgmax2d()
     assert m(input).shape == (2, 5, 2, 3, 3)
Esempio n. 7
0
 def test_smoke(self, device):
     input = torch.zeros(1, 1, 3, 3).to(device)
     m = kornia.ConvSoftArgmax2d((3, 3))
     assert m(input).shape == (1, 1, 2, 3, 3)
 def test_smoke_with_val(self, device, dtype):
     input = torch.zeros(1, 1, 3, 3, device=device, dtype=dtype)
     m = kornia.ConvSoftArgmax2d((3, 3), output_value=True)
     coords, val = m(input)
     assert coords.shape == (1, 1, 2, 3, 3)
     assert val.shape == (1, 1, 3, 3)