Beispiel #1
0
 def test_color_jitter(self):
     trans = transforms.Compose([
         transforms.BrightnessTransform(0.0),
         transforms.HueTransform(0.0),
         transforms.SaturationTransform(0.0),
         transforms.ContrastTransform(0.0),
     ])
     self.do_transform(trans)
Beispiel #2
0
    def test_exception(self):
        trans = transforms.Compose([transforms.Resize(-1)])

        trans_batch = transforms.BatchCompose([transforms.Resize(-1)])

        with self.assertRaises(Exception):
            self.do_transform(trans)

        with self.assertRaises(Exception):
            self.do_transform(trans_batch)

        with self.assertRaises(ValueError):
            transforms.ContrastTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.SaturationTransform(-1.0),

        with self.assertRaises(ValueError):
            transforms.HueTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.BrightnessTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.Pad([1.0, 2.0, 3.0])

        with self.assertRaises(TypeError):
            fake_img = np.random.rand(100, 120, 3).astype('float32')
            F.pad(fake_img, '1')

        with self.assertRaises(TypeError):
            fake_img = np.random.rand(100, 120, 3).astype('float32')
            F.pad(fake_img, 1, {})

        with self.assertRaises(TypeError):
            fake_img = np.random.rand(100, 120, 3).astype('float32')
            F.pad(fake_img, 1, padding_mode=-1)

        with self.assertRaises(ValueError):
            fake_img = np.random.rand(100, 120, 3).astype('float32')
            F.pad(fake_img, [1.0, 2.0, 3.0])

        with self.assertRaises(ValueError):
            transforms.RandomRotate(-2)

        with self.assertRaises(ValueError):
            transforms.RandomRotate([1, 2, 3])

        with self.assertRaises(ValueError):
            trans_gray = transforms.Grayscale(5)
            fake_img = np.random.rand(100, 120, 3).astype('float32')
            trans_gray(fake_img)
Beispiel #3
0
    def test_exception(self):
        trans = transforms.Compose([transforms.Resize(-1)])

        trans_batch = transforms.Compose([transforms.Resize(-1)])

        with self.assertRaises(Exception):
            self.do_transform(trans)

        with self.assertRaises(Exception):
            self.do_transform(trans_batch)

        with self.assertRaises(ValueError):
            transforms.ContrastTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.SaturationTransform(-1.0),

        with self.assertRaises(ValueError):
            transforms.HueTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.BrightnessTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.Pad([1.0, 2.0, 3.0])

        with self.assertRaises(TypeError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, '1')

        with self.assertRaises(TypeError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, 1, {})

        with self.assertRaises(TypeError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, 1, padding_mode=-1)

        with self.assertRaises(ValueError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, [1.0, 2.0, 3.0])

        with self.assertRaises(TypeError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, '1')

        with self.assertRaises(TypeError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, 1, {})

        with self.assertRaises(TypeError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, 1, padding_mode=-1)

        with self.assertRaises(ValueError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, [1.0, 2.0, 3.0])

        with self.assertRaises(ValueError):
            transforms.RandomAffine(-10)

        with self.assertRaises(ValueError):
            transforms.RandomAffine([-30, 60], translate=[2, 2])

        with self.assertRaises(ValueError):
            transforms.RandomAffine(10, translate=[0.2, 0.2], scale=[1, 2, 3]),

        with self.assertRaises(ValueError):
            transforms.RandomAffine(10,
                                    translate=[0.2, 0.2],
                                    scale=[0.5, 0.5],
                                    shear=[1, 2, 3]),

        with self.assertRaises(ValueError):
            transforms.RandomAffine(10,
                                    translate=[0.5, 0.3],
                                    scale=[0.7, 1.3],
                                    shear=[-10, 10, 0, 20, 40])

        with self.assertRaises(ValueError):
            transforms.RandomAffine(10,
                                    translate=[0.5, 0.3],
                                    scale=[0.7, 1.3],
                                    shear=[-10, 10, 20, 40],
                                    fill=114,
                                    center=(1, 2, 3))

        with self.assertRaises(ValueError):
            transforms.RandomRotation(-2)

        with self.assertRaises(ValueError):
            transforms.RandomRotation([1, 2, 3])

        with self.assertRaises(ValueError):
            trans_gray = transforms.Grayscale(5)
            fake_img = self.create_image((100, 120, 3))
            trans_gray(fake_img)

        with self.assertRaises(TypeError):
            transform = transforms.RandomResizedCrop(64)
            transform(1)

        with self.assertRaises(ValueError):
            transform = transforms.BrightnessTransform([-0.1, -0.2])

        with self.assertRaises(TypeError):
            transform = transforms.BrightnessTransform('0.1')

        with self.assertRaises(ValueError):
            transform = transforms.BrightnessTransform('0.1', keys=1)

        with self.assertRaises(NotImplementedError):
            transform = transforms.BrightnessTransform('0.1', keys='a')

        with self.assertRaises(Exception):
            transform = transforms.RandomErasing(scale=0.5)

        with self.assertRaises(Exception):
            transform = transforms.RandomErasing(ratio=0.8)

        with self.assertRaises(Exception):
            transform = transforms.RandomErasing(scale=(10, 0.4))

        with self.assertRaises(Exception):
            transform = transforms.RandomErasing(ratio=(3.3, 0.3))

        with self.assertRaises(Exception):
            transform = transforms.RandomErasing(prob=1.5)

        with self.assertRaises(Exception):
            transform = transforms.RandomErasing(value="0")
    def test_exception(self):
        trans = transforms.Compose([transforms.Resize(-1)])

        trans_batch = transforms.Compose([transforms.Resize(-1)])

        with self.assertRaises(Exception):
            self.do_transform(trans)

        with self.assertRaises(Exception):
            self.do_transform(trans_batch)

        with self.assertRaises(ValueError):
            transforms.ContrastTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.SaturationTransform(-1.0),

        with self.assertRaises(ValueError):
            transforms.HueTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.BrightnessTransform(-1.0)

        with self.assertRaises(ValueError):
            transforms.Pad([1.0, 2.0, 3.0])

        with self.assertRaises(TypeError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, '1')

        with self.assertRaises(TypeError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, 1, {})

        with self.assertRaises(TypeError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, 1, padding_mode=-1)

        with self.assertRaises(ValueError):
            fake_img = self.create_image((100, 120, 3))
            F.pad(fake_img, [1.0, 2.0, 3.0])

        with self.assertRaises(TypeError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, '1')

        with self.assertRaises(TypeError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, 1, {})

        with self.assertRaises(TypeError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, 1, padding_mode=-1)

        with self.assertRaises(ValueError):
            tensor_img = paddle.rand((3, 100, 100))
            F.pad(tensor_img, [1.0, 2.0, 3.0])

        with self.assertRaises(ValueError):
            transforms.RandomRotation(-2)

        with self.assertRaises(ValueError):
            transforms.RandomRotation([1, 2, 3])

        with self.assertRaises(ValueError):
            trans_gray = transforms.Grayscale(5)
            fake_img = self.create_image((100, 120, 3))
            trans_gray(fake_img)

        with self.assertRaises(TypeError):
            transform = transforms.RandomResizedCrop(64)
            transform(1)

        with self.assertRaises(ValueError):
            transform = transforms.BrightnessTransform([-0.1, -0.2])

        with self.assertRaises(TypeError):
            transform = transforms.BrightnessTransform('0.1')

        with self.assertRaises(ValueError):
            transform = transforms.BrightnessTransform('0.1', keys=1)

        with self.assertRaises(NotImplementedError):
            transform = transforms.BrightnessTransform('0.1', keys='a')