-
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
Making Vflip and Hflip in Tensor format #1465
Conversation
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.
Thanks a lot for the PR @surgan12, it looks great !
I have a few comments, let me know what you think.
Also, I think lint will fail, can you check?
test/test_functional_tensor.py
Outdated
vflipped_img = F_t.vflip(img_tensor) | ||
vflipped_img_again = F_t.vflip(vflipped_img) | ||
|
||
assert vflipped_img.shape == img_tensor.shape |
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.
Can we use self.assertEqual
here? I'd prefer to move away from the raw asserts and use self.assert*
methods from unittest for newer test
test/test_functional_tensor.py
Outdated
vflipped_img_again = F_t.vflip(vflipped_img) | ||
|
||
assert vflipped_img.shape == img_tensor.shape | ||
assert torch.equal(img_tensor, vflipped_img_again) |
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.
I think I'd prefer using self.assertTrue
here.
"""Vertically flip the given the Image Tensor. | ||
|
||
Args: | ||
img_tensor (Tensor): Image Tensor to be flipped. |
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.
Can you specify in the documentation what is the expected format of the tensor? Is it HxWxC
or CxHxW
?
if not F._is_tensor_image(img_tensor): | ||
raise TypeError('tensor is not a torch image.') | ||
|
||
return img_tensor.flip(1) |
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.
Can you make the offset relative to the end of the dimension?
This way, we could make it also work for batches of images / videos.
So it would be something like
return img_tensor.flip(-2)
if not F._is_tensor_image(img_tensor): | ||
raise TypeError('tensor is not a torch image.') | ||
|
||
return img_tensor.flip(2) |
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, can you do .flip(-1)
here?
@fmassa , got'em. Making the updates. |
Codecov Report
@@ Coverage Diff @@
## master #1465 +/- ##
==========================================
- Coverage 64.08% 64.07% -0.01%
==========================================
Files 80 81 +1
Lines 6328 6338 +10
Branches 973 975 +2
==========================================
+ Hits 4055 4061 +6
- Misses 1986 1988 +2
- Partials 287 289 +2
Continue to review full report at Codecov.
|
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.
Lint is still failing, and I have a minor nit but otherwise looks good to be merged, thanks!
I need to figure out what's happening with CircleCI though
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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.
linter is failing due to the missing newline here
"""Vertically flip the given the Image Tensor. | ||
|
||
Args: | ||
img_tensor (Tensor): Image Tensor to be flipped in the form CXHXW. |
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.
nit: can you make it CxHxW
or [C, H, W]
? I think it's more readable.
@surgan12 the CircleCI error is very weird, it looks like it's trying to run from your account. Can you try creating a new branch in your fork of torchvision (with the current commits), and then creating a new PR?
and then try again? |
Sure will do that ! |
cc: @fmassa
Ref: #1375