-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.py
65 lines (51 loc) · 1.75 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import torch
from options.test_options import TestOptions
import torch.distributed as dist
from data import CreateDataLoader
from models import create_model
from util import html_util as html
from util.visualizer import save_images
import pygame
import ntpath
import numpy as np
import random
os.environ['NCCL_IB_DISABLE'] = '1'
opt = TestOptions().parse()
opt.nThreads = 1 # test code only supports nThreads = 1
opt.batchSize = 1 # test code only supports batchSize = 1
opt.serial_batches = True # no shuffle
opt.no_flip = True # no flip
torch.manual_seed(opt.seed)
torch.cuda.manual_seed_all(opt.seed)
np.random.seed(opt.seed)
random.seed(opt.seed)
if opt.model in ['Erase','erase','erasenet', 'gateconv']:
opt.data_norm = False
# opt.isTrain = True
data_loader = CreateDataLoader(opt, dist)
dataset = data_loader.load_data()
# opt.isTrain = False
model = create_model(opt)
pygame.init()
model.setup(opt)
back_trans = None
if hasattr(data_loader.dataset, "back_transform"):
back_trans = data_loader.dataset.back_transform
print("reshape trans")
web_dir = os.path.join("../ablation/", opt.model, opt.name, '%s_%s' % (opt.phase, opt.which_epoch))
webpage = html.HTML(web_dir, 'Experiment = %s, Phase = %s, Epoch = %s' % (opt.name, opt.phase, opt.which_epoch))
# test
print(len(dataset))
for i, data in enumerate(dataset):
if i > opt.how_many:
break
model.set_input(data)
model.test()
visuals = model.get_current_visuals(back_trans)
img_path = model.get_image_paths()
if i % 10 == 0:
print('process image...%s, %s' % (i, img_path))
save_images(webpage, visuals, img_path)
webpage.save()
# python test.py --dataset_mode syn_online --model pix2pix --name unet --netG unet_512 --n_layers_D 6 --which_epoch latest