-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.py
68 lines (54 loc) · 1.99 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
64
65
66
67
import time
import torch
import numpy as np
import pytorch_ssim
import torchvision.utils as vutils
from util import util
from models import create_model
from options.options import CollorOptions
from skimage.measure import compare_psnr, compare_ssim
from skimage import io
from skimage.color import rgb2gray
from torchvision import transforms
opt = CollorOptions().parse()
model = create_model.create_collar_model(opt)
model = model.cuda(opt.gpuid)
Tensor = torch.cuda.FloatTensor
class trans:
def __init__(self):
self.transform = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize((128, 128), interpolation=2),
transforms.RandomAffine(degrees=15, scale=(0.85, 1.55), translate=(0.10, 0.0)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])
self.org_transform = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize((128, 128), interpolation=2),
transforms.ToTensor(),
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])
trans = trans()
for i in range(1, 9):
path = './example/'
edge = io.imread(path + 'edge/%02d.png' % i)
src = io.imread(path + 'src/%02d.png' % i)
# ref = rgb2gray(ref)
edge = trans.transform(np.uint8(edge))
src = trans.org_transform(src.astype(np.uint8))
edge_tensor = edge.cuda(opt.gpuid)
src_tensor = src.cuda(opt.gpuid)
edge_tensor = torch.unsqueeze(edge_tensor, 0).cuda(opt.gpuid)
src_tensor = torch.unsqueeze(src_tensor, 0).cuda(opt.gpuid)
with torch.no_grad():
edgeFeat = model.edgeE(edge_tensor)
srcFeat = model.srcE(src_tensor)
syn = model.netG(torch.cat((edgeFeat, srcFeat), dim=1), src_tensor)
print('Save images.')
path = './example/syn/' + str(i + 1)
util.mkdir(path)
vutils.save_image(
syn, '%s/%02d.png' % (path, i),
normalize=True
)