Skip to content

Commit 4578af1

Browse files
authored
Update metrics.rst
1 parent e6ef77d commit 4578af1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/source/metrics.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ use the ``output_transform`` argument to transform it:
3838
metric.attach(engine, "accuracy")
3939
4040
41+
.. warning::
42+
43+
Please, be careful when using ``lambda`` functions to setup multiple ``output_transform`` for multiple metrics
44+
45+
.. code-block:: python
46+
47+
# Wrong
48+
# metrics_group = [Accuracy(output_transform=lambda output: output[name]) for name in names]
49+
# As lambda can not store `name` and all `output_transform` will use the last `name`
50+
51+
# A correct way. For example, using functools.partial
52+
from functools import partial
53+
54+
def ot_func(output, name):
55+
return output[name]
56+
57+
metrics_group = [Accuracy(output_transform=partial(ot_func, name=name)) for name in names]
58+
59+
For more details, see `here <https://discuss.pytorch.org/t/evaluate-multiple-models-with-one-evaluator-results-weird-metrics/96695>`_
60+
4161
.. Note ::
4262
4363
Most of implemented metrics are adapted to distributed computations and reduce their internal states across supported

0 commit comments

Comments
 (0)