Skip to content

Commit d5cfa4d

Browse files
committed
2 parents f27da7d + 4eaf9e4 commit d5cfa4d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

models/base_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(self, opt):
4141
self.visual_names = []
4242
self.optimizers = []
4343
self.image_paths = []
44+
self.metric = 0 # used for learning rate policy 'plateau'
4445

4546
@staticmethod
4647
def modify_commandline_options(parser, is_train):
@@ -115,7 +116,7 @@ def get_image_paths(self):
115116
def update_learning_rate(self):
116117
"""Update learning rates for all the networks; called at the end of every epoch"""
117118
for scheduler in self.schedulers:
118-
scheduler.step()
119+
scheduler.step(self.metric)
119120
lr = self.optimizers[0].param_groups[0]['lr']
120121
print('learning rate = %.7f' % lr)
121122

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)