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

Making Vflip and Hflip in Tensor format #1465

Closed
wants to merge 4 commits into from

Conversation

surgan12
Copy link
Contributor

@surgan12 surgan12 commented Oct 15, 2019

cc: @fmassa
Ref: #1375

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 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?

vflipped_img = F_t.vflip(img_tensor)
vflipped_img_again = F_t.vflip(vflipped_img)

assert vflipped_img.shape == img_tensor.shape
Copy link
Member

@fmassa fmassa Oct 15, 2019

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

vflipped_img_again = F_t.vflip(vflipped_img)

assert vflipped_img.shape == img_tensor.shape
assert torch.equal(img_tensor, vflipped_img_again)
Copy link
Member

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

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

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)
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, can you do .flip(-1) here?

@surgan12
Copy link
Contributor Author

@fmassa , got'em. Making the updates.

@codecov-io
Copy link

Codecov Report

Merging #1465 into master will decrease coverage by <.01%.
The diff coverage is 60%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
torchvision/transforms/functional_tensor.py 60% <60%> (ø)

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 f16b672...444a69f. Read the comment docs.

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.

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

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

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.

@fmassa
Copy link
Member

fmassa commented Oct 15, 2019

@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?

git checkout -b tensor-flip
# assuming that me points to your remote
git push me tensor-flip

and then try again?

@surgan12
Copy link
Contributor Author

Sure will do that !

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