Exemplo n.º 1
0
 def __init__(self, cfg):
     super(Data, self).__init__()
     self.cfg = cfg
     # 下面是数据增强等
     self.randombrig = RandomBrightness()
     self.normalize = Normalize(mean=cfg.mean, std=cfg.std)
     self.randomcrop = RandomCrop()
     self.blur = RandomBlur()
     self.randomvflip = RandomVorizontalFlip()
     self.randomhflip = RandomHorizontalFlip()
     self.resize = Resize(384, 384)
     self.totensor = ToTensor()
     # 读数据
     with open(cfg.datapath + '/' + cfg.mode + '.txt', 'r') as lines:
         self.samples = []
         for line in lines:
             self.samples.append(line.strip())
Exemplo n.º 2
0
    start_epoch = 0

train_img_shape = tuple([int(x) for x in args.train_img_shape])

img_transform_list = [
    Scale(train_img_shape, Image.BILINEAR),
    ToTensor(),
    # Normalize([.485, .456, .406], [.229, .224, .225])
]

if args.augment:
    aug_list = [
        RandomRotation(),
        # RandomVerticalFlip(), # non-realistic
        RandomHorizontalFlip(),
        RandomSizedCrop()
    ]
    img_transform_list = aug_list + img_transform_list

img_transform = Compose(img_transform_list)

label_transform = Compose([
    Scale(train_img_shape, Image.NEAREST),
    ToLabel(),
    ReLabel(255, args.n_class - 1),
])

src_dataset = get_dataset(dataset_name=args.src_dataset,
                          split=args.split,
                          img_transform=img_transform,
Exemplo n.º 3
0
# Save param dic
if resume_flg:
    json_fn = os.path.join(args.outdir, "param-%s_resume.json" % model_name)
else:
    json_fn = os.path.join(outdir, "param-%s.json" % model_name)
check_if_done(json_fn)
save_dic_to_json(args.__dict__, json_fn)

train_img_shape = tuple([int(x) for x in args.train_img_shape])
img_transform_list = [
    Scale(train_img_shape, Image.BILINEAR),
    ToTensor(),
    Normalize([.485, .456, .406], [.229, .224, .225])
]
if args.augment:
    aug_list = [RandomRotation(), RandomHorizontalFlip(), RandomSizedCrop()]
    img_transform_list = aug_list + img_transform_list

img_transform = Compose(img_transform_list)

label_transform = Compose([
    Scale(train_img_shape, Image.NEAREST),
    ToLabel(),
    ReLabel(255,
            args.n_class - 1),  # Last Class is "Void" or "Background" class
])

src_dataset = get_dataset(dataset_name=args.src_dataset,
                          split=args.src_split,
                          img_transform=img_transform,
                          label_transform=label_transform,