Skip to content

Removed the +1 and divide by 2 to allow for random offset padding #564

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

Merged
merged 1 commit into from
Aug 2, 2018
Merged

Removed the +1 and divide by 2 to allow for random offset padding #564

merged 1 commit into from
Aug 2, 2018

Conversation

ryanpeach
Copy link
Contributor

In reference to Issue #562

I learned that RandomCrop, when you set pad_if_needed to True does not RandomPad. a-la, whereas random crop applies a crop at a random offset to the image, pad_if_needed performs a centered padding, which does not randomly place the image in the padded image. The goal for this method, regardless of whether or not the image is too big or too small, is that the resulting image should be the right size, contain as much of the image as possible, and at random offset.

Imagine the image, whatever size, on an infinite canvas.
Apply a random offset, and a random crop, to that canvas, such that:
if the crop is bigger than the original image, all of the original image remains in the output.
if the crop is smaller than the original image, all of the output is part of the original image.

The fix is just to pad the image by double the previous amount, such that there is enough padding for the random cropping function to apply the offset.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me.
Thanks for the PR!

@fmassa fmassa merged commit fe973ce into pytorch:master Aug 2, 2018
@fmassa fmassa mentioned this pull request Aug 2, 2018
@pmeier pmeier mentioned this pull request Sep 19, 2022
rajveerb pushed a commit to rajveerb/vision that referenced this pull request Nov 30, 2023
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.

2 participants