introduce _check method for type checks on prototype transforms#6503
Merged
pmeier merged 10 commits intopytorch:mainfrom Oct 13, 2022
Merged
introduce _check method for type checks on prototype transforms#6503pmeier merged 10 commits intopytorch:mainfrom
pmeier merged 10 commits intopytorch:mainfrom
Conversation
pmeier
commented
Oct 13, 2022
datumbox
reviewed
Oct 13, 2022
| def forward(self, *inputs: Any) -> Any: | ||
| sample = inputs if len(inputs) > 1 else inputs[0] | ||
|
|
||
| self._check(sample) |
Contributor
There was a problem hiding this comment.
Why aren't we flattening before this call? Also in this approach we can avoid the multiple flattening calls within has_any, has_all and the rest of the utility methods. Do you plan to do this on a follow up?
Contributor
Author
There was a problem hiding this comment.
Yes. My plan was to introduce _check here and go for #6760 in a follow-up PR.
Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
…nto transforms-check
vfdev-5
reviewed
Oct 13, 2022
facebook-github-bot
pushed a commit
that referenced
this pull request
Oct 17, 2022
…rms (#6503) Summary: * introduce _check method for type checks on prototype transforms * cleanup * Update torchvision/prototype/transforms/_geometry.py * introduce _check on new transforms * _check -> _check_inputs * always check inputs in _RandomApplyTransform Reviewed By: NicolasHug Differential Revision: D40427467 fbshipit-source-id: eec7c1ac207955df9310212443769f8f7b146c6a Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com> Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Most of our prototype transforms that override
forwarddo this only to perform some input checks before passing them on to_get_paramsand_transform. This PR adds a_checkmethod that makes this regular behavior, whereas overridingforwardmeans some "special" behavior the API can't handle.with
_checkin place, there are only three* transforms that still need to overrideforward:vision/torchvision/prototype/transforms/_augment.py
Line 188 in 7cc2c95
vision/torchvision/prototype/transforms/_auto_augment.py
Line 139 in 7cc2c95
vision/torchvision/prototype/transforms/_container.py
Line 10 in 7cc2c95
These are objectively outlier and thus it is justified for them to override
forward.Using
_checkwill also get rid of the boilerplateidiom.