From 4d588e12d8049b7275dfb9c8d935928e1994b555 Mon Sep 17 00:00:00 2001 From: gcroci2 Date: Tue, 24 Oct 2023 11:09:29 +0200 Subject: [PATCH] fix Trainer _eval method for cases in which there is a target attribute but no target values are present in the hdf5 file/s --- deeprank2/trainer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deeprank2/trainer.py b/deeprank2/trainer.py index 2afab715e..0a9a92892 100644 --- a/deeprank2/trainer.py +++ b/deeprank2/trainer.py @@ -748,6 +748,9 @@ def _eval( # pylint: disable=too-many-locals loss_ = loss_func(pred, y) count_predictions += pred.shape[0] sum_of_losses += loss_.detach().item() * pred.shape[0] + else: + target_vals = ['None'] * pred.shape[0] + eval_loss = 'None' # Get the outputs for export # Remember that non-linear activation is automatically applied in CrossEntropyLoss @@ -764,7 +767,7 @@ def _eval( # pylint: disable=too-many-locals if count_predictions > 0: eval_loss = sum_of_losses / count_predictions else: - eval_loss = 0.0 + eval_loss = 'None' self._output_exporters.process( pass_name, epoch_number, entry_names, outputs, target_vals, eval_loss)