warp_perspective produced wrong results with integer input
See original GitHub issueDescribe the bug
got a runtime error when I test warp_perspective
Reproduction steps
run
def test_warp_perspective() :
import kornia as K
import torch
input = torch.zeros(1,3,1000,1000).cuda()
print(input.shape)
h, w = 64, 128 # destination size
points_src = torch.tensor([[
[100, 100], [200, 100], [200, 200], [100, 200],
]])
# points_src = torch.tensor([[
# [125., 150.], [562., 40.], [562., 282.], [54., 328.],
# ]])
points_dst = torch.tensor([[
[0., 0.], [w - 1., 0.], [w - 1., h - 1.], [0., h - 1.],
]])
print(points_src, points_dst)
# compute perspective transform
M: torch.tensor = K.get_perspective_transform(points_src, points_dst)
print(input.shape, M)
# warp the original image by the found transform
img_warp: torch.tensor = K.warp_perspective(input, M.cuda(), dsize=(h, w))
print(img_warp.shape)
if __name__ == "__main__":
test_warp_perspective()
File “test2.py”, line 33, in <module> test_warp_perspective() File “test2.py”, line 29, in test_warp_perspective img_warp: torch.tensor = K.warp_perspective(input, M.cuda(), dsize=(h, w)) File “/usr/local/lib/python3.6/dist-packages/kornia/geometry/transform/imgwarp.py”, line 96, in warp_perspective dst_norm_trans_src_norm: torch.Tensor = normalize_homography(M, (H, W), (h_out, w_out)) # Bx3x3 File “/usr/local/lib/python3.6/dist-packages/kornia/geometry/transform/homography_warper.py”, line 378, in normalize_homography src_pix_trans_src_norm = _torch_inverse_cast(src_norm_trans_src_pix) File “/usr/local/lib/python3.6/dist-packages/kornia/utils/helpers.py”, line 50, in _torch_inverse_cast return torch.inverse(input.to(dtype)).to(input.dtype) RuntimeError: inverse_cuda: For batch 0: U(1,1) is zero, singular U.
Expected behavior
no RuntimeError
Environment
>>> torch.__version__
'1.9.1+cu102'
>>> kornia.__version__
'0.5.11'
### Additional context
_No response_
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (9 by maintainers)
Top GitHub Comments
#1413
get_perspective_transform got wrong result when points_src is type of int
when points_src is type of float: the result seems normal
6.3000e-01 vs 0