예제 #1
0
 def test_flip(self):
     trans = transforms.Compose([
         transforms.RandomHorizontalFlip(1.0),
         transforms.RandomHorizontalFlip(0.0),
         transforms.RandomVerticalFlip(0.0),
         transforms.RandomVerticalFlip(1.0),
     ])
     self.do_transform(trans)
예제 #2
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)
예제 #3
0
    def test_trans_all(self):
        normalize = transforms.Normalize(
            mean=[123.675, 116.28, 103.53], std=[58.395, 57.120, 57.375])
        trans = transforms.Compose([
            transforms.RandomResizedCrop(224), transforms.GaussianNoise(),
            transforms.ColorJitter(
                brightness=0.4, contrast=0.4, saturation=0.4,
                hue=0.4), transforms.RandomHorizontalFlip(),
            transforms.Permute(mode='CHW'), normalize
        ])

        self.do_transform(trans)
예제 #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
            ])
예제 #5
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
예제 #6
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)
예제 #7
0
 def test_trans_centerCrop(self):
     trans = transforms.Compose([
         transforms.CenterCropResize(224),
         transforms.CenterCropResize(128, 160),
     ])
     self.do_transform(trans)
예제 #8
0
 def test_info(self):
     str(transforms.Compose([transforms.Resize((224, 224))]))
     str(transforms.BatchCompose([transforms.Resize((224, 224))]))