def test_batch_random_vflip(self, device): batch_size = 5 flip_param_0 = {'batch_prob': torch.tensor([False] * 5)} flip_param_1 = {'batch_prob': torch.tensor([True] * 5)} input = torch.tensor([[[[0., 0., 0.], [0., 0., 0.], [0., 1., 1.]]]]) # 1 x 1 x 3 x 3 input.to(device) expected = torch.tensor([[[[0., 1., 1.], [0., 0., 0.], [0., 0., 0.]]]]) # 1 x 1 x 3 x 3 expected_transform = torch.tensor([[[1., 0., 0.], [0., -1., 3.], [0., 0., 1.]]]) # 1 x 3 x 3 identity = torch.tensor([[[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]]) # 1 x 3 x 3 input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3 expected = expected.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3 expected_transform = expected_transform.repeat(batch_size, 1, 1) # 5 x 3 x 3 identity = identity.repeat(batch_size, 1, 1) # 5 x 3 x 3 assert (F.apply_vflip(input, params=flip_param_0, return_transform=True)[0] == input).all() assert (F.apply_vflip(input, params=flip_param_0, return_transform=True)[1] == identity).all() assert (F.apply_vflip(input, params=flip_param_1, return_transform=True)[0] == expected).all() assert (F.apply_vflip(input, params=flip_param_1, return_transform=True)[1] == expected_transform).all()
def test_random_vflip(self, device): flip_param_0 = {'batch_prob': torch.tensor(False)} flip_param_1 = {'batch_prob': torch.tensor(True)} input = torch.tensor([[0., 0., 0.], [0., 0., 0.], [0., 1., 1.]]) # 3 x 3 input.to(device) expected = torch.tensor([[0., 1., 1.], [0., 0., 0.], [0., 0., 0.]]) # 3 x 3 assert (F.apply_vflip(input, params=flip_param_0) == input).all() assert (F.apply_vflip(input, params=flip_param_1) == expected).all()
def test_batch_random_vflip(self, device): batch_size = 5 flip_param_0 = {'batch_prob': torch.tensor([False] * 5)} flip_param_1 = {'batch_prob': torch.tensor([True] * 5)} input = torch.tensor([[[[0., 0., 0.], [0., 0., 0.], [0., 1., 1.]]]]) # 1 x 1 x 3 x 3 input.to(device) expected = torch.tensor([[[[0., 1., 1.], [0., 0., 0.], [0., 0., 0.]]]]) # 1 x 1 x 3 x 3 input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3 expected = expected.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3 assert (F.apply_vflip(input, params=flip_param_0) == input).all() assert (F.apply_vflip(input, params=flip_param_1) == expected).all()
def test_random_vflip(self, device, dtype): input = torch.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]], device=device, dtype=dtype) # 3 x 3 expected = torch.tensor( [[0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], device=device, dtype=dtype ) # 3 x 3 assert (F.apply_vflip(input[None, None]) == expected).all()
def test_random_vflip(self, device, dtype): input = torch.tensor([[0., 0., 0.], [0., 0., 0.], [0., 1., 1.]], device=device, dtype=dtype) # 3 x 3 expected = torch.tensor([[0., 1., 1.], [0., 0., 0.], [0., 0., 0.]], device=device, dtype=dtype) # 3 x 3 assert (F.apply_vflip(input) == expected).all()
def test_random_vflip(self, device): flip_param_0 = {'batch_prob': torch.tensor(False)} flip_param_1 = {'batch_prob': torch.tensor(True)} input = torch.tensor([[0., 0., 0.], [0., 0., 0.], [0., 1., 1.]]) # 3 x 3 input.to(device) expected = torch.tensor([[0., 1., 1.], [0., 0., 0.], [0., 0., 0.]]) # 3 x 3 expected_transform = torch.tensor([[1., 0., 0.], [0., -1., 3.], [0., 0., 1.]]) # 3 x 3 identity = torch.tensor([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) # 3 x 3 assert (F.apply_vflip(input, params=flip_param_0, return_transform=True)[0] == input).all() assert (F.apply_vflip(input, params=flip_param_0, return_transform=True)[1] == identity).all() assert (F.apply_vflip(input, params=flip_param_1, return_transform=True)[0] == expected).all() assert (F.apply_vflip(input, params=flip_param_1, return_transform=True)[1] == expected_transform).all() assert (F.apply_vflip(input, params=flip_param_0, return_transform=False) == input).all() assert (F.apply_vflip(input, params=flip_param_1, return_transform=False) == expected).all()
def test_batch_random_vflip(self, device, dtype): batch_size = 5 input = torch.tensor( [[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]]]], device=device, dtype=dtype ) # 1 x 1 x 3 x 3 expected = torch.tensor( [[[[0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]], device=device, dtype=dtype ) # 1 x 1 x 3 x 3 input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3 expected = expected.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3 assert (F.apply_vflip(input) == expected).all()