question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] _compute_shear_matrix and get_affine_matrix2d yield different results

See original GitHub issue

🐛 Bug

_compute_shear_matrix and get_affine_matrix2d yield different results.

To Reproduce

import functools
import torch
from kornia.geometry.transform.affwarp import _compute_shear_matrix
from kornia import get_affine_matrix2d

translations = torch.zeros(1, 2)
center = torch.zeros(1, 2)
scale = torch.ones(1)
angle = torch.zeros(1)
get_affine_matrix2d_shear = functools.partial(
    get_affine_matrix2d, translations, center, scale, angle
)

# just making sure that the defaults for the other parameters are correct
assert torch.norm(get_affine_matrix2d_shear() - torch.eye(3)) < 1e-6


torch.manual_seed(0)
sx, sy = torch.rand(1), torch.rand(1)
shear = torch.stack((sx, sy), dim=1)

print(_compute_shear_matrix(shear))
print(get_affine_matrix2d_shear(sx=sx, sy=sy))
tensor([[[1.0000, 0.4963, 0.0000],
         [0.7682, 1.0000, 0.0000],
         [0.0000, 0.0000, 1.0000]]])
tensor([[[ 1.0000, -0.5415,  0.0000],
         [-0.9662,  1.5232,  0.0000],
         [ 0.0000,  0.0000,  1.0000]]])

Expected behavior

Maybe I’m missing something obvious, but I imagined both functions should yield the same results if fed with the same shear parameters.

Environment

kornia == 0.4.1+86185fb
PyTorch version: 1.6.0
Is debug build: False
CUDA used to build PyTorch: 10.2

OS: Ubuntu 18.04.4 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.10.2

Python version: 3.6 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: 10.2.89
GPU models and configuration: GPU 0: GeForce GTX 1080
Nvidia driver version: 440.33.01
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5

Versions of relevant libraries:
[pip3] light-the-torch==0.2.0
[pip3] numpy==1.19.1
[pip3] torch==1.6.0
[conda] Could not collect

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
shijianjiancommented, Aug 18, 2020

Yes. The order does not matter since they are diagonal matrices but it is not equivalent to the x-and-y shearing. They are different mathematically:

image

Not sure about the source implementations. @ducha-aiki may know where to find it.

0reactions
stale[bot]commented, Dec 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions, and happy coding day 😎

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found