π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
force solve with torch.float64 (#2785)
Edgar Riba2a56ccd1fde7
diff --git a/kornia/utils/helpers.py b/kornia/utils/helpers.pyindex e3a07122e..a61416562 100644--- a/kornia/utils/helpers.py+++ b/kornia/utils/helpers.py@@ -229,11 +229,11 @@ def _torch_solve_cast(A: Tensor, B: Tensor) -> Tensor:The function torch.solve is only implemented for fp32/64 which makes impossible to be used by fp16 or others. Whatthis function does, is cast input data type to fp32, apply torch.svd, and cast back to the input dtype."""- dtype: torch.dtype = A.dtype- if dtype not in (torch.float32, torch.float64):- dtype = torch.float32+ # dtype: torch.dtype = A.dtype+ # if dtype not in (torch.float32, torch.float64):+ # dtype = torch.float32- out = torch.linalg.solve(A.to(dtype), B.to(dtype))+ out = torch.linalg.solve(A.to(torch.float64), B.to(torch.float64))return out.to(A.dtype)diff --git a/tests/geometry/transform/test_thin_plate_spline.py b/tests/geometry/transform/test_thin_plate_spline.pyindex d8cfe8b66..37f260ae9 100644--- a/tests/geometry/transform/test_thin_plate_spline.py+++ b/tests/geometry/transform/test_thin_plate_spline.py@@ -3,7 +3,6 @@ import torchfrom torch.autograd import gradcheckimport kornia-from kornia.utils._compat import torch_version_gefrom testing.base import assert_close@@ -154,12 +153,9 @@ class TestWarpImage:warp = kornia.geometry.transform.warp_image_tps(tensor, dst, kernel, affine)assert warp.shape == tensor.shape- @pytest.mark.skipif(- torch_version_ge(1, 10), reason="for some reason the solver detects singular matrices in pytorch >=1.10."- )@pytest.mark.parametrize("batch_size", [1, 3])def test_warp(self, batch_size, device, dtype):- src = torch.tensor([[[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, -1.0], [0.0, 0.0]]], device=device).repeat(+ src = torch.tensor([[[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [0.0, 0.0]]], device=device).repeat(batch_size, 1, 1)# zoom in by a factor of 2