def transform_tr(self, sample): if random.random() > 0.5: if random.random() > 0.5: tr_function = tr.FixScaleCrop else: tr_function = tr.FixedResize composed_transforms = transforms.Compose( [ tr_function(self.args.crop_size), tr.RandomGaussianBlur(), tr.Normalize( mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225) ), tr.ToTensor(), ] ) else: composed_transforms = transforms.Compose( [ 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)
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), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std = (0.229, 0.224, 0.225)), tr.ToTensor()])
def transform_tr(self, sample): # if (sample['image'].width>self.args.base_size*2) and (sample['image'].height>self.args.base_size*2): # composed_transforms = transforms.Compose([ # tr.RandomHorizontalFlip(), # tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), # tr.RandomGaussianBlur(), # tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), # tr.ToTensor()]) # else: # composed_transforms = transforms.Compose([ # # tr.FixScaleCrop(crop_size=self.args.crop_size), # tr.RandomHorizontalFlip(), # tr.RandomGaussianBlur(), # tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), # tr.ToTensor()]) composed_transforms = transforms.Compose([ tr.RandomHorizontalFlip(), tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) return composed_transforms(sample)
def transform_tr(self, sample): composed_transforms = transforms.Compose([ tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) return composed_transforms(sample)
def transform_tr(self, sample): # eventually, according to the condition of split in self.split, then split == 'train' composed_transforms = transforms.Compose([ # define transform_tr tr.RandomHorizontalFlip(), tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), # random scale crop, we have to calcualte base_size and crop_size based on argparse tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor()]) return composed_transforms(sample) # return composed_transforms
def transform(self, sample): composed_transforms = transforms.Compose([ tr.RandomHorizontalFlip(), tr.RandomScaleCrop(base_size=self.cfg.DATASET.BASE_SIZE, crop_size=self.cfg.DATASET.CROP_SIZE), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor()]) return composed_transforms(sample)
def transform_tr(self, sample): composed_transforms = transforms.Compose([ tr.FixedResize(size=(1024, 2048)), tr.ColorJitter(), tr.RandomGaussianBlur(), tr.RandomMotionBlur(), tr.RandomHorizontalFlip(), tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size, fill=255), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor()]) return composed_transforms(sample)
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.279, 0.293, 0.290), std=(0.197, 0.198, 0.201)), tr.ToTensor() ]) return composed_transforms(sample)
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), tr.RandomGaussianBlur(), tr.Resize_normalize_train(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)) ]) return composed_transforms(sample)
def transform_tr(self, sample): composed_transforms = transforms.Compose([ tr.FixedNoMaskResize(size=self.args.crop_size), tr.RandomColorJeter(0.3, 0.3, 0.3, 0.3), tr.RandomHorizontalFlip(), # tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor()]) return composed_transforms(sample)
def transform_train(self, sample): composed_transforms = transforms.Compose([ self.scalecrop, tr.RandomHorizontalFlip(), #tr.RandomScaleCrop(base_size=self.base_size, crop_size=self.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)
def transform_train(self, sample): composed_transforms = transforms.Compose([ tr.FixScaleCrop(crop_size=self.crop_size), tr.RandomHorizontalFlip(), tr.RandomGaussianBlur(), tr.Normalize(mean=[0.4911], std=[0.1658]), tr.ToTensor() ]) transformed = composed_transforms(sample) transformed['image'] = transformed['image'].unsqueeze(0) return transformed
def transform_tr_part1(self, sample): if self.args.use_small: composed_transforms = transforms.Compose( [tr.FixScaleCrop(crop_size=self.args.crop_size)]) else: composed_transforms = transforms.Compose([ tr.RandomHorizontalFlip(), tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), tr.RandomGaussianBlur() ]) # Zhiwei return composed_transforms(sample)
def transform_tr(self, sample): composed_transforms = transforms.Compose([ tr.RandomHorizontalFlip( ), # given PIL image randomly with a given probability tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) return composed_transforms(sample)
def transform_tr(self, sample): composed_transforms = transforms.Compose([ # transforms.ColorJitter(brightness=(-1,1),contrast=(-1, 1),saturation=(-0.3, 0.3), hue=(-0.3, 0.3)), # transforms.ColorJitter(brightness=0.4, contrast=0.4,saturation=0.4), tr.RandomHorizontalFlip(), tr.GaussianNoise(), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.PatchToTensor() ]) return composed_transforms(sample)
def transform_tr(self, sample): composed_transforms = transforms.Compose([ #tr.RandomHorizontalFlip(), tr.RandomRotate(degree=random.randint(15, 350)), 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)
def transform_tr(self, sample): #print(sample) composed_transforms = transforms.Compose([ tr.RandomHorizontalFlip(), tr.FixScaleCrop(crop_size=self.args.crop_size), #tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor(), tr.Lablize(high_confidence=self.args.high_confidence) ]) return composed_transforms(sample)
def transform_train(self, sample): composed_transforms = transforms.Compose([ tr.RandomHorizontalFlip(), tr.RandomVerticalFlip(), # tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size, fill=255), # tr.FixedResize(size=self.args.crop_size), tr.RandomRotate(), tr.RandomGammaTransform(), tr.RandomGaussianBlur(), tr.RandomNoise(), tr.Normalize(mean=(0.544650, 0.352033, 0.384602, 0.352311), std=(0.249456, 0.241652, 0.228824, 0.227583)), tr.ToTensor()]) return composed_transforms(sample)
def transform_tr(self, sample): ''' Transform the given training sample. @param sample: The given training 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(), tf.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) return composed_transforms(sample)
def __init__(self, args, split='train', ): super().__init__() self._dataset = ic.get_dataset('ilabs.vision', 'scarlet300') files = list(self._dataset[split]) images = sorted(f for f in files if f.endswith('.png')) masks_filename = self.CACHE_BOX % split if not os.path.exists(masks_filename): print('Generating CACHE for split', split) masks = [generate_first_box(fname) for fname in tqdm(images)] torch.save(masks, masks_filename) else: masks = torch.load(masks_filename) assert len(images) == len(masks) self._images = images self._masks = masks self.split = split self.args = args if split == 'train': self._transform = transforms.Compose([ # tr.RandomHorizontalFlip(), # tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size, fill=0xffffff), tr.RandomGaussianBlur(), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) elif split == 'test': self._transform = transforms.Compose([ # tr.FixScaleCrop(crop_size=self.args.crop_size), tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) else: raise ValueError('Unknown split: ' + split)
def transform_tr(self, sample): color_transforms = [ transforms.RandomApply([transforms.ColorJitter(brightness=0.1) ]), # brightness transforms.RandomApply([transforms.ColorJitter(contrast=0.1) ]), # contrast transforms.RandomApply([transforms.ColorJitter(saturation=0.1) ]), # saturation transforms.RandomApply([transforms.ColorJitter(hue=0.05)]) ] # hue joint_transforms = transforms.Compose([ tr.RandomHorizontalFlip(), tr.RandomScaleCrop(base_size=self.args.base_size, crop_size=self.args.crop_size, fill=255), tr.equalize(), tr.RandomGaussianBlur(), tr.RandomRotate(degree=7) ]) image_transforms = transforms.Compose([ transforms.RandomOrder(color_transforms), transforms.RandomGrayscale(p=0.3) ]) normalize_transforms = transforms.Compose([ tr.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), tr.ToTensor() ]) tmp_sample = joint_transforms(sample) tmp_sample['image'] = image_transforms(tmp_sample['image']) tmp_sample = normalize_transforms(tmp_sample) return tmp_sample
def transform_tr(self, sample): """ composed transformers for training dataset :param sample: {'image': image, 'label': label} :return: """ img = sample['image'] img = transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.5, hue=0.2)(img) sample = {'image': img, 'label': sample['label']} composed_transforms = transforms.Compose([ ct.RandomHorizontalFlip(), ct.RandomScaleCrop(base_size=self.base_size, crop_size=self.crop_size), # ct.RandomChangeBackground(), ct.RandomGaussianBlur(), ct.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)), ct.ToTensor() ]) return composed_transforms(sample)
def make_data_loader(args, **kwargs): # if args.dataset == 'pascal': # train_set = pascal.VOCSegmentation(args, split='train') # val_set = pascal.VOCSegmentation(args, split='val') # if args.use_sbd: # sbd_train = sbd.SBDSegmentation(args, split=['train', 'val']) # train_set = combine_dbs.CombineDBs([train_set, sbd_train], excluded=[val_set]) # # num_class = train_set.NUM_CLASSES # train_loader = DataLoader(train_set, batch_size=args.batch_size, shuffle=True, **kwargs) # val_loader = DataLoader(val_set, batch_size=args.batch_size, shuffle=False, **kwargs) # TODO: add a crop here, because the images are not of the same size (Square or whatever) tfs = transforms.Compose([ tr.TestMode(), tr.FixedResize(512), tr.RandomHorizontalFlip(), tr.RandomGaussianBlur(), tr.ToTensor() ]) data = ImageFolder(root=args.test_root, transform=tfs) test_loader = DataLoader(data, batch_size=args.batch_size, num_workers=0) return None, None, test_loader, 1
def transform_tr_part1_2(self, sample): if not self.args.use_small: composed_transforms = transforms.Compose([tr.RandomGaussianBlur()]) return composed_transforms(sample)