Example #1
0
    def test_random_hflip(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., 0.],
                              [0., 0., 1., 2.]])  # 3 x 4
        input.to(device)

        expected_transform = torch.tensor([[-1., 0., 4.], [0., 1., 0.],
                                           [0., 0., 1.]])  # 3 x 3

        identity = torch.tensor([[1., 0., 0.], [0., 1., 0.], [0., 0.,
                                                              1.]])  # 3 x 3

        assert (F.compute_hflip_transformation(
            input, params=flip_param_0) == identity).all()
        assert (F.compute_hflip_transformation(
            input, params=flip_param_1) == expected_transform).all()
    def test_random_hflip(self, device):
        input = torch.tensor([[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0],
                              [0.0, 0.0, 1.0, 2.0]])  # 3 x 4
        input.to(device)

        expected_transform = torch.tensor([[-1.0, 0.0, 3.0], [0.0, 1.0, 0.0],
                                           [0.0, 0.0, 1.0]])  # 3 x 3

        assert (F.compute_hflip_transformation(
            input[None, None]) == expected_transform).all()
Example #3
0
    def test_random_hflip(self, device):
        input = torch.tensor([[0., 0., 0., 0.],
                              [0., 0., 0., 0.],
                              [0., 0., 1., 2.]])  # 3 x 4
        input.to(device)

        expected_transform = torch.tensor([[-1., 0., 3.],
                                           [0., 1., 0.],
                                           [0., 0., 1.]])  # 3 x 3

        assert (F.compute_hflip_transformation(input) == expected_transform).all()
Example #4
0
    def test_batch_random_hflip(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_transform = torch.tensor([[[-1., 0., 3.], [0., 1., 0.],
                                            [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_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.compute_hflip_transformation(
            input, params=flip_param_0) == identity).all()
        assert (F.compute_hflip_transformation(
            input, params=flip_param_1) == expected_transform).all()
    def test_batch_random_hflip(self, device):
        batch_size = 5

        input = torch.tensor([[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
                                [0.0, 1.0, 1.0]]]])  # 1 x 1 x 3 x 3
        input.to(device)

        expected_transform = torch.tensor([[[-1.0, 0.0, 2.0], [0.0, 1.0, 0.0],
                                            [0.0, 0.0, 1.0]]])  # 1 x 3 x 3

        input = input.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

        assert (
            F.compute_hflip_transformation(input) == expected_transform).all()