示例#1
0
    def test_intensity_only(self):
        seq = K.PatchSequential(
            K.ImageSequential(
                K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                K.RandomPerspective(0.2, p=0.5),
                K.RandomSolarize(0.1, 0.1, p=0.5),
            ),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1),
            K.ImageSequential(
                K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                K.RandomPerspective(0.2, p=0.5),
                K.RandomSolarize(0.1, 0.1, p=0.5),
            ),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1),
            grid_size=(2, 2),
        )
        assert not seq.is_intensity_only()

        seq = K.PatchSequential(
            K.ImageSequential(K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5)),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1),
            grid_size=(2, 2),
        )
        assert seq.is_intensity_only()
示例#2
0
    def test_forward(self, shape, padding, patchwise_apply, same_on_batch,
                     keepdim, random_apply, device, dtype):
        torch.manual_seed(11)
        try:  # skip wrong param settings.
            seq = K.PatchSequential(
                K.color.RgbToBgr(),
                K.ColorJitter(0.1, 0.1, 0.1, 0.1),
                K.ImageSequential(
                    K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                    K.RandomPerspective(0.2, p=0.5),
                    K.RandomSolarize(0.1, 0.1, p=0.5),
                ),
                K.RandomMixUp(p=1.0),
                grid_size=(2, 2),
                padding=padding,
                patchwise_apply=patchwise_apply,
                same_on_batch=same_on_batch,
                keepdim=keepdim,
                random_apply=random_apply,
            )
        # TODO: improve me and remove the exception.
        except Exception:
            return

        input = torch.randn(*shape, device=device, dtype=dtype)
        out = seq(input)
        if seq.return_label:
            out, _ = out
        assert out.shape[-3:] == input.shape[-3:]

        reproducibility_test(input, seq)
示例#3
0
    def test_forward(self, shape, padding, patchwise_apply, same_on_batch,
                     keepdim, device, dtype):
        seq = K.PatchSequential(
            K.ImageSequential(
                K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                K.RandomPerspective(0.2, p=0.5),
                K.RandomSolarize(0.1, 0.1, p=0.5),
            ),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1),
            K.ImageSequential(
                K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                K.RandomPerspective(0.2, p=0.5),
                K.RandomSolarize(0.1, 0.1, p=0.5),
            ),
            K.ColorJitter(0.1, 0.1, 0.1, 0.1),
            grid_size=(2, 2),
            padding=padding,
            patchwise_apply=patchwise_apply,
            same_on_batch=same_on_batch,
            keepdim=keepdim,
        )
        input = torch.randn(*shape, device=device, dtype=dtype)
        trans = torch.randn(shape[0], 3, 3, device=device, dtype=dtype)
        out = seq(input)
        assert out.shape[-3:] == input.shape[-3:]

        out = seq((input, trans))
        assert out[0].shape[-3:] == input.shape[-3:]
        assert out[1].shape == trans.shape
示例#4
0
 def test_exception(self, error_param):
     with pytest.raises(Exception):  # AssertError and NotImplementedError
         K.PatchSequential(
             K.ImageSequential(
                 K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                 K.RandomPerspective(0.2, p=0.5),
                 K.RandomSolarize(0.1, 0.1, p=0.5),
             ),
             K.ColorJitter(0.1, 0.1, 0.1, 0.1),
             K.ImageSequential(
                 K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                 K.RandomPerspective(0.2, p=0.5),
                 K.RandomSolarize(0.1, 0.1, p=0.5),
             ),
             K.ColorJitter(0.1, 0.1, 0.1, 0.1),
             **error_param,
         )
示例#5
0
    def test_forward(self, shape, padding, patchwise_apply, same_on_batch,
                     keepdim, random_apply, device, dtype):
        try:  # skip wrong param settings.
            seq = K.PatchSequential(
                K.ImageSequential(
                    K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                    K.RandomPerspective(0.2, p=0.5),
                    K.RandomSolarize(0.1, 0.1, p=0.5),
                ),
                K.ColorJitter(0.1, 0.1, 0.1, 0.1),
                K.ImageSequential(
                    K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=0.5),
                    K.RandomPerspective(0.2, p=0.5),
                    K.RandomSolarize(0.1, 0.1, p=0.5),
                ),
                K.ColorJitter(0.1, 0.1, 0.1, 0.1),
                grid_size=(2, 2),
                padding=padding,
                patchwise_apply=patchwise_apply,
                same_on_batch=same_on_batch,
                keepdim=keepdim,
                random_apply=random_apply,
            )
        except:
            return

        input = torch.randn(*shape, device=device, dtype=dtype)
        trans = torch.randn(shape[0], 3, 3, device=device, dtype=dtype)
        out = seq(input)
        assert out.shape[-3:] == input.shape[-3:]

        out = seq((input, trans))
        assert out[0].shape[-3:] == input.shape[-3:]
        assert out[1].shape == trans.shape

        reproducibility_test(input, seq)