Skip to content

Make _get_perspective_coeffs device agnostic #9082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AntoineSimoulin
Copy link
Member

Context

This PR is an attempt to solve the issue mentioned in #9076 and explicitly accept tensor on any device as input for the function _get_perspective_coeffs.

proposed solution

This PR proposes to cast startpoints and endpoints as Tensor if a List[List[int]] is passed as input. We then modify how the a_matrix is build to avoid the for loop and make sure the construction of the matrix is compatible with torchscript. The b_matrix is then directly constructed from startpoints (reshaping and modifying the precision).

Testing

We add one test (test_perspective_tensor_input) to make sure the function is compatible with tensor inputs.

pytest test/test_functional_tensor.py -vvv -k test_perspective
...
337 passed, 336 skipped, 21843 deselected in 5.75s (on CPU machine)

Copy link

pytorch-bot bot commented May 23, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9082

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants