Skip to content

Commit 6d0306f

Browse files
committed
update for loading mask image and multiple styles
1 parent 16a2798 commit 6d0306f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

test.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import torch
22

33
from network import AvatarNet
4-
from utils import imload, imsave
4+
from utils import imload, imsave, maskload
55

66

77
def network_test(args):
88
# set device
9-
device = torch.device("cuda" if args.cuda_device_no >= 0 else "cpu")
9+
device = torch.device('cuda' if args.gpu_no >= 0 else 'cpu')
10+
11+
# load check point
12+
check_point = torch.load(args.check_point)
1013

1114
# load network
1215
network = AvatarNet(args.layers)
13-
network.load_state_dict(torch.load(args.model_load_path))
16+
network.load_state_dict(check_point['state_dict'])
1417
network = network.to(device)
1518

1619
# load target images
17-
content_image = imload(args.test_content_image_path, args.imsize, args.cropsize)
18-
style_image = imload(args.test_style_image_path, args.imsize, args.cropsize)
19-
content_image, style_image = content_image.to(device), style_image.to(device)
20-
20+
content_img = imload(args.content, args.imsize, args.cropsize).to(device)
21+
style_imgs = [imload(style, args.imsize, args.cropsize, args.cencrop).to(device) for style in args.style]
22+
masks = None
23+
if args.mask:
24+
masks = [maskload(mask).to(device) for mask in args.mask]
25+
2126
# stylize image
2227
with torch.no_grad():
23-
output_image = network(content_image, style_image, args.train_flag, args.style_strength, args.patch_size, args.patch_stride)
28+
stylized_img = network(content_img, style_imgs, args.style_strength, args.patch_size, args.patch_stride,
29+
masks, args.interpolation_weights, args.preserve_color, False)
2430

25-
imsave(output_image.data, args.output_image_path)
26-
27-
return output_image
31+
imsave(stylized_img, 'stylized_image.jpg')
32+
33+
return None

0 commit comments

Comments
 (0)