Make RandomHorizontalFlip torchscriptable #2278
Closed
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.
This is the first PR in a series towards making the torchvision transforms torchscriptable.
The majority of the work has already been done in the
functional_tensor.py
file, which for now hasn't been properly exposed to the user.The objective of this PR is twofold:
functional
andtransforms
seamlessly support Tensor argumentsfunctional
andtransforms
be torchscriptableIn order to minimize code changes, I decided for now to move (one at a time) the Pillow transforms to a separate file, and in
functional.py
dispatch to eitherfunctional_tensor.py
orfunctional_pil.py
.Another thing that might be worth discussion: the torchvision transforms now inherit from
nn.Module
. I think this makes things simpler wrt torchscript, and as such might be preferred over keeping them as before. In particular, it will make it possible to save the transforms into a standalone file, and having custom__str__
implementations.cc @eellison for feedback on replacing standard classes with classes inheriting from
nn.Module
for a more seamless support for torchscript.