-
Notifications
You must be signed in to change notification settings - Fork 7.2k
fix bug when using PIL backend in references/classification #7665
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,11 +69,10 @@ def __init__( | |
| backend="pil", | ||
| ): | ||
| trans = [] | ||
|
|
||
| backend = backend.lower() | ||
| if backend == "tensor": | ||
| trans.append(transforms.PILToTensor()) | ||
| else: | ||
| elif backend != "pil": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably still be buggy when As it will not apply
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we apply PILtoTensor when backend="pil"? I was just guided by the way it is done in the ClassificationPresetTrain class
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably do this in Line 83. I missed this. But it's confusing why would one apply
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I see, we apply PILtoTensor at the beginning, when backend=="tensor", to do transformations over tensors, not over PIL images. trans += [
transforms.Resize(resize_size, interpolation=interpolation, antialias=True),
transforms.CenterCrop(crop_size),
]As written in the documentation for transforms.Resize:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah it's not super clean nor obvious just reading the code. The key piece of information is that those presets make the hard assumption that whatever you pass as input is a PIL image, no matter the backend! So when we pass A more complete solution would be to do all those checks "at runtime" in |
||
| raise ValueError(f"backend can be 'tensor' or 'pil', but got {backend}") | ||
|
|
||
| trans += [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this should change to