From 603c9be87e3503a20d7430df1dfbd0e02659ce52 Mon Sep 17 00:00:00 2001 From: seilmast Date: Mon, 24 Feb 2025 09:13:04 +0100 Subject: [PATCH 1/2] Fixed a small bug in metric wrapper --- CollaborativeCoding/load_metric.py | 1 + CollaborativeCoding/metrics/EntropyPred.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CollaborativeCoding/load_metric.py b/CollaborativeCoding/load_metric.py index c47a02a..002260c 100644 --- a/CollaborativeCoding/load_metric.py +++ b/CollaborativeCoding/load_metric.py @@ -79,6 +79,7 @@ def _get_metric(self, key): raise ValueError(f"Metric {key} not supported") def __call__(self, y_true, y_pred): + y_true, y_pred = y_true.detach().cpu(), y_pred.detach().cpu() for key in self.metrics: self.metrics[key](y_true, y_pred) diff --git a/CollaborativeCoding/metrics/EntropyPred.py b/CollaborativeCoding/metrics/EntropyPred.py index b77e8d7..7626962 100644 --- a/CollaborativeCoding/metrics/EntropyPred.py +++ b/CollaborativeCoding/metrics/EntropyPred.py @@ -36,7 +36,6 @@ def __call__(self, y_true: th.Tensor, y_logits: th.Tensor): assert y_logits.size(-1) == self.num_classes, ( f"y_logit class length: {y_logits.size(-1)}, expected: {self.num_classes}" ) - y_pred = nn.Softmax(dim=1)(y_logits) print(f"y_pred: {y_pred}") entropy_values = entropy(y_pred, axis=1) From bc1dd7a0aed7cbf5d009f899dbce31a7a3a0951a Mon Sep 17 00:00:00 2001 From: seilmast Date: Mon, 24 Feb 2025 09:25:29 +0100 Subject: [PATCH 2/2] Removed prints from entropy call func --- CollaborativeCoding/metrics/EntropyPred.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/CollaborativeCoding/metrics/EntropyPred.py b/CollaborativeCoding/metrics/EntropyPred.py index 7626962..9338f44 100644 --- a/CollaborativeCoding/metrics/EntropyPred.py +++ b/CollaborativeCoding/metrics/EntropyPred.py @@ -37,14 +37,12 @@ def __call__(self, y_true: th.Tensor, y_logits: th.Tensor): f"y_logit class length: {y_logits.size(-1)}, expected: {self.num_classes}" ) y_pred = nn.Softmax(dim=1)(y_logits) - print(f"y_pred: {y_pred}") entropy_values = entropy(y_pred, axis=1) entropy_values = th.from_numpy(entropy_values) # Fix numerical errors for perfect guesses entropy_values[entropy_values == th.inf] = 0 entropy_values = th.nan_to_num(entropy_values) - print(f"Entropy Values: {entropy_values}") for sample in entropy_values: self.stored_entropy_values.append(sample.item())