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

Refactor transformations by extracting probabilities to get_params() method #3098

Closed
wants to merge 3 commits into from
Closed

Refactor transformations by extracting probabilities to get_params() method #3098

wants to merge 3 commits into from

Conversation

kondela
Copy link
Contributor

@kondela kondela commented Dec 2, 2020

Fixes: #3066

Transformations that need to be refactored since they call torch.rand(1) in forward():

  • RandomApply
  • RandomHorizontalFlip
  • RandomVerticalFlip
  • RandomGrayscale
  • RandomErasing
  • RandomPerspective

Not sure how to handle the last two as they already have get_params() method define and the probability needs to be drawn before get_params() is called, for example RandomPerspective():

if torch.rand(1) < self.p:
width, height = F._get_image_size(img)
startpoints, endpoints = self.get_params(width, height, self.distortion_scale)
return F.perspective(img, startpoints, endpoints, self.interpolation, fill)

@fmassa
Copy link
Member

fmassa commented Dec 4, 2020

Hi,

Thanks for the PR!

I've just made a comment in #3065 (comment) which explains my reasoning behind get_params. Let me know what you think

@kondela
Copy link
Contributor Author

kondela commented Dec 5, 2020

Hi,

Thanks for the PR!

I've just made a comment in #3065 (comment) which explains my reasoning behind get_params. Let me know what you think

Hi, it seems that the discussion in that thread is still ongoing. Do we want to merge it as it is, i.e leave RandomErasing(), RandomPerspective() unchanged or how do we proceed with these two as we can't simply extract torch.rand(1).item() to get_params()?

Thanks!

@datumbox
Copy link
Contributor

datumbox commented Dec 5, 2020

@kondela I wonder if you don't mind to finish the 2 remaining methods so that this PR is complete. I have also a bunch of operators that are pending to be merged and use the specific idiom, so if we decide to return a boolean instead of a weight, I can fix yours and mine in the same PR. I don't really have a preference, let me know. :)

@kondela
Copy link
Contributor Author

kondela commented Dec 6, 2020

@kondela I wonder if you don't mind to finish the 2 remaining methods so that this PR is complete. I have also a bunch of operators that are pending to be merged and use the specific idiom, so if we decide to return a boolean instead of a weight, I can fix yours and mine in the same PR. I don't really have a preference, let me know. :)

Hey @datumbox I refactored the last two transformations, please see if its okay. I was hoping for a hint since as I said in #3098 (comment) that these two transformations are different.

@datumbox
Copy link
Contributor

datumbox commented Dec 6, 2020

I was hoping for a hint since as I said in #3098 (comment) that these two transformations are different.

Hmm, I just saw that you edited your original message. You are right, let us get back to you on this one.

@kondela
Copy link
Contributor Author

kondela commented Dec 6, 2020

I was hoping for a hint since as I said in #3098 (comment) that these two transformations are different.

Hmm, I just saw that you edited your original message. You are right, let us get back to you on this one.

Ok, let me know :). I will wait with fixing the failing tests.

@datumbox
Copy link
Contributor

@kondela FYI we have not forgotten about this. It's just unclear right now which path we are going to take.

Note that we recently merged PR #3123 which adds more transforms. Originally I took the approach of your PR for structuring the random params but I rolled it back (see #3123 (comment)) until we are certain on how to handle this.

@datumbox
Copy link
Contributor

Unfortunately, it seems we need to rethink the plan to cover better cases such as Object Detection. See #3286 for more details on the discussion.

@kondela Thank you for sending the PR, I'll close it for now but I'm happy to ping you once we have a more concrete proposal on how to move forwards.

@datumbox datumbox closed this Mar 20, 2021
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.

Avoid calling torch.rand in Transformation.forward()
4 participants