Prevent from calling compute
#2904
-
|
The |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I understand that the automatic call to metric = YourMetric(...)
for batch in dataloader:
metric.update(preds, targets) # just update state
final_result = metric.compute() # call compute once after epochThis approach avoids repeated calls to |
Beta Was this translation helpful? Give feedback.
I understand that the automatic call to
computeinsidemetric(preds, targets)can be costly and you want to avoid it until the end of the evaluation epoch.By design, TorchMetrics updates internal state with the call to the metric and calls
computeto get a final value. To achieve your goal, you should avoid using the metric as a callable during every batch. Instead, call the.update(preds, targets)method to update the metric state without triggering computation, then call.compute()only once when you need the final result (e.g., at the end of the epoch).