-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_demo.py
65 lines (46 loc) · 1.83 KB
/
test_demo.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
64
65
import os
import numpy
from options.test_pose_options import TestPoseOptions
from data import CreateDataLoader
from models import create_model
from skimage.io import imread, imsave
from scipy.misc import imresize
def deprocess_image(img):
return (255 * ((img + 1) / 2.0)).astype(numpy.uint8)
if __name__ == '__main__':
opt = TestPoseOptions().parse()
opt.nThreads = 1 # test code only supports nThreads = 1
opt.batchSize = 1 # test code only supports batchSize = 1
opt.serial_batches = True ##### randomly choose the target pose ####
opt.no_flip = True # no flip
opt.display_id = -1 # no visdom display
opt.no_lsgan= False
data_loader = CreateDataLoader(opt)
dataset = data_loader.load_data()
model = create_model(opt)
model.setup(opt)
if not os.path.exists(opt.results_dir):
os.makedirs(opt.results_dir)
# test
for i, data in enumerate(dataset):
if i >= opt.how_many:
break
model.set_input(data)
model.test()
fake_B = model.fake_B.cpu().numpy()
fake_B = fake_B[0]
fake_B = numpy.transpose(fake_B,(1,2,0))
fake_A = model.fake_A.cpu().numpy()
fake_A = fake_A[0]
fake_A = numpy.transpose(fake_A,(1,2,0))
img_A_path = model.image_A_paths[0]
img_B_path = model.image_B_paths[0]
A_parsing = model.A_parsing.cpu().numpy()
A = imread(img_A_path)
B = imread(img_B_path)
fake_A = deprocess_image(fake_A)
fake_B = deprocess_image(fake_B)
A_name = img_A_path.split('/')[-1]
B_name = img_B_path.split('/')[-1]
imname = os.path.join(opt.results_dir, A_name + '_' + B_name +'.png')
imsave(imname,numpy.concatenate((A, B, fake_B),axis=1))