Skip to content

Commit

Permalink
doctest for epoch metric (#2351)
Browse files Browse the repository at this point in the history
Co-authored-by: Desroziers <sylvain.desroziers@michelin.com>
  • Loading branch information
sdesrozis and Desroziers authored Dec 11, 2021
1 parent 4597bbc commit b20677f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ignite/metrics/epoch_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ class EpochMetric(Metric):
Default, True.
device: optional device specification for internal storage.
Example:
.. testcode::
def mse_fn(y_preds, y_targets):
return torch.mean(((y_preds - y_targets.type_as(y_preds)) ** 2)).item()
metric = EpochMetric(mse_fn)
metric.attach(default_evaluator, "mse")
y_true = torch.Tensor([0, 1, 2, 3, 4, 5])
y_pred = y_true * 0.75
state = default_evaluator.run([[y_pred, y_true]])
print(state.metrics["mse"])
.. testoutput::
0.5729...
Warnings:
EpochMetricWarning: User is warned that there are issues with ``compute_fn`` on a batch of data processed.
To disable the warning, set ``check_compute_fn=False``.
Expand Down

0 comments on commit b20677f

Please sign in to comment.