def test_errors(self): with self.assertRaises(TypeError): F.to_tensor(1) with self.assertRaises(ValueError): fake_img = Image.fromarray((np.random.rand(28, 28, 3) * 255).astype( 'uint8')) F.to_tensor(fake_img, data_format=1) with self.assertRaises(ValueError): fake_img = paddle.rand((3, 100, 100)) F.pad(fake_img, 1, padding_mode='symmetric') with self.assertRaises(TypeError): fake_img = paddle.rand((3, 100, 100)) F.resize(fake_img, {1: 1}) with self.assertRaises(TypeError): fake_img = Image.fromarray((np.random.rand(28, 28, 3) * 255).astype( 'uint8')) F.resize(fake_img, '1') with self.assertRaises(TypeError): F.resize(1, 1) with self.assertRaises(TypeError): F.pad(1, 1) with self.assertRaises(TypeError): F.crop(1, 1, 1, 1, 1) with self.assertRaises(TypeError): F.hflip(1) with self.assertRaises(TypeError): F.vflip(1) with self.assertRaises(TypeError): F.adjust_brightness(1, 0.1) with self.assertRaises(TypeError): F.adjust_contrast(1, 0.1) with self.assertRaises(TypeError): F.adjust_hue(1, 0.1) with self.assertRaises(TypeError): F.adjust_saturation(1, 0.1) with self.assertRaises(TypeError): F.rotate(1, 0.1) with self.assertRaises(TypeError): F.to_grayscale(1) with self.assertRaises(ValueError): set_image_backend(1) with self.assertRaises(ValueError): image_load('tmp.jpg', backend=1)
def _apply_image(self, img): if self.param is None: self.param = self._get_param(img) i, j, h, w = self.param cropped_img = F.crop(img, i, j, h, w) return F.resize(cropped_img, self.size, self.interpolation)
def _apply_mask(self, mask): _, height, width = F.to_tensor(mask).shape ret = F.pad(mask, self.padding) return F.crop(ret, top=abs(self.y_offset) if self.y_offset >= 0 else 0, left=0 if self.x_offset >= 0 else abs(self.x_offset), height=height, width=width)
def _apply_image(self, image): _, height, width = F.to_tensor(image).shape ret = F.pad(image, self.padding) return F.crop(ret, top=abs(self.y_offset) if self.y_offset >= 0 else 0, left=0 if self.x_offset >= 0 else abs(self.x_offset), height=height, width=width)
def _apply_image(self, img): i, j, h, w = self.params['crop_prams'] return F.crop(img, i, j, h, w)
def test_errors(self): with self.assertRaises(TypeError): F.to_tensor(1) with self.assertRaises(ValueError): fake_img = Image.fromarray( (np.random.rand(28, 28, 3) * 255).astype('uint8')) F.to_tensor(fake_img, data_format=1) with self.assertRaises(ValueError): fake_img = paddle.rand((3, 100, 100)) F.pad(fake_img, 1, padding_mode='symmetric') with self.assertRaises(TypeError): fake_img = paddle.rand((3, 100, 100)) F.resize(fake_img, {1: 1}) with self.assertRaises(TypeError): fake_img = Image.fromarray( (np.random.rand(28, 28, 3) * 255).astype('uint8')) F.resize(fake_img, '1') with self.assertRaises(TypeError): F.resize(1, 1) with self.assertRaises(TypeError): F.pad(1, 1) with self.assertRaises(TypeError): F.crop(1, 1, 1, 1, 1) with self.assertRaises(TypeError): F.hflip(1) with self.assertRaises(TypeError): F.vflip(1) with self.assertRaises(TypeError): F.adjust_brightness(1, 0.1) with self.assertRaises(TypeError): F.adjust_contrast(1, 0.1) with self.assertRaises(TypeError): F.adjust_hue(1, 0.1) with self.assertRaises(TypeError): F.adjust_saturation(1, 0.1) with self.assertRaises(TypeError): F.affine('45') with self.assertRaises(TypeError): F.affine(45, translate=0.3) with self.assertRaises(TypeError): F.affine(45, translate=[0.2, 0.2, 0.3]) with self.assertRaises(TypeError): F.affine(45, translate=[0.2, 0.2], scale=-0.5) with self.assertRaises(TypeError): F.affine(45, translate=[0.2, 0.2], scale=0.5, shear=10) with self.assertRaises(TypeError): F.affine(45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 0, 10]) with self.assertRaises(TypeError): F.affine(45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 10], interpolation=2) with self.assertRaises(TypeError): F.affine(45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 10], center=0) with self.assertRaises(TypeError): F.rotate(1, 0.1) with self.assertRaises(TypeError): F.to_grayscale(1) with self.assertRaises(ValueError): set_image_backend(1) with self.assertRaises(ValueError): image_load('tmp.jpg', backend=1)
def __call__(self, img): return F.crop(img, self.x1, self.y1, self.x2 - self.x1, self.y2 - self.y1)