vision icon indicating copy to clipboard operation
vision copied to clipboard

Make `_get_perspective_coeffs` device agnostic

Open AntoineSimoulin opened this issue 8 months ago • 1 comments

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)

AntoineSimoulin avatar May 23 '25 02:05 AntoineSimoulin

:link: Helpful Links

:test_tube: 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.

pytorch-bot[bot] avatar May 23 '25 02:05 pytorch-bot[bot]