MCPcopy Create free account
hub / github.com/AIRMEC/HECTOR / __call__

Method __call__

utils.py:127–155  ·  view source on GitHub ↗
(self, epoch, eval_loss, eval_cindex, eval_other_metrics, model, log_dir)

Source from the content-addressed store, hash-verified

125 self.saving_checkpoint = saving_checkpoint
126
127 def __call__(self, epoch, eval_loss, eval_cindex, eval_other_metrics, model, log_dir):
128
129 loss_score = -eval_loss
130 CI_score = eval_cindex
131 metrics_score = eval_other_metrics
132
133 # Save model at epoch 0 and starts monitoring.
134 if self.best_loss_score is None:
135 self._update_loss_scores(loss_score, eval_loss, epoch)
136 self._update_metrics_scores(CI_score, metrics_score, epoch)
137 #self.save_checkpoint(model, log_dir, epoch)
138
139 # Eval loss starts increasing. Recommend running early stopping on the loss.
140 elif loss_score < self.best_loss_score:
141 self.counter += 1
142 print(f'Evaluation loss does not decrease : Starting Early stopping counter {self.counter} out of {self.patience}')
143 if self.counter >= self.patience and epoch > self.min_epochs:
144 self.early_stop = True
145 # Eval loss keeps decreasing.
146 else:
147 print(f'Epoch {epoch} validation loss decreased ({self.eval_loss_min:.6f} --> {eval_loss:.6f})')
148 self._update_loss_scores(loss_score, eval_loss, epoch)
149 #self.save_checkpoint(model, log_dir, epoch)
150 self.counter = 0
151
152 # We may have a tiny lag between min loss and the best C-index. With the patience and early stop, it is fine but better to save based on highest C-index too.
153 if CI_score > self.best_CI_score:
154 self._update_metrics_scores(CI_score, metrics_score, epoch)
155 #self.save_checkpoint(model, log_dir, epoch)
156
157 def save_checkpoint(self, model, log_dir, epoch):
158 filepath = os.path.join(log_dir, f"{epoch}_checkpoint.pt")

Callers

nothing calls this directly

Calls 2

_update_loss_scoresMethod · 0.95

Tested by

no test coverage detected