π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Fix: rasanc max_samples_by_conf to not return negative (#2897)
Vaclav Vavraf0ed53efc02f
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 4a4e9b24e..8af0a1e88 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -9,12 +9,12 @@ Everyone is welcome to get involved with the project. There are different ways t1. using the GitHub discussion at Kornia repo: [GH Discussions](https://github.com/kornia/kornia/discussions)2. our slack workspace to keep in touch with our core contributors and the community:[Join Here](https://join.slack.com/t/kornia/shared_invite/zt-csobk21g-2AQRi~X9Uu6PLMuUZdvfjA)- 3. using the `#kornia` tag in [PyTorch Discuss](https://discuss.pytorch.org>)+ 3. using the `#kornia` tag in [PyTorch Discuss](https://discuss.pytorch.org)- Please, don't use GitHub issues for Q&A.- In case you are a developer and want to learn more about the PyTorch ecosystem, we suggest you join the PyTorch- slack. You can apply using this form: [https://bit.ly/ptslack](https://bit.ly/ptslack>)+ slack. You can apply using this form: [https://bit.ly/ptslack](https://bit.ly/ptslack)-2. Report bugs through [GitHub issues](https://github.com/kornia/kornia/issues>):+2. Report bugs through [GitHub issues](https://github.com/kornia/kornia/issues):- Do a quick search first to see whether others reported a similar issue.- In case you find an unreported bug, please open a new ticket.- Try to provide as much information as possible. Report using one of the available templates. Some tips:diff --git a/kornia/geometry/ransac.py b/kornia/geometry/ransac.pyindex 91eb062f6..5d5ac6149 100644--- a/kornia/geometry/ransac.py+++ b/kornia/geometry/ransac.py@@ -103,7 +103,7 @@ class RANSAC(Module):return 1.0if n_inl == num_tc:return 1.0- return math.log(1.0 - conf) / max(eps, math.log(max(eps, 1.0 - math.pow(n_inl / num_tc, sample_size))))+ return math.log(1.0 - conf) / min(-eps, math.log(max(eps, 1.0 - math.pow(n_inl / num_tc, sample_size))))def estimate_model_from_minsample(self, kp1: Tensor, kp2: Tensor) -> Tensor:batch_size, sample_size = kp1.shape[:2]diff --git a/tests/geometry/test_ransac.py b/tests/geometry/test_ransac.pyindex d89dbedc3..7f0f91567 100644--- a/tests/geometry/test_ransac.py+++ b/tests/geometry/test_ransac.py@@ -1,3 +1,5 @@+import math+import pytestimport torch@@ -241,3 +243,17 @@ class TestRANSACFundamental(BaseTester):return model(p1, p2)[0]self.gradcheck(gradfun, (points1, points2), fast_mode=False, requires_grad=(True, False, False))+++class TestRansacMethods:+ def test_max_samples_by_conf(self):+ conf = 0.99+ eps = 1e-9++ x = RANSAC.max_samples_by_conf(n_inl=1, num_tc=1000, sample_size=7, conf=conf)+ assert x > 0.0+ assert x == math.log(1.0 - conf) / -eps++ x = RANSAC.max_samples_by_conf(n_inl=999999999, num_tc=1000000000, sample_size=1, conf=conf)+ assert x > 0.0+ assert x == math.log(1.0 - conf) / math.log(eps)