Skip to content

A minor change for transforms.RandomCrop #462

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 5 commits into from
Apr 6, 2018
Merged

Conversation

anguelos
Copy link
Contributor

@anguelos anguelos commented Apr 5, 2018

I just added an optional parameter that pads an image if needed so that small errors don't raise exceptions.
The option is by default turned off so that API behavior is exactly the same.
As far as I saw the test cases don't test for Exceptions so i did not add a test for the feature being off but I tested that locally.

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.

Thanks for the PR!

Lint is complaining about two small details, could you fix that?

Also, I'm curious in which context you faced this problem. Usually, T.Resize(224) resizes the image such that the minimum size is 224, while when we pass a tuple like T.Resize((224, 300)), the image will have that exact size. So normally the user would know exactly what is the minimum length of his image. When did you face this error?

But I'm ok with merging this, because I'm planning about adding a max_size option to T.Resize, so this could be useful.

@@ -1164,4 +1174,4 @@ def test_random_grayscale(self):


if __name__ == '__main__':
unittest.main()
unittest.main()

This comment was marked as off-topic.

img = F.pad(img, (int((1 + self.size[1] - img.size[0]) / 2), 0))
# pad the height if needed
if self.pad_if_needed and img.size[1] < self.size[0]:
img = F.pad(img,(0, int((1 + self.size[0] - img.size[1]) / 2)))

This comment was marked as off-topic.

@anguelos
Copy link
Contributor Author

anguelos commented Apr 5, 2018

The context is texture analysis.
Scaling samples with resize would distort texture properties.
I use a dataset were I want during inference to have variable sized images.
But train on randomly cropped fixed size images so that they are easy to collate.
As the situation was I had to set the cropping size to be smaller than the smallest sample in the dataset.

@anguelos
Copy link
Contributor Author

anguelos commented Apr 6, 2018

I have updated the two linting errors. The Travis failure appears to not be related with my pull request.

@fmassa fmassa merged commit 4e6faa7 into pytorch:master Apr 6, 2018
@fmassa
Copy link
Member

fmassa commented Apr 6, 2018

Yes, the failure looks spurious. Thanks!

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