Commit e279eba0 authored by Surgan Jandial's avatar Surgan Jandial Committed by Francisco Massa
Browse files

Vflip and Hflip In tensor format (#1466)

* vflip and hflip tensor

* vflip and hflip tensor

* changes made

* lint

* lint

* lint failing
parent 896d7ec7
import torchvision.transforms.functional_tensor as F_t
import unittest
import torch
class Tester(unittest.TestCase):
def test_vflip(self):
img_tensor = torch.randn(3, 16, 16)
vflipped_img = F_t.vflip(img_tensor)
vflipped_img_again = F_t.vflip(vflipped_img)
self.assertEqual(vflipped_img.shape, img_tensor.shape)
self.assertTrue(torch.equal(img_tensor, vflipped_img_again))
def test_hflip(self):
img_tensor = torch.randn(3, 16, 16)
hflipped_img = F_t.hflip(img_tensor)
hflipped_img_again = F_t.hflip(hflipped_img)
self.assertEqual(hflipped_img.shape, img_tensor.shape)
self.assertTrue(torch.equal(img_tensor, hflipped_img_again))
if __name__ == '__main__':
unittest.main()
import torch
import torchvision.transforms.functional as F
def vflip(img_tensor):
"""Vertically flip the given the Image Tensor.
Args:
img_tensor (Tensor): Image Tensor to be flipped in the form [C, H, W].
Returns:
Tensor: Vertically flipped image Tensor.
"""
if not F._is_tensor_image(img_tensor):
raise TypeError('tensor is not a torch image.')
return img_tensor.flip(-2)
def hflip(img_tensor):
"""Horizontally flip the given the Image Tensor.
Args:
img_tensor (Tensor): Image Tensor to be flipped in the form [C, H, W].
Returns:
Tensor: Horizontally flipped image Tensor.
"""
if not F._is_tensor_image(img_tensor):
raise TypeError('tensor is not a torch image.')
return img_tensor.flip(-1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment