Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ def get_current_visuals(self):

def get_current_losses(self):
"""Return traning losses / errors. simple.py will print out these errors on console, and save them to a file"""
errors_ret = OrderedDict()
for name in self.loss_names:
if isinstance(name, str):
errors_ret[name] = float(getattr(self, 'loss_' + name)) # float(...) works for both scalar tensor and float number
return errors_ret
errors_ret = OrderedDict()
for name in self.loss_names:
if isinstance(name, str):
loss_value = getattr(self, 'loss_' + name)
if isinstance(loss_value, torch.Tensor):
# detach() avoids inadvertently keeping autograd history when converting tensors to scalars
errors_ret[name] = loss_value.detach().item()
else:
errors_ret[name] = float(loss_value)
return errors_ret

def save_networks(self, epoch):
"""Save all the networks to the disk.
Expand Down