Skip to content
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

[prototype] Restore BC on perspective #6902

Merged
merged 9 commits into from
Nov 4, 2022

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Nov 3, 2022

This PR is a potential solution for restoring BC on the perspective kernel.

@vfdev-5 noted that on the new kernels we use the perspective_coeffs parameter which was favoured on the _FT and _FP stable kernels instead of the startpoints and endpoints parameters exposed by stable F. This would be BC breaking and thus we have to restore the original parameters.

Unfortunately the estimation of perspective_coeffs is quite computationally expensive and thus it would be great if we can estimate them once per record on the RandomPerspective transform and share it with all the inputs. A middle ground is to introduce a coefficients parameters on all the perspective* kernels and dispatchers which will allow users to pass directly the coefficients if they have them.

This PR:

  • Restores the startpoints and endpoints parameters on the original positional locations of perspective* methods.
  • Introduces an extra keyword argument called coefficients in all the perspective* methods.
  • Changes the types of all above parameters to make it possible to accept None values. Either startpoints/endpoints or coeffiecients must be non-None.
  • Updates the tests to pass startpoints=None, endpoints=None and coeffiecients=perspective_coeffs.

Might be worth on a follow up to add tests for the case where startpoints/endpoints are non-None.

cc @vfdev-5 @bjuncek @pmeier

Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for quick fix, @datumbox !

@@ -1184,38 +1184,38 @@ def reference_inputs_pad_bounding_box():
def sample_inputs_perspective_image_tensor():
for image_loader in make_image_loaders(sizes=["random"]):
for fill in [None, 128.0, 128, [12.0], [12.0 + c for c in range(image_loader.num_channels)]]:
yield ArgsKwargs(image_loader, fill=fill, perspective_coeffs=_PERSPECTIVE_COEFFS[0])
yield ArgsKwargs(image_loader, None, None, fill=fill, coefficients=_PERSPECTIVE_COEFFS[0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: While correct, can we pass keywords here to make this call more readable?

Suggested change
yield ArgsKwargs(image_loader, None, None, fill=fill, coefficients=_PERSPECTIVE_COEFFS[0])
yield ArgsKwargs(image_loader, startpoints=None, endpoints=None, fill=fill, coefficients=_PERSPECTIVE_COEFFS[0])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to make this change on the tests. I wouldn't want to make it on the main code because the arguments are positional not keyword args. Any concerns on that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nono, fine with that. The test definition is just hard to read without knowledge of the exact signature of the kernel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something, somewhere in the testing framework seems to send multiple parameters to the kernel. I don't want to waste too much time on this, I've reverted the named params change and we can do the optimization on a follow up as it doesn't affect the main implementation or the quality of the tests.

@datumbox datumbox changed the title [WIP] [prototype] Restore BC on perspective [prototype] Restore BC on perspective Nov 4, 2022
@datumbox datumbox merged commit dc11b1f into pytorch:main Nov 4, 2022
@datumbox datumbox deleted the prototype/perspective_bc branch November 4, 2022 10:39
facebook-github-bot pushed a commit that referenced this pull request Nov 14, 2022
Summary:
* Restore BC on perspective

* Fixes linter

* Fixing tests.

* Apply code-review changes.

* Pleasing mypy.

* Revert named parameters.

Reviewed By: NicolasHug

Differential Revision: D41265194

fbshipit-source-id: 4e72d73342d179071458d15593b9cee00eaa84e5
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.

4 participants