def main(): opt = parse_args() print(opt) # if manual seed is not provide then pick one randomly if opt.manualSeed is None: opt.manualSeed = random.randint(1, 10000) print('Random Seed: ', opt.manualSeed) random.seed(opt.manualSeed) torch.manual_seed(opt.manualSeed) # check wether cuda is available if torch.cuda.is_available() and not opt.cuda: print("WARNING: You have a CUDA device, so you should probably run with --cuda") if opt.cuda: torch.cuda.manual_seed_all(opt.manualSeed) cudnn.enabled = True cudnn.benchmark = False # prepare the output directories try: os.makedirs(opt.outf) os.makedirs(os.path.join(opt.outf, 'figures')) except OSError: pass # prepare the data loader x_files_list_file = opt.xFilesList y_files_list_file = opt.yFilesList in_dim = opt.mgcDim out_dim = opt.mgcDim with open(x_files_list_file, 'r') as fid: x_files_list = [l.strip() for l in fid.readlines()] with open(y_files_list_file, 'r') as fid: y_files_list = [l.strip() for l in fid.readlines()] data_loader = get_loader(x_files_list, y_files_list, in_dim, out_dim, opt.batchSize, False, 0) # get the device device = torch.device("cuda:0" if opt.cuda else "cpu") # define the generator netG = define_netG(in_ch=2,device=device) if opt.netG != '': netG.load_state_dict(torch.load(opt.netG)) print(netG) # define the discriminator netD = define_netD(device=device) if opt.netD != '': netD.load_state_dict(torch.load(opt.netD)) print(netD) if opt.mode == 'train': train(netD, netG, data_loader, opt) elif opt.mode == 'test': test(netG, opt) else: print('Mode must be either train or test only')
print('Random Seed: ', opt.manualSeed) random.seed(opt.manualSeed) torch.manual_seed(opt.manualSeed) if torch.cuda.is_available() and not opt.cuda: print( "WARNING: You have a CUDA device, so you should probably run with --cuda" ) if opt.cuda: torch.cuda.manual_seed_all(opt.manualSeed) cudnn.enabled = True cudnn.benchmark = True # define the generator netG = define_netG(in_ch=2) if opt.netG != '': netG.load_state_dict(torch.load(opt.netG)) print(netG) # define the discriminator netD = define_netD() if opt.netD != '': netD.load_state_dict(torch.load(opt.netD)) print(netD) if opt.mode == 'train': train(netD, netG, data_loader, opt) elif opt.mode == 'test': test(netG, opt) else: print('Mode must be either train or test only')
opt.manualSeed = random.randint(1, 10000) print('Random Seed: ', opt.manualSeed) random.seed(opt.manualSeed) torch.manual_seed(opt.manualSeed) if torch.cuda.is_available() and not opt.cuda: print("WARNING: You have a CUDA device, so you should probably run with --cuda") if opt.cuda: torch.cuda.manual_seed_all(opt.manualSeed) cudnn.enabled = False cudnn.benchmark = False # define the generator netG = define_netG(in_ch=2, device=device) if opt.netG != '': netG.load_state_dict(torch.load(opt.netG)) print(netG) # define the discriminator netD = define_netD(device=device) if opt.netD != '': netD.load_state_dict(torch.load(opt.netD)) print(netD) if opt.mode == 'train': train(netD, netG, data_loader, opt) elif opt.mode == 'test': test(netG, opt) else: print('Mode must be either train or test only')
random.seed(opt.manualSeed) torch.manual_seed(opt.manualSeed) if torch.cuda.is_available() and not opt.cuda: print("WARNING: You have a CUDA device, so you should probably run with --cuda") if opt.cuda: torch.cuda.manual_seed_all(opt.manualSeed) cudnn.enabled = False cudnn.benchmark = False # define the generator netG_AB = define_netG(in_ch=2, device=device) if opt.netG != '': netG_AB.load_state_dict(torch.load(opt.netG)) print(netG_AB) netG_BA = define_netG(in_ch=2, device=device) # define the discriminator netD_A = define_netD(device=device) if opt.netD != '': netD_A.load_state_dict(torch.load(opt.netD)) print(netD_A) netD_B = define_netD(device=device) if opt.mode == 'train': train(netD_A=netD_A, netD_B=netD_B, netG_AB=netG_AB, netG_BA=netG_BA, data_loader=data_loader, opt=opt, device=device) else: print('Mode must be either train or test only')
if opt.manualSeed is None: opt.manualSeed = random.randint(1, 10000) print('Random Seed: ', opt.manualSeed) random.seed(opt.manualSeed) torch.manual_seed(opt.manualSeed) if opt.cuda: torch.cuda.manual_seed_all(opt.manualSeed) cudnn.benchmark = True if torch.cuda.is_available() and not opt.cuda: print("WARNING: You have a CUDA device, so you should probably run with --cuda") nz = int(opt.nz) # define the generator netG = define_netG(opt.nz, opt.acSize) if opt.netG != '': netG.load_state_dict(torch.load(opt.netG)) print(netG) # define the discriminator netD = define_netD(opt.acSize) if opt.netD != '': netD.load_state_dict(torch.load(opt.netD)) print(netD) if opt.mode == 'train': train(netD, netG, opt) elif opt.mode == 'test': test(netG, opt) else: print('Mode must be either train or test only')