-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_satellite.py
executable file
·59 lines (47 loc) · 1.84 KB
/
test_satellite.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
"""
Copyright (C) 2019 NVIDIA Corporation. All rights reserved.
Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
"""
import os
from collections import OrderedDict
import data
from options.test_options import TestOptions
from models.pix2pix_satellite_model import Pix2PixSatelliteModel
from util.visualizer import Visualizer
from util import html
from trainers.pix2pix_satellite_trainer import ClassDist
import numpy as np
import cv2
def save_mask(mask, path, mask_path):
mask = mask.detach().cpu().numpy()[0]
name = os.path.basename(path[0])
path = os.path.join(mask_path, "{}.png".format(name))
cv2.imwrite(path, mask*255)
opt = TestOptions().parse()
#class_dist = ClassDist(opt)
dataloader = data.create_dataloader(opt)
model = Pix2PixSatelliteModel(opt)
model.eval()
visualizer = Visualizer(opt)
# create a webpage that summarizes the all results
web_dir = os.path.join(opt.results_dir, 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))
#masks_path = "./masks_{}".format(opt.name)
#os.makedirs(masks_path, exist_ok=True)
# test
for i, data_i in enumerate(dataloader):
if i * opt.batchSize >= opt.how_many:
break
#class_dist.get_class_dist(data_i)
generated = model(data_i, mode='inference')
img_path = data_i['path']
for b in range(generated.shape[0]):
print('process image... %s' % img_path[b])
visuals = OrderedDict([('input_label', data_i['label'][b]),
('synthesized_image', generated[b])])
#save_mask(data_i['label'][b], img_path[b:b + 1], masks_path)
visualizer.save_images(webpage, visuals, img_path[b:b + 1])
webpage.save()