Exemplo n.º 1
0
dataset_dir = os.path.join(foreign_dir, 'datasets', args.dataset)
soft_data_dir = os.path.join(foreign_dir, 'train_set_result', args.dataset)
transforms_ = [
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
]  # (0,1) -> (-1,1)
dataloader = DataLoader(PairedImageDataset(dataset_dir,
                                           soft_data_dir,
                                           transforms_=transforms_,
                                           mode=args.task),
                        batch_size=args.batch_size,
                        shuffle=True,
                        num_workers=args.cpus,
                        drop_last=True)
dataloader_test = DataLoader(ImageDataset(os.path.join(dataset_dir, 'test',
                                                       source_str),
                                          transforms_=transforms_),
                             batch_size=1,
                             shuffle=False,
                             num_workers=args.cpus)

# FID img dirs:
test_img_generation_dir_temp = os.path.join(results_dir,
                                            'test_set_generation_temp')
create_dir(test_img_generation_dir_temp)
img_paths_for_FID = [
    test_img_generation_dir_temp,
    os.path.join(dataset_dir, 'train', target_str)
]

# Inputs & targets memory allocation
Exemplo n.º 2
0
netD.load_state_dict(torch.load(d_path)['netD'])
print('load D from %s' % d_path)
start_epoch = 0
best_FID = 1e9
loss_G_lst, loss_G_perceptual_lst, loss_G_GAN_lst, loss_D_lst = [], [], [], []

# Dataset loader: img shape=(256,256)
dataset_dir = os.path.join(foreign_dir, 'datasets', args.dataset)
soft_data_dir = os.path.join(foreign_dir, 'train_set_result', args.dataset)
transforms_ = [ transforms.ToTensor(),
                transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5)) ] # (0,1) -> (-1,1)
dataloader = DataLoader(
    PairedImageDataset(dataset_dir, soft_data_dir, transforms_=transforms_, mode=args.task), 
    batch_size=args.batch_size, shuffle=True, num_workers=args.cpus, drop_last=True)
dataloader_test = DataLoader(
    ImageDataset(os.path.join(dataset_dir, 'test', source_str), transforms_=transforms_), 
    batch_size=1, shuffle=False, num_workers=args.cpus)

# FID img dirs:
test_img_generation_dir_temp = os.path.join(results_dir, 'test_set_generation_temp')
create_dir(test_img_generation_dir_temp)
img_paths_for_FID = [test_img_generation_dir_temp, os.path.join(dataset_dir, 'train', target_str)]

# Inputs & targets memory allocation
Tensor = torch.cuda.FloatTensor
input_source = Tensor(args.batch_size, args.input_nc, args.size, args.size)
input_target = Tensor(args.batch_size, args.output_nc, args.size, args.size)
target_real = Variable(Tensor(args.batch_size).fill_(1.0), requires_grad=False)
target_fake = Variable(Tensor(args.batch_size).fill_(0.0), requires_grad=False)
fake_img_buffer = ReplayBuffer()
input_source_test = Tensor(1, args.input_nc, args.size, args.size)