π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
remove half log2 in `extract_patches` (#1616)
Dmytro Mishkin097db22331d4
diff --git a/kornia/feature/laf.py b/kornia/feature/laf.pyindex 8ce63b7c3..fdcfeccff 100644--- a/kornia/feature/laf.py+++ b/kornia/feature/laf.py@@ -473,8 +473,7 @@ def extract_patches_from_pyramid(B, N, _, _ = laf.size()_, ch, h, w = img.size()scale = 2.0 * get_laf_scale(denormalize_laf(nlaf, img)) / float(PS)- half: float = 0.5- pyr_idx = (scale.log2() + half).relu().long()+ pyr_idx = scale.log2().relu().long()cur_img = imgcur_pyr_level = 0out = torch.zeros(B, N, ch, PS, PS).to(nlaf.dtype).to(nlaf.device)diff --git a/test/feature/test_integrated.py b/test/feature/test_integrated.pyindex bcb5f3d55..26a9b82fd 100644--- a/test/feature/test_integrated.py+++ b/test/feature/test_integrated.py@@ -50,10 +50,10 @@ class TestGetLAFDescriptors:B, C, H, W = 1, 1, 32, 32PS = 16img = torch.rand(B, C, H, W, device=device)- centers = torch.tensor([[H / 3.0, W / 3.0], [2.0 * H / 3.0, W / 2.0]], device=device, dtype=dtype).view(+ centers = torch.tensor([[H / 2.0, W / 2.0], [2.0 * H / 3.0, W / 2.0]], device=device, dtype=dtype).view(1, 2, 2)- scales = torch.tensor([(H + W) / 4.0, (H + W) / 8.0], device=device, dtype=dtype).view(1, 2, 1, 1)+ scales = torch.tensor([(H + W) / 5.0, (H + W) / 6.0], device=device, dtype=dtype).view(1, 2, 1, 1)ori = torch.tensor([0.0, 30.0], device=device, dtype=dtype).view(1, 2, 1)lafs = kornia.feature.laf_from_center_scale_ori(centers, scales, ori)img = utils.tensor_to_gradcheck_var(img) # to var@@ -64,7 +64,6 @@ class TestGetLAFDescriptors:return inputs.mean(dim=(2, 3))desc = _MeanPatch()- img = utils.tensor_to_gradcheck_var(img) # to varassert gradcheck(get_laf_descriptors, (img, lafs, desc, PS, True),eps=1e-3, atol=1e-3, raise_exception=True, nondet_tol=1e-3)@@ -89,13 +88,15 @@ class TestLAFDescriptor:descs_reference = sift(patches.view(B1 * N1, CH1, H1, W1)).view(B1, N1, -1)assert_close(descs_test, descs_reference)- def test_gradcheck(self, device, dtype=torch.float64):+ def test_gradcheck(self, device):B, C, H, W = 1, 1, 32, 32PS = 16img = torch.rand(B, C, H, W, device=device)- centers = torch.tensor([[H / 3.0, W / 3.0], [2.0 * H / 3.0, W / 2.0]], device=device, dtype=dtype).view(1, 2, 2)- scales = torch.tensor([(H + W) / 4.0, (H + W) / 8.0], device=device, dtype=dtype).view(1, 2, 1, 1)- ori = torch.tensor([0.0, 30.0], device=device, dtype=dtype).view(1, 2, 1)+ centers = torch.tensor([[H / 2.0, W / 2.0], [2.0 * H / 3.0, W / 2.0]], device=device).view(+ 1, 2, 2+ )+ scales = torch.tensor([(H + W) / 5.0, (H + W) / 6.0], device=device).view(1, 2, 1, 1)+ ori = torch.tensor([0.0, 30.0], device=device).view(1, 2, 1)lafs = kornia.feature.laf_from_center_scale_ori(centers, scales, ori)img = utils.tensor_to_gradcheck_var(img) # to varlafs = utils.tensor_to_gradcheck_var(lafs) # to var@@ -103,9 +104,7 @@ class TestLAFDescriptor:class _MeanPatch(nn.Module):def forward(self, inputs):return inputs.mean(dim=(2, 3))-lafdesc = LAFDescriptor(_MeanPatch(), PS)- img = utils.tensor_to_gradcheck_var(img) # to varassert gradcheck(lafdesc, (img, lafs), eps=1e-3, atol=1e-3, raise_exception=True, nondet_tol=1e-3)