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)
def __init__(self): self.root = Path.db_root_dir('penn') self.transform = transforms.Compose( [tr.FixedResize(550), tr.ToTensor()]) self.PNGImagesRoot = "PNGImages" self.PedMasksRoot = "PedMasks" # 加载image和mask,sort是为了保证他们一一对应 self.imgs = list( sorted(os.listdir(os.path.join(self.root, self.PNGImagesRoot)))) self.masks = list( sorted(os.listdir(os.path.join(self.root, self.PedMasksRoot))))
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() ]) return composed_transforms(sample)
def transform(sample): train_transform = transforms.Compose([ tr.FixedResize(700), # 如果内存不够就resize到700或者512 tr.ToTensor(), ]) return train_transform(sample)