Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store returned metrics in variables prior to return statements. #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions metrics/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def stable_mean_dist_reduce_fn(state: torch.Tensor) -> torch.Tensor:
value=state[:, 0],
weight=state[:, 1],
)
return torch.stack([mean, weight_sum])
merged_accumulated_mean = torch.stack([mean, weight_sum])
return merged_accumulated_mean


class StableMean(torchmetrics.Metric):
Expand Down Expand Up @@ -94,4 +95,5 @@ def compute(self) -> torch.Tensor:
"""
Compute and return the accumulated mean.
"""
return self.mean_and_weight_sum[0]
accumulated_mean = self.mean_and_weight_sum[0]
return accumulated_mean
4 changes: 3 additions & 1 deletion metrics/auroc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,6 @@ def compute(self) -> torch.Tensor:
)

# Compute auroc with the weight set to 1/2 when positive & negative have identical scores.
return auroc_le - (auroc_le - auroc_lt) / 2.0
auroc = auroc_le - (auroc_le - auroc_lt) / 2.0
return auroc

6 changes: 4 additions & 2 deletions metrics/rce.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def _smooth(
label_smoothing: smoothing constant.
Returns: Smoothed values.
"""
return value * (1.0 - label_smoothing) + 0.5 * label_smoothing
smoothed_values = value * (1.0 - label_smoothing) + 0.5 * label_smoothing
return smoothed_values


def _binary_cross_entropy_with_clipping(
Expand Down Expand Up @@ -178,7 +179,8 @@ def compute(self) -> torch.Tensor:

pred_ce = self.binary_cross_entropy.compute()

return (1.0 - (pred_ce / baseline_ce)) * 100
rce = (1.0 - (pred_ce / baseline_ce)) * 100
return rce

def reset(self):
"""
Expand Down