|
7 | 7 | from scipy.misc import imresize |
8 | 8 |
|
9 | 9 |
|
| 10 | +# save image to the disk |
| 11 | +def save_images(webpage, visuals, image_path, aspect_ratio=1.0, width=256): |
| 12 | + image_dir = webpage.get_image_dir() |
| 13 | + short_path = ntpath.basename(image_path[0]) |
| 14 | + name = os.path.splitext(short_path)[0] |
| 15 | + |
| 16 | + webpage.add_header(name) |
| 17 | + ims, txts, links = [], [], [] |
| 18 | + |
| 19 | + for label, im_data in visuals.items(): |
| 20 | + im = util.tensor2im(im_data) |
| 21 | + image_name = '%s_%s.png' % (name, label) |
| 22 | + save_path = os.path.join(image_dir, image_name) |
| 23 | + h, w, _ = im.shape |
| 24 | + if aspect_ratio > 1.0: |
| 25 | + im = imresize(im, (h, int(w * aspect_ratio)), interp='bicubic') |
| 26 | + if aspect_ratio < 1.0: |
| 27 | + im = imresize(im, (int(h / aspect_ratio), w), interp='bicubic') |
| 28 | + util.save_image(im, save_path) |
| 29 | + |
| 30 | + ims.append(image_name) |
| 31 | + txts.append(label) |
| 32 | + links.append(image_name) |
| 33 | + webpage.add_images(ims, txts, links, width=width) |
| 34 | + |
| 35 | + |
10 | 36 | class Visualizer(): |
11 | 37 | def __init__(self, opt): |
12 | 38 | self.display_id = opt.display_id |
@@ -124,28 +150,3 @@ def print_current_losses(self, epoch, i, losses, t, t_data): |
124 | 150 | print(message) |
125 | 151 | with open(self.log_name, "a") as log_file: |
126 | 152 | log_file.write('%s\n' % message) |
127 | | - |
128 | | - # save image to the disk |
129 | | - def save_images(self, webpage, visuals, image_path, aspect_ratio=1.0): |
130 | | - image_dir = webpage.get_image_dir() |
131 | | - short_path = ntpath.basename(image_path[0]) |
132 | | - name = os.path.splitext(short_path)[0] |
133 | | - |
134 | | - webpage.add_header(name) |
135 | | - ims, txts, links = [], [], [] |
136 | | - |
137 | | - for label, im_data in visuals.items(): |
138 | | - im = util.tensor2im(im_data) |
139 | | - image_name = '%s_%s.png' % (name, label) |
140 | | - save_path = os.path.join(image_dir, image_name) |
141 | | - h, w, _ = im.shape |
142 | | - if aspect_ratio > 1.0: |
143 | | - im = imresize(im, (h, int(w * aspect_ratio)), interp='bicubic') |
144 | | - if aspect_ratio < 1.0: |
145 | | - im = imresize(im, (int(h / aspect_ratio), w), interp='bicubic') |
146 | | - util.save_image(im, save_path) |
147 | | - |
148 | | - ims.append(image_name) |
149 | | - txts.append(label) |
150 | | - links.append(image_name) |
151 | | - webpage.add_images(ims, txts, links, width=self.win_size) |
|
0 commit comments