Skip to content

Commit bd73e45

Browse files
author
junyanz
committed
automatically create visdom connections
1 parent 5762f5b commit bd73e45

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

util/visualizer.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def __init__(self, opt):
7575
if self.display_id > 0: # connect to a visdom server given <display_port> and <display_server>
7676
import visdom
7777
self.ncols = opt.display_ncols
78-
self.vis = visdom.Visdom(server=opt.display_server, port=opt.display_port, env=opt.display_env, raise_exceptions=True)
78+
self.vis = visdom.Visdom(server=opt.display_server, port=opt.display_port, env=opt.display_env)
79+
if not self.vis.check_connection():
80+
self.create_visdom_connections()
7981

8082
if self.use_html: # create an HTML object at <checkpoints_dir>/web/; images will be saved under <checkpoints_dir>/web/images/
8183
self.web_dir = os.path.join(opt.checkpoints_dir, opt.name, 'web')
@@ -148,11 +150,14 @@ def display_current_results(self, visuals, epoch, save_result):
148150

149151
else: # show each image in a separate visdom panel;
150152
idx = 1
151-
for label, image in visuals.items():
152-
image_numpy = util.tensor2im(image)
153-
self.vis.image(image_numpy.transpose([2, 0, 1]), opts=dict(title=label),
154-
win=self.display_id + idx)
155-
idx += 1
153+
try:
154+
for label, image in visuals.items():
155+
image_numpy = util.tensor2im(image)
156+
self.vis.image(image_numpy.transpose([2, 0, 1]), opts=dict(title=label),
157+
win=self.display_id + idx)
158+
idx += 1
159+
except VisdomExceptionBase:
160+
self.create_visdom_connections()
156161

157162
if self.use_html and (save_result or not self.saved): # save images to an HTML file if they haven't been saved.
158163
self.saved = True

0 commit comments

Comments
 (0)