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

Add Tensor support for some transforms #1104

Closed
wants to merge 8 commits into from

Conversation

fmassa
Copy link
Member

@fmassa fmassa commented Jul 10, 2019

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.

@codecov-io
Copy link

codecov-io commented Jul 11, 2019

Codecov Report

Merging #1104 into master will increase coverage by 0.96%.
The diff coverage is 81.25%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
torchvision/transforms/functional.py 71.66% <81.25%> (+0.27%) ⬆️
torchvision/models/detection/roi_heads.py 55.93% <0.00%> (-0.97%) ⬇️
torchvision/transforms/transforms.py 80.94% <0.00%> (-0.84%) ⬇️
torchvision/ops/boxes.py 94.73% <0.00%> (ø)
torchvision/models/vgg.py 89.55% <0.00%> (ø)
torchvision/models/resnet.py 88.27% <0.00%> (ø)
torchvision/models/mnasnet.py 82.71% <0.00%> (ø)
torchvision/models/densenet.py 86.79% <0.00%> (ø)
torchvision/models/detection/transform.py 78.30% <0.00%> (+0.20%) ⬆️
torchvision/datasets/svhn.py 67.30% <0.00%> (+32.69%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5508815...ed3424f. Read the comment docs.

@fmassa fmassa changed the title [WIP] Add Tensor support for some transforms Add Tensor support for some transforms Jul 12, 2019
@fmassa fmassa requested a review from soumith July 26, 2019 14:29
@@ -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)):
Copy link
Member

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)):
Copy link
Member

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
Copy link
Member

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)):
Copy link
Member

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):
Copy link
Member

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)):
Copy link
Member

Choose a reason for hiding this comment

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

doc comment as above

@fmassa
Copy link
Member Author

fmassa commented Jul 8, 2020

Subsumed by PRs linked to #1375 and #2292

@fmassa fmassa closed this Jul 8, 2020
@fmassa fmassa deleted the tensor-transforms branch July 8, 2020 12:35
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.

3 participants