-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Add Tensor support for some transforms #1104
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1104 +/- ##
==========================================
+ Coverage 63.92% 64.89% +0.96%
==========================================
Files 68 68
Lines 5406 5438 +32
Branches 829 843 +14
==========================================
+ Hits 3456 3529 +73
+ Misses 1707 1650 -57
- Partials 243 259 +16
Continue to review full report at Codecov.
|
@@ -234,26 +243,42 @@ def resize(img, size, interpolation=Image.BILINEAR): | |||
Returns: | |||
PIL Image: Resized image. | |||
""" | |||
if not _is_pil_image(img): | |||
if not (_is_pil_image(img) or isinstance(img, torch.Tensor)): |
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.
the comment above needs to be updated that it takes torch.Tensor (and has to specify what range the Tensor's values have to be)
@@ -362,16 +387,19 @@ def crop(img, i, j, h, w): | |||
Returns: | |||
PIL Image: Cropped image. | |||
""" | |||
if not _is_pil_image(img): | |||
if not (_is_pil_image(img) or isinstance(img, torch.Tensor)): |
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.
same comment as above
Image.NEAREST: "nearest", | ||
Image.BILINEAR: "bilinear" | ||
} | ||
should_unsqueeze = False |
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.
this is actually should_squeeze
as you squeeze below in 278
@@ -410,10 +438,13 @@ def hflip(img): | |||
Returns: | |||
PIL Image: Horizontall flipped image. | |||
""" | |||
if not _is_pil_image(img): | |||
if not (_is_pil_image(img) or isinstance(img, torch.Tensor)): |
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.
same documentation comment as above
raise TypeError('img should be PIL Image. Got {}'.format(type(img))) | ||
|
||
return img.transpose(Image.FLIP_LEFT_RIGHT) | ||
if _is_pil_image(img): |
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.
it's much cleaner to write explicit if
/else
, rather than have if
shortcut to a return
@@ -468,10 +499,13 @@ def vflip(img): | |||
Returns: | |||
PIL Image: Vertically flipped image. | |||
""" | |||
if not _is_pil_image(img): | |||
if not (_is_pil_image(img) or isinstance(img, torch.Tensor)): |
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.
doc comment as above
This is a POC implementation for adding support for tensors in some of the transforms.
It will be specially useful for video, and also as a first step towards enabling (some of) the transforms to be traceable.