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.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)
def test_rotate(self): trans = transforms.Compose([ transforms.RandomRotation(90), transforms.RandomRotation([-10, 10]), transforms.RandomRotation(45, expand=True), transforms.RandomRotation(10, expand=True, center=(60, 80)), ]) self.do_transform(trans)
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.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=[-2, -1]), 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.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)
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')