Skip to content
Merged
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
23 changes: 22 additions & 1 deletion ignite/metrics/metrics_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class MetricsLambda(Metric):
else that will be fed to ``f`` as keyword arguments.

Examples:
.. code-block:: python

.. testcode::

precision = Precision(average=False)
recall = Recall(average=False)
Expand All @@ -41,6 +42,26 @@ def Fbeta(r, p, beta):
F3 = MetricsLambda(Fbeta, recall, precision, 3)
F4 = MetricsLambda(Fbeta, recall, precision, 4)

F1.attach(default_evaluator, "F1")
F2.attach(default_evaluator, "F2")
F3.attach(default_evaluator, "F3")
F4.attach(default_evaluator, "F4")

y_true = torch.Tensor([1, 0, 1, 0, 0, 1])
y_pred = torch.Tensor([1, 0, 1, 0, 1, 1])
state = default_evaluator.run([[y_pred, y_true]])
print(state.metrics["F1"])
print(state.metrics["F2"])
print(state.metrics["F3"])
print(state.metrics["F4"])

.. testoutput::

0.8571...
0.9375...
0.9677...
0.9807...

When check if the metric is attached, if one of its dependency
metrics is detached, the metric is considered detached too.

Expand Down