def test_hot_diag_norm(self, device, dtype):
     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.],
     ]]]],
                          device=device,
                          dtype=dtype)
     softargmax = kornia.ConvSoftArgmax3d((1, 3, 3), (1, 2, 2), (0, 0, 0),
                                          temperature=10.,
                                          normalized_coordinates=True,
                                          output_value=True)
     expected_val = torch.tensor([[[[[0.1214, 0.], [0., 0.1214]]]]],
                                 device=device,
                                 dtype=dtype)
     expected_coord = torch.tensor(
         [[[[[[-1., -1.], [-1., -1.]]], [[[-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_allclose(val, expected_val, atol=1e-4, rtol=1e-4)
     assert_allclose(coords, expected_coord, atol=1e-4, rtol=1e-4)
 def test_cold_diag(self, device, dtype):
     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.],
     ]]]],
                          device=device,
                          dtype=dtype)
     softargmax = kornia.ConvSoftArgmax3d((1, 3, 3), (1, 2, 2), (0, 0, 0),
                                          temperature=0.05,
                                          normalized_coordinates=False,
                                          output_value=True)
     expected_val = torch.tensor([[[[[1., 0.], [0., 1.]]]]],
                                 device=device,
                                 dtype=dtype)
     expected_coord = torch.tensor(
         [[[[[[0., 0.], [0., 0.]]], [[[1., 3.], [1., 3.]]],
            [[[1., 1.], [3., 3.]]]]]],
         device=device,
         dtype=dtype)
     coords, val = softargmax(input)
     assert_allclose(val, expected_val, atol=1e-4, rtol=1e-4)
     assert_allclose(coords, expected_coord, atol=1e-4, rtol=1e-4)
Пример #3
0
 def test_cold_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.ConvSoftArgmax3d((1, 3, 3), (1, 2, 2), (0, 0, 0),
                                          temperature=0.05,
                                          normalized_coordinates=True,
                                          output_value=True)
     expected_val = torch.tensor([[[[[1., 0.], [0., 1.]]]]])
     expected_coord = torch.tensor([[[[[[-1., -1.], [-1., -1.]]],
                                      [[[-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)
Пример #4
0
 def test_hot_diag(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.ConvSoftArgmax3d((1, 3, 3), (1, 2, 2), (0, 0, 0),
                                          temperature=10.,
                                          normalized_coordinates=False,
                                          output_value=True)
     expected_val = torch.tensor([[[[[0.1214, 0.], [0., 0.1214]]]]])
     expected_coord = torch.tensor([[[[[[0., 0.], [0., 0.]]],
                                      [[[1., 3.], [1., 3.]]],
                                      [[[1., 1.], [3., 3.]]]]]])
     coords, val = softargmax(input)
     assert_allclose(val, expected_val)
     assert_allclose(coords, expected_coord)
Пример #5
0
 def test_smoke_with_val(self, device):
     input = torch.zeros(1, 1, 3, 3, 3).to(device)
     m = kornia.ConvSoftArgmax3d((3, 3, 3), output_value=True)
     coords, val = m(input)
     assert coords.shape == (1, 1, 3, 3, 3, 3)
     assert val.shape == (1, 1, 3, 3, 3)
Пример #6
0
 def test_smoke(self, device):
     input = torch.zeros(1, 1, 3, 3, 3).to(device)
     m = kornia.ConvSoftArgmax3d((3, 3, 3), output_value=False)
     assert m(input).shape == (1, 1, 3, 3, 3, 3)