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

Make RandomHorizontalFlip torchscriptable #2278

Closed
wants to merge 2 commits into from

Conversation

fmassa
Copy link
Member

@fmassa fmassa commented Jun 1, 2020

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:

  • make functional and transforms seamlessly support Tensor arguments
  • make functional and transforms be torchscriptable

In 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 either functional_tensor.py or functional_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.

@fmassa fmassa requested a review from eellison June 1, 2020 13:08
@@ -500,25 +500,29 @@ def __repr__(self):
return self.__class__.__name__ + '(size={0}, padding={1})'.format(self.size, self.padding)


class RandomHorizontalFlip(object):
"""Horizontally flip the given PIL Image randomly with a given probability.
class RandomHorizontalFlip(torch.nn.Module):
Copy link
Member Author

Choose a reason for hiding this comment

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

@eellison this is the part I would like your thoughts on

@fmassa fmassa mentioned this pull request Jun 1, 2020
@fmassa fmassa closed this Jun 2, 2020
@fmassa fmassa deleted the hflip-script branch June 2, 2020 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant