Exemple #1
0
 def test_trans_resize(self):
     trans = transforms.Compose([
         transforms.Resize(300, [0, 1]),
         transforms.RandomResizedCrop((280, 280)),
         transforms.Resize(280, [0, 1]),
         transforms.Resize((256, 200)),
         transforms.Resize((180, 160)),
         transforms.CenterCrop(128),
         transforms.CenterCrop((128, 128)),
     ])
     self.do_transform(trans)
Exemple #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)
Exemple #3
0
def load_image(image_path, max_size=400, shape=None):
    image = cv2.imread(image_path)
    image = image.astype('float32') / 255.0
    size = shape if shape is not None else max_size if max(
        image.shape[:2]) > max_size else max(image.shape[:2])

    transform = transforms.Compose([
        transforms.Resize(size),
        transforms.Permute(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])
    image = transform(image)[np.newaxis, :3, :, :]
    image = fluid.dygraph.to_variable(image)
    return image
Exemple #4
0
    def __init__(self,
                 path,
                 mode='train',
                 image_size=224,
                 resize_short_size=256):
        super(ImageNetDataset, self).__init__(path)
        self.mode = mode

        normalize = transforms.Normalize(
            mean=[123.675, 116.28, 103.53], std=[58.395, 57.120, 57.375])
        if self.mode == 'train':
            self.transform = transforms.Compose([
                transforms.RandomResizedCrop(image_size),
                transforms.RandomHorizontalFlip(),
                transforms.Permute(mode='CHW'), normalize
            ])
        else:
            self.transform = transforms.Compose([
                transforms.Resize(resize_short_size),
                transforms.CenterCrop(image_size),
                transforms.Permute(mode='CHW'), normalize
            ])
Exemple #5
0
 def test_info(self):
     str(transforms.Compose([transforms.Resize((224, 224))]))
     str(transforms.BatchCompose([transforms.Resize((224, 224))]))