Ignite: Improve metrics docs: 2 types of API

Created on 1 Jan 2021  路  5Comments  路  Source: pytorch/ignite

馃殌 Feature

Following https://github.com/pytorch/ignite/issues/1538 it would be nice to explicitly mention here that there are 2 types of API :

  • using metric with Engine
  • using metric's reset/update/compute

and give examples.

docs help wanted metrics

All 5 comments

@vfdev-5 I am familiar with .attach() method. For reset/update/compute, the correct way is like this (computing epoch-wise)?

precision = Precision()
precision.attach(engine, 'precision')
@engine.on(Events.EPOCH_STARTED)
def reset():
    precision.reset()

def process_fn(e, b):
    ...
    precision.update((pred, target))

@engine.on(Events.EPOCH_COMPLETED)
def compute():
    precision.compute()

We have introduced MetricUsage to do this. See https://github.com/pytorch/ignite/blob/5ceacbb3ccea433317df2776556bd4a08d0a923d/ignite/metrics/metric.py#L52

The doc is here : https://pytorch.org/ignite/metrics.html#metrics-and-its-usages

The relevant PR is #979

HTH

@ydcjeff yes, the idea is to show how to use reset/update/compute API without relation to the engine:

precision = Precision()

precision.update((pred1, target1))
precision.update((pred2, target2))
precision.update((pred3, target3))

print("Precision: ", precision.compute())

precision.reset()
precision.update((pred1, target1))
precision.update((pred2, target2))
precision.update((pred3, target3))
print("Precision: ", precision.compute())

@ydcjeff would you like to send a PR to fix this issue ?

I can only send in next weeks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheCodez picture TheCodez  路  3Comments

samarth-robo picture samarth-robo  路  3Comments

kilsenp picture kilsenp  路  3Comments

UjwalKandi picture UjwalKandi  路  3Comments

elanmart picture elanmart  路  4Comments