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 setUp(self): self.backend = self.get_backend() set_image_backend(self.backend) self.data_dir = tempfile.mkdtemp() for i in range(2): sub_dir = os.path.join(self.data_dir, 'class_' + str(i)) if not os.path.exists(sub_dir): os.makedirs(sub_dir) for j in range(2): if j == 0: fake_img = (np.random.random( (280, 350, 3)) * 255).astype('uint8') else: fake_img = (np.random.random( (400, 300, 3)) * 255).astype('uint8') cv2.imwrite(os.path.join(sub_dir, str(j) + '.jpg'), fake_img)
def test_image_load(self): fake_img = Image.fromarray((np.random.random( (32, 32, 3)) * 255).astype('uint8')) path = 'temp.jpg' fake_img.save(path) set_image_backend('pil') pil_img = image_load(path).convert('RGB') print(type(pil_img)) set_image_backend('cv2') np_img = image_load(path) os.remove(path)
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)