Example #1
0
 def transform_tr(self, sample):
     if self.table == {}:
         composed_transforms = transforms.Compose([
             tr.RandomHorizontalFlip(),
             tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
             #tr.Remap(self.building_table, self.nonbuilding_table, self.channels)
             tr.RandomGaussianBlur(),
             #tr.ConvertFromInts(),
             #tr.PhotometricDistort(),
             tr.Normalize(mean=self.source_dist['mean'],
                          std=self.source_dist['std']),
             tr.ToTensor(),
         ])
     else:
         composed_transforms = transforms.Compose([
             tr.RandomHorizontalFlip(),
             tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
             tr.Remap(self.table, self.channels),
             tr.RandomGaussianBlur(),
             #tr.ConvertFromInts(),
             #tr.PhotometricDistort(),
             tr.Normalize(mean=self.source_dist['mean'],
                          std=self.source_dist['std']),
             tr.ToTensor(),
         ])
     return composed_transforms(sample)
Example #2
0
def get_transformations(p):
    """ Return transformations for training and evaluationg """
    from data import custom_transforms as tr

    db_name = p['train_db_name']

    __imagenet_pca = {
        'eigval':
        torch.Tensor([0.2175, 0.0188, 0.0045]),
        'eigvec':
        torch.Tensor([
            [-0.5675, 0.7192, 0.4009],
            [-0.5808, -0.0045, -0.8140],
            [-0.5836, -0.6948, 0.4203],
        ])
    }

    # Training transformations

    # Horizontal flips with probability of 0.5
    transforms_tr = [tr.RandomHorizontalFlip()]

    # Fixed Resize to input resolution
    transforms_tr.extend([
        tr.FixedResize(resolutions={
            x: tuple(p.TRAIN.SCALE)
            for x in p.ALL_TASKS.FLAGVALS
        },
                       flagvals={
                           x: p.ALL_TASKS.FLAGVALS[x]
                           for x in p.ALL_TASKS.FLAGVALS
                       })
    ])

    transforms_tr.extend([tr.AddIgnoreRegions(), tr.ToTensor()])

    transforms_tr.extend(
        [tr.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

    transforms_tr = transforms.Compose(transforms_tr)

    # Testing (during training transforms)
    transforms_ts = []
    transforms_ts.extend([
        tr.FixedResize(
            resolutions={
                x: tuple(p.TRAIN.SCALE)
                for x in p.ALL_TASKS.FLAGVALS
            },
            flagvals={x: p.TASKS.FLAGVALS[x]
                      for x in p.TASKS.FLAGVALS})
    ])
    transforms_ts.extend([
        tr.AddIgnoreRegions(),
        tr.ToTensor(),
        tr.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])
    transforms_ts = transforms.Compose(transforms_ts)

    return transforms_tr, transforms_ts
Example #3
0
def get_transformations(p):
    """ Return transformations for training and evaluationg """
    from data import custom_transforms as tr

    # Training transformations

    # Horizontal flips with probability of 0.5
    transforms_tr = [tr.RandomHorizontalFlip()]

    # Rotations and scaling
    transforms_tr.extend([
        tr.ScaleNRotate(rots=(-20, 20),
                        scales=(.75, 1.25),
                        flagvals={
                            x: p.ALL_TASKS.FLAGVALS[x]
                            for x in p.ALL_TASKS.FLAGVALS
                        })
    ])
    # Fixed Resize to input resolution
    transforms_tr.extend([
        tr.FixedResize(resolutions={
            x: tuple(p.TRAIN.SCALE)
            for x in p.ALL_TASKS.FLAGVALS
        },
                       flagvals={
                           x: p.ALL_TASKS.FLAGVALS[x]
                           for x in p.ALL_TASKS.FLAGVALS
                       })
    ])
    transforms_tr.extend([
        tr.AddIgnoreRegions(),
        tr.ToTensor(),
        tr.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])
    transforms_tr = transforms.Compose(transforms_tr)

    # Testing (during training transforms)
    transforms_ts = []
    transforms_ts.extend([
        tr.FixedResize(
            resolutions={x: tuple(p.TEST.SCALE)
                         for x in p.TASKS.FLAGVALS},
            flagvals={x: p.TASKS.FLAGVALS[x]
                      for x in p.TASKS.FLAGVALS})
    ])
    transforms_ts.extend([
        tr.AddIgnoreRegions(),
        tr.ToTensor(),
        tr.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])
    transforms_ts = transforms.Compose(transforms_ts)

    return transforms_tr, transforms_ts
 def transform_tr(self, sample):
     train_transforms = list()
     train_transforms.append(tr.Resize(self.cfg.LOAD_SIZE))
     train_transforms.append(tr.RandomScale(self.cfg.RANDOM_SCALE_SIZE))
     train_transforms.append(
         tr.RandomCrop(self.cfg.FINE_SIZE, pad_if_needed=True, fill=0))
     train_transforms.append(tr.RandomRotate())
     train_transforms.append(tr.RandomGaussianBlur())
     train_transforms.append(tr.RandomHorizontalFlip())
     # if self.cfg.TARGET_MODAL == 'lab':
     #     train_transforms.append(tr.RGB2Lab())
     if self.cfg.MULTI_SCALE:
         for item in self.cfg.MULTI_TARGETS:
             self.ms_targets.append(item)
         train_transforms.append(
             tr.MultiScale(size=self.cfg.FINE_SIZE,
                           scale_times=self.cfg.MULTI_SCALE_NUM,
                           ms_targets=self.ms_targets))
     train_transforms.append(tr.ToTensor())
     train_transforms.append(
         tr.Normalize(mean=self.cfg.MEAN,
                      std=self.cfg.STD,
                      ms_targets=self.ms_targets))
     composed_transforms = transforms.Compose(train_transforms)
     return composed_transforms(sample)
Example #5
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(),
            tr.ToTensor(),
        ])
        return composed_transforms(sample)
 def transform_val(self, sample):
     val_transforms = list()
     val_transforms.append(tr.Resize(self.cfg.LOAD_SIZE))
     if self.cfg.MULTI_SCALE:
         val_transforms.append(tr.MultiScale(size=self.cfg.FINE_SIZE,scale_times=self.cfg.MULTI_SCALE_NUM, ms_targets=self.ms_targets))
     val_transforms.append(tr.ToTensor())
     val_transforms.append(tr.Normalize(mean=self.cfg.MEAN, std=self.cfg.STD, ms_targets=self.ms_targets))
     composed_transforms = transforms.Compose(val_transforms)
Example #7
0
    def transform_val(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixScaleCrop(400),
            tr.Normalize(),
            tr.ToTensor(),
        ])
        return composed_transforms(sample)
Example #8
0
 def transform_tr(self, sample):
     composed_transforms = transforms.Compose([
         tr.RandomHorizontalFlip(),
         tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
         tr.Normalize(),
         tr.ToTensor(),
     ])
     return composed_transforms(sample)
Example #9
0
 def transform_tr(self, sample):
     composed_transforms = transforms.Compose([
         # tr.RandomHorizontalFlip(),
         tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size, fill=255),
         # tr.RandomGaussianBlur(),
         tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
         tr.ToTensor()])
     return composed_transforms(sample)
Example #10
0
    def transform_val(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixScaleCrop(400),
            tr.Normalize(mean=self.source_dist['mean'], std=self.source_dist['std']),
            tr.ToTensor(),
        ])
        return composed_transforms(sample)
Example #11
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=self.args.crop_size),
            tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
            tr.ToTensor()])

        return composed_transforms(sample)
Example #12
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(mean=self.source_dist['mean'], std=self.source_dist['std']),
            tr.ToTensor(),
        ])
        return composed_transforms(sample)
 def transform_tr(self, sample):
     train_transforms = list()
     train_transforms.append(tr.RandomHorizontalFlip())
     train_transforms.append(tr.RandomScaleCrop(base_size=self.cfg.LOAD_SIZE, crop_size=self.cfg.FINE_SIZE))
     train_transforms.append(tr.RandomGaussianBlur())
     train_transforms.append(tr.ToTensor())
     train_transforms.append(tr.Normalize(mean=self.cfg.MEAN, std=self.cfg.STD, ms_targets=self.ms_targets))
     composed_transforms = transforms.Compose(train_transforms)
     return composed_transforms(sample)
Example #14
0
    def transform_val(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixScaleCrop(400),
            tr.Normalize(mean=self.mean_std[0], std=self.mean_std[1]),
            tr.ToTensor()
        ])

        return composed_transforms(sample)
Example #15
0
    def transform_val(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixScaleCrop(400),
            #tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
            tr.Normalize(),
            tr.ToTensor(),
        ])
        return composed_transforms(sample)
Example #16
0
 def transform_tr(self, sample):
     composed_transforms = transforms.Compose([
         tr.RandomHorizontalFlip(),
         tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
         tr.RandomGaussianBlur(),
         tr.Normalize(mean=self.source_dist['mean'], std=self.source_dist['std']),
         tr.ToTensor(),
     ])
     return composed_transforms(sample)
Example #17
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(mean=self.mean_std[0],
                         std=self.mean_std[1]),  # tr.Normalize(),
            tr.ToTensor()
        ])

        return composed_transforms(sample)
Example #18
0
    def transform_pair_val(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixScaleCrop(400),
            tr.HorizontalFlip(),
            tr.GaussianBlur(),
            tr.Normalize(mean=self.source_dist['mean'], std=self.source_dist['std'], if_pair=True),
            tr.ToTensor(if_pair=True),
        ])
        return composed_transforms(sample)
Example #19
0
 def transform_finetune(self, sample):
     composed_transforms = transforms.Compose([
         tr.RandomHorizontalFlip(),
         # tr.RandomCrop(crop_size = 200),
         tr.RandomScaleCrop(base_size=600, crop_size=400, fill=0),
         tr.RandomGaussianBlur(),
         tr.Normalize(),
         tr.ToTensor()
     ])
     return composed_transforms(sample)
Example #20
0
    def transform_ts(self, sample):
        sample = tr.Normalize()(sample)
        sample = tr.ToTensor()(sample)
        # composed_transforms = transforms.Compose([
        #     tr.FixedResize(size=400),
        #     #tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
        #     tr.Normalize(),
        #     tr.ToTensor()])

        # return composed_transforms(sample)
        return sample
Example #21
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(mean=(0.1420, 0.2116, 0.2823),
                         std=(0.0899, 0.1083, 0.1310)),
            # tr.Normalize(),
            tr.ToTensor()
        ])

        return composed_transforms(sample)
Example #22
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(mean=(0.2382, 0.2741, 0.3068),
                         std=(0.1586, 0.1593, 0.1618)),
            # tr.Normalize(),
            tr.ToTensor()
        ])

        return composed_transforms(sample)
Example #23
0
 def transform_pair_train(self, sample):
     composed_transforms = transforms.Compose([
         tr.RandomHorizontalFlip(),
         tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
         #tr.RandomGaussianBlur(),
         tr.HorizontalFlip(),
         tr.GaussianBlur(),
         tr.Normalize(if_pair=True),
         tr.ToTensor(if_pair=True),
     ])
     return composed_transforms(sample)
Example #24
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(mean=(0.2709, 0.3400, 0.3707),
                         std=(0.1403, 0.1570, 0.1658)),
            # tr.Normalize(),
            tr.ToTensor()
        ])

        return composed_transforms(sample)
    def transform_val(self, sample):
        val_transforms = list()
        val_transforms.append(tr.FixScaleCrop(crop_size=self.cfg.FINE_SIZE))
        val_transforms.append(tr.ToTensor())
        val_transforms.append(
            tr.Normalize(mean=self.cfg.MEAN,
                         std=self.cfg.STD,
                         ms_targets=self.ms_targets))
        composed_transforms = transforms.Compose(val_transforms)

        return composed_transforms(sample)
Example #26
0
    def transform_pair_val(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixScaleCrop(400),
            #tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
            tr.HorizontalFlip(),
            tr.GaussianBlur(),
            tr.Normalize(if_pair=True),
            tr.ToTensor(if_pair=True),
        ])
        return composed_transforms(sample)
Example #27
0
    def transform_ts(self, sample):

        composed_transforms = transforms.Compose([
            tr.FixedResize(size=400),
            tr.Normalize(mean=(0.3441, 0.3809, 0.4014),
                         std=(0.1883, 0.2039, 0.2119)),
            # tr.Normalize(),
            tr.ToTensor()
        ])

        return composed_transforms(sample)
Example #28
0
 def transform_pair_train(self, sample):
     composed_transforms = transforms.Compose([
         tr.RandomHorizontalFlip(),
         tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
         tr.RandomGaussianBlur(),
         tr.ColorDistort(if_pair=True),
         #tr.CropAndResize(if_pair=True),
         tr.Normalize(mean=self.source_dist['mean'],
                      std=self.source_dist['std'],
                      if_pair=True),
         tr.ToTensor(if_pair=True),
     ])
     return composed_transforms(sample)
Example #29
0
    def transform_tr(self, sample):
        sample = tr.Normalize()(sample)
        sample = tr.ToTensor()(sample)
        # composed_transforms = transforms.Compose([
        #     #tr.RandomHorizontalFlip(),
        #     tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
        #     #tr.RandomGaussianBlur(),
        #     #tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
        #     tr.Normalize(),
        #     tr.ToTensor()])

        # return composed_transforms(sample)
        return sample
Example #30
0
    def transform_tr(self, sample):
        composed_transforms = transforms.Compose([
            tr.RandomHorizontalFlip(),
            tr.RandomVerticalFlip(),
            tr.RandomRotate(180),
            tr.RandomScaleCrop(base_size=400, crop_size=400, fill=0),
            tr.RandomGaussianBlur(),
            # tr.Normalize(),
            tr.Normalize(mean=(0.2382, 0.2741, 0.3068),
                         std=(0.1586, 0.1593, 0.1618)),
            tr.ToTensor(),
        ])

        return composed_transforms(sample)