def main(args): print(args) cudnn.benchmark = True torch.manual_seed(args.seed) solver = Solver(args) if args.mode == 'train': assert len(subdirs(args.train_img_dir)) == args.num_domains assert len(subdirs(args.val_img_dir)) == args.num_domains loaders = Munch(src=get_train_loader(root=args.train_img_dir, which='source', img_size=args.img_size, batch_size=args.batch_size, prob=args.randcrop_prob, num_workers=args.num_workers), ref=get_train_loader(root=args.train_img_dir, which='reference', img_size=args.img_size, batch_size=args.batch_size, prob=args.randcrop_prob, num_workers=args.num_workers), val=get_test_loader(root=args.val_img_dir, img_size=args.img_size, batch_size=args.val_batch_size, shuffle=True, num_workers=args.num_workers)) solver.train(loaders) elif args.mode == 'test': solver.test() elif args.mode == 'sample': assert len(subdirs(args.src_dir)) == args.num_domains assert len(subdirs(args.ref_dir)) == args.num_domains loaders = Munch(src=get_test_loader(root=args.src_dir, img_size=args.img_size, batch_size=args.val_batch_size, shuffle=False, num_workers=args.num_workers), ref=get_test_loader(root=args.ref_dir, img_size=args.img_size, batch_size=args.val_batch_size, shuffle=False, num_workers=args.num_workers)) solver.sample(loaders) elif args.mode == 'eval': solver.evaluate() elif args.mode == 'align': from core.wing import align_faces align_faces(args, args.inp_dir, args.out_dir) else: raise NotImplementedError
def main(config): # For fast training. cudnn.benchmark = True # Create directories if not exist. if not os.path.exists(config.log_dir): os.makedirs(config.log_dir) if not os.path.exists(config.model_save_dir): os.makedirs(config.model_save_dir) if not os.path.exists(config.sample_dir): os.makedirs(config.sample_dir) if not os.path.exists(config.result_dir): os.makedirs(config.result_dir) # Data loader. celeba_loader = None rafd_loader = None if config.dataset in ['CelebA', 'Both']: celeba_loader = get_loader(config.celeba_image_dir, config.attr_path, config.selected_attrs, config.celeba_crop_size, config.image_size, config.batch_size, 'CelebA', config.mode, config.num_workers) if config.dataset in ['RaFD', 'Both']: rafd_loader = get_loader(config.rafd_image_dir, None, None, config.rafd_crop_size, config.image_size, config.batch_size, 'RaFD', config.mode, config.num_workers) # Solver for training and testing StarGAN. solver = Solver(celeba_loader, rafd_loader, config) if config.mode == 'train': if config.dataset in ['CelebA', 'RaFD']: solver.train() elif config.dataset in ['Both']: solver.train_multi() elif config.mode == 'test': if config.dataset in ['CelebA', 'RaFD']: solver.test() elif config.dataset in ['Both']: solver.test_multi()