Commit a38c125a authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): save the pillow repr

parent f789ab3b
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
@@ -684,3 +684,113 @@ class TestPreprocessPillow:
        pnormalize = PillowNormalize(mean=mean, std=std)
        with pytest.raises(ValueError):
            _ = pnormalize(arr.numpy())

    @pytest.mark.parametrize(['mean', 'std', 'repr_text'], [
        ((0.485, 0.456, 0.406), (0.229, 0.224, 0.225),
         'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229 0.224 0.225])'),
        ((0.485, 0.456, 0.406), [0.229, 0.224, 0.225],
         'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229 0.224 0.225])'),
        ((0.485, 0.456, 0.406), (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.5 0.5 0.5])'),
        ((0.485, 0.456, 0.406), (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[1. 1. 1.])'),
        ((0.485, 0.456, 0.406), (0.229,), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229])'),
        ((0.485, 0.456, 0.406), (0.5,), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.5])'),
        ((0.485, 0.456, 0.406), (1.0,), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[1.])'),
        ((0.485, 0.456, 0.406), 0.229, 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229])'),
        ((0.485, 0.456, 0.406), 0.5, 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.5])'),
        ((0.485, 0.456, 0.406), 1.0, 'PillowNormalize(mean=[0.485 0.456 0.406], std=[1.])'),
        ([0.485, 0.456, 0.406], (0.229, 0.224, 0.225),
         'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229 0.224 0.225])'),
        ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225],
         'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229 0.224 0.225])'),
        ([0.485, 0.456, 0.406], (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.5 0.5 0.5])'),
        ([0.485, 0.456, 0.406], (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[1. 1. 1.])'),
        ([0.485, 0.456, 0.406], (0.229,), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229])'),
        ([0.485, 0.456, 0.406], (0.5,), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.5])'),
        ([0.485, 0.456, 0.406], (1.0,), 'PillowNormalize(mean=[0.485 0.456 0.406], std=[1.])'),
        ([0.485, 0.456, 0.406], 0.229, 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.229])'),
        ([0.485, 0.456, 0.406], 0.5, 'PillowNormalize(mean=[0.485 0.456 0.406], std=[0.5])'),
        ([0.485, 0.456, 0.406], 1.0, 'PillowNormalize(mean=[0.485 0.456 0.406], std=[1.])'),
        ((0.5, 0.5, 0.5), (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.229 0.224 0.225])'),
        ((0.5, 0.5, 0.5), [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.229 0.224 0.225])'),
        ((0.5, 0.5, 0.5), (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.5 0.5 0.5])'),
        ((0.5, 0.5, 0.5), (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.5 0.5 0.5], std=[1. 1. 1.])'),
        ((0.5, 0.5, 0.5), (0.229,), 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.229])'),
        ((0.5, 0.5, 0.5), (0.5,), 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.5])'),
        ((0.5, 0.5, 0.5), (1.0,), 'PillowNormalize(mean=[0.5 0.5 0.5], std=[1.])'),
        ((0.5, 0.5, 0.5), 0.229, 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.229])'),
        ((0.5, 0.5, 0.5), 0.5, 'PillowNormalize(mean=[0.5 0.5 0.5], std=[0.5])'),
        ((0.5, 0.5, 0.5), 1.0, 'PillowNormalize(mean=[0.5 0.5 0.5], std=[1.])'),
        ((0.0, 0.0, 0.0), (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0. 0. 0.], std=[0.229 0.224 0.225])'),
        ((0.0, 0.0, 0.0), [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0. 0. 0.], std=[0.229 0.224 0.225])'),
        ((0.0, 0.0, 0.0), (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0. 0. 0.], std=[0.5 0.5 0.5])'),
        ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0. 0. 0.], std=[1. 1. 1.])'),
        ((0.0, 0.0, 0.0), (0.229,), 'PillowNormalize(mean=[0. 0. 0.], std=[0.229])'),
        ((0.0, 0.0, 0.0), (0.5,), 'PillowNormalize(mean=[0. 0. 0.], std=[0.5])'),
        ((0.0, 0.0, 0.0), (1.0,), 'PillowNormalize(mean=[0. 0. 0.], std=[1.])'),
        ((0.0, 0.0, 0.0), 0.229, 'PillowNormalize(mean=[0. 0. 0.], std=[0.229])'),
        ((0.0, 0.0, 0.0), 0.5, 'PillowNormalize(mean=[0. 0. 0.], std=[0.5])'),
        ((0.0, 0.0, 0.0), 1.0, 'PillowNormalize(mean=[0. 0. 0.], std=[1.])'),
        ((0.485,), (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.485], std=[0.229 0.224 0.225])'),
        ((0.485,), [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.485], std=[0.229 0.224 0.225])'),
        ((0.485,), (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.485], std=[0.5 0.5 0.5])'),
        ((0.485,), (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.485], std=[1. 1. 1.])'),
        ((0.485,), (0.229,), 'PillowNormalize(mean=[0.485], std=[0.229])'),
        ((0.485,), (0.5,), 'PillowNormalize(mean=[0.485], std=[0.5])'),
        ((0.485,), (1.0,), 'PillowNormalize(mean=[0.485], std=[1.])'),
        ((0.485,), 0.229, 'PillowNormalize(mean=[0.485], std=[0.229])'),
        ((0.485,), 0.5, 'PillowNormalize(mean=[0.485], std=[0.5])'),
        ((0.485,), 1.0, 'PillowNormalize(mean=[0.485], std=[1.])'),
        ((0.5,), (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.5], std=[0.229 0.224 0.225])'),
        ((0.5,), [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.5], std=[0.229 0.224 0.225])'),
        ((0.5,), (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.5], std=[0.5 0.5 0.5])'),
        ((0.5,), (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.5], std=[1. 1. 1.])'),
        ((0.5,), (0.229,), 'PillowNormalize(mean=[0.5], std=[0.229])'),
        ((0.5,), (0.5,), 'PillowNormalize(mean=[0.5], std=[0.5])'),
        ((0.5,), (1.0,), 'PillowNormalize(mean=[0.5], std=[1.])'),
        ((0.5,), 0.229, 'PillowNormalize(mean=[0.5], std=[0.229])'),
        ((0.5,), 0.5, 'PillowNormalize(mean=[0.5], std=[0.5])'),
        ((0.5,), 1.0, 'PillowNormalize(mean=[0.5], std=[1.])'),
        ((0.0,), (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.], std=[0.229 0.224 0.225])'),
        ((0.0,), [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.], std=[0.229 0.224 0.225])'),
        ((0.0,), (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.], std=[0.5 0.5 0.5])'),
        ((0.0,), (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.], std=[1. 1. 1.])'),
        ((0.0,), (0.229,), 'PillowNormalize(mean=[0.], std=[0.229])'),
        ((0.0,), (0.5,), 'PillowNormalize(mean=[0.], std=[0.5])'),
        ((0.0,), (1.0,), 'PillowNormalize(mean=[0.], std=[1.])'),
        ((0.0,), 0.229, 'PillowNormalize(mean=[0.], std=[0.229])'),
        ((0.0,), 0.5, 'PillowNormalize(mean=[0.], std=[0.5])'),
        ((0.0,), 1.0, 'PillowNormalize(mean=[0.], std=[1.])'),
        (0.485, (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.485], std=[0.229 0.224 0.225])'),
        (0.485, [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.485], std=[0.229 0.224 0.225])'),
        (0.485, (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.485], std=[0.5 0.5 0.5])'),
        (0.485, (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.485], std=[1. 1. 1.])'),
        (0.485, (0.229,), 'PillowNormalize(mean=[0.485], std=[0.229])'),
        (0.485, (0.5,), 'PillowNormalize(mean=[0.485], std=[0.5])'),
        (0.485, (1.0,), 'PillowNormalize(mean=[0.485], std=[1.])'),
        (0.485, 0.229, 'PillowNormalize(mean=[0.485], std=[0.229])'),
        (0.485, 0.5, 'PillowNormalize(mean=[0.485], std=[0.5])'),
        (0.485, 1.0, 'PillowNormalize(mean=[0.485], std=[1.])'),
        (0.5, (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.5], std=[0.229 0.224 0.225])'),
        (0.5, [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.5], std=[0.229 0.224 0.225])'),
        (0.5, (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.5], std=[0.5 0.5 0.5])'),
        (0.5, (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.5], std=[1. 1. 1.])'),
        (0.5, (0.229,), 'PillowNormalize(mean=[0.5], std=[0.229])'),
        (0.5, (0.5,), 'PillowNormalize(mean=[0.5], std=[0.5])'),
        (0.5, (1.0,), 'PillowNormalize(mean=[0.5], std=[1.])'),
        (0.5, 0.229, 'PillowNormalize(mean=[0.5], std=[0.229])'),
        (0.5, 0.5, 'PillowNormalize(mean=[0.5], std=[0.5])'),
        (0.5, 1.0, 'PillowNormalize(mean=[0.5], std=[1.])'),
        (0.0, (0.229, 0.224, 0.225), 'PillowNormalize(mean=[0.], std=[0.229 0.224 0.225])'),
        (0.0, [0.229, 0.224, 0.225], 'PillowNormalize(mean=[0.], std=[0.229 0.224 0.225])'),
        (0.0, (0.5, 0.5, 0.5), 'PillowNormalize(mean=[0.], std=[0.5 0.5 0.5])'),
        (0.0, (1.0, 1.0, 1.0), 'PillowNormalize(mean=[0.], std=[1. 1. 1.])'),
        (0.0, (0.229,), 'PillowNormalize(mean=[0.], std=[0.229])'),
        (0.0, (0.5,), 'PillowNormalize(mean=[0.], std=[0.5])'),
        (0.0, (1.0,), 'PillowNormalize(mean=[0.], std=[1.])'),
        (0.0, 0.229, 'PillowNormalize(mean=[0.], std=[0.229])'),
        (0.0, 0.5, 'PillowNormalize(mean=[0.], std=[0.5])'),
        (0.0, 1.0, 'PillowNormalize(mean=[0.], std=[1.])'),
    ])
    def test_normalize_repr(self, mean, std, repr_text):
        pnormalize = PillowNormalize(mean, std)
        assert repr(pnormalize) == repr_text