Skip to content

Commit

Permalink
Create loss tracker entry if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
mdw771 committed May 16, 2024
1 parent 5a395f9 commit fe8a051
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generic_trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def update_losses(self, losses, type='loss', epoch=None, lr=None):
:return: bool. If type is "val_loss" and the given validation loss is lower than the current best validation
loss, return True.
"""
if type not in self.keys():
self[type] = []
self[type].append(losses[0])

if epoch is None:
Expand All @@ -110,6 +112,8 @@ def update_losses(self, losses, type='loss', epoch=None, lr=None):
self['lrs'].append(lr)

for i, pred_name in enumerate(self.pred_names):
if '{}_{}'.format(type, pred_name) not in self.keys():
self['{}_{}'.format(type, pred_name)] = []
self['{}_{}'.format(type, pred_name)].append(losses[i + 1])
if type == 'val_loss' and losses[0] < self['best_val_loss']:
self['best_val_loss'] = losses[0]
Expand Down Expand Up @@ -211,6 +215,8 @@ def update_accuracy_history(self, acc_dict, type='train'):
:param type: str. Can be 'train' or 'val'.
"""
for i, pred_name in enumerate(self.pred_names):
if '{}_acc_{}'.format(type, pred_name) not in self.keys():
self['{}_acc_{}'.format(type, pred_name)] = []
self['{}_acc_{}'.format(type, pred_name)].append(acc_dict[pred_name])

def sync_classification_preds_and_labels_across_ranks(self):
Expand Down

0 comments on commit fe8a051

Please sign in to comment.