π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
batch and test fixed
Dmytro Mishkina5f5c663ac7d
diff --git a/kornia/feature/affine_shape.py b/kornia/feature/affine_shape.pyindex 940df14a4..f4798a286 100644--- a/kornia/feature/affine_shape.py+++ b/kornia/feature/affine_shape.py@@ -35,7 +35,7 @@ class PatchAffineShapeEstimator(nn.Module):"input shape should be must be [Bx1x{}x{}]. ""Got {}".format(self.patch_size, self.patch_size, patch.size()))self.weighting = self.weighting.to(patch.dtype).to(patch.device)- grads: torch.Tensor = self.gradient(patch)+ grads: torch.Tensor = self.gradient(patch) * self.weighting# unpack the edgesgx: torch.Tensor = grads[:, :, 0]gy: torch.Tensor = grads[:, :, 1]diff --git a/kornia/feature/scale_space_detector.py b/kornia/feature/scale_space_detector.pyindex c599645e7..dce25da98 100644--- a/kornia/feature/scale_space_detector.py+++ b/kornia/feature/scale_space_detector.py@@ -118,7 +118,7 @@ class ScaleSpaceDetector(nn.Module):max_coords_best = _scale_index_to_scale(max_coords_best, sigmas_oct)# Create local affine frames (LAFs)- rotmat = angle_to_rotation_matrix(torch.zeros(B, N))+ rotmat = angle_to_rotation_matrix(torch.zeros(B, N).to(max_coords_best.device).to(max_coords_best.dtype))current_lafs = torch.cat([self.mr_size * max_coords_best[:, :, 0].view(B, N, 1, 1) * rotmat,max_coords_best[:, :, 1:3].view(B, N, 2, 1)], dim=3)# Normalize LAFsdiff --git a/kornia/geometry/transform/pyramid.py b/kornia/geometry/transform/pyramid.pyindex b4f7f4c6f..d4b8cd81d 100644--- a/kornia/geometry/transform/pyramid.py+++ b/kornia/geometry/transform/pyramid.py@@ -174,11 +174,11 @@ class ScalePyramid(nn.Module):cur_level = gaussian_blur2d(x, (ksize, ksize), (sigma, sigma))else:cur_level = x- sigmas = [cur_sigma * torch.ones(bs, self.n_levels).to(x.device)]+ sigmas = [cur_sigma * torch.ones(bs, self.n_levels).to(x.device).to(x.dtype)]pixel_dists = [pixel_distance * torch.ones(bs,self.n_levels).to(- x.device)]+ x.device).to(x.dtype)]pyr = [[cur_level.unsqueeze(1)]]oct_idx = 0while True:diff --git a/test/feature/test_affine_shape_estimator.py b/test/feature/test_affine_shape_estimator.pyindex 767a345e6..a2de7816d 100644--- a/test/feature/test_affine_shape_estimator.py+++ b/test/feature/test_affine_shape_estimator.py@@ -73,7 +73,9 @@ class TestLAFAffineShapeEstimator:batch_size, channels, height, width = 1, 1, 21, 21patches = torch.rand(batch_size, channels, height, width).float()patches = utils.tensor_to_gradcheck_var(patches) # to var- laf = torch.ones(batch_size, 4, 2, 3).float()+ laf = 0.5 * torch.ones(batch_size, 2, 2, 3).float()+ laf[:, :, 0, 1] = 0+ laf[:, :, 1, 0] = 0laf = utils.tensor_to_gradcheck_var(laf) # to var- assert gradcheck(LAFAffineShapeEstimator(8), (laf, patches),- raise_exception=True, rtol=1e-4, atol=1e-4)+ assert gradcheck(LAFAffineShapeEstimator(12), (laf, patches),+ raise_exception=True, rtol=1e-3, atol=1e-3)diff --git a/test/feature/test_laf.py b/test/feature/test_laf.pyindex da2170fd7..6a8a952ca 100644--- a/test/feature/test_laf.py+++ b/test/feature/test_laf.py@@ -279,7 +279,7 @@ class TestExtractPatchesPyr:assert patches.shape == (5, 4, 3, PS, PS)# TODO: check what to do to improve timing- # @pytest.mark.skip("The test takes too long to finish.")+ @pytest.mark.skip("The test takes too long to finish.")def test_gradcheck(self):nlaf = torch.tensor([[0.1, 0.001, 0.5], [0, 0.1, 0.5]]).float()nlaf = nlaf.view(1, 1, 2, 3)diff --git a/test/feature/test_local_features_orientation.py b/test/feature/test_local_features_orientation.pyindex edb69acb6..1a25eef0c 100644--- a/test/feature/test_local_features_orientation.py+++ b/test/feature/test_local_features_orientation.py@@ -108,7 +108,9 @@ class TestLAFOrienter:batch_size, channels, height, width = 1, 1, 21, 21patches = torch.rand(batch_size, channels, height, width).float()patches = utils.tensor_to_gradcheck_var(patches) # to var- laf = torch.ones(batch_size, 4, 2, 3).float()+ laf = torch.ones(batch_size, 2, 2, 3).float()+ laf[:, :, 0, 1] = 0+ laf[:, :, 1, 0] = 0laf = utils.tensor_to_gradcheck_var(laf) # to varassert gradcheck(LAFOrienter(8), (laf, patches),- raise_exception=True, rtol=1e-4, atol=1e-4)+ raise_exception=True, rtol=1e-3, atol=1e-3)diff --git a/test/feature/test_scale_space_detector.py b/test/feature/test_scale_space_detector.pyindex 3cdea6569..bce455de8 100644--- a/test/feature/test_scale_space_detector.py+++ b/test/feature/test_scale_space_detector.py@@ -16,20 +16,28 @@ class TestScaleSpaceDetector:assert lafs.shape == torch.Size([1, n_feats, 2, 3])assert resps.shape == torch.Size([1, n_feats])+ def test_shape_batch(self):+ inp = torch.rand(7, 1, 32, 32)+ n_feats = 10+ det = ScaleSpaceDetector(n_feats)+ lafs, resps = det(inp)+ assert lafs.shape == torch.Size([7, n_feats, 2, 3])+ assert resps.shape == torch.Size([7, n_feats])+def test_print(self):sift = ScaleSpaceDetector()sift.__repr__()def test_toy(self):inp = torch.zeros(1, 1, 33, 33)- inp[:, :, 8:-8, 8:-8] = 1.0+ inp[:, :, 13:-13, 13:-13] = 1.0n_feats = 1det = ScaleSpaceDetector(n_feats,resp_module=kornia.feature.BlobHessian(),mr_size=3.0)lafs, resps = det(inp)- expected_laf = torch.tensor([[[[12.1187, 0.0000, 15.9958], [0.0, 12.1187, 15.9958]]]])- expected_resp = torch.tensor([[0.0699]])+ expected_laf = torch.tensor([[[[6.0548, 0.0000, 16.0], [0.0, 6.0548, 16.0]]]])+ expected_resp = torch.tensor([[0.0806]])assert_allclose(expected_laf, lafs)assert_allclose(expected_resp, resps)