Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 874 : add custom events for Metrics #979

Merged
merged 59 commits into from May 18, 2020
Merged

Conversation

sdesrozis
Copy link
Contributor

@sdesrozis sdesrozis commented Apr 25, 2020

Fixes #874

Description:

Allow customization for Events of Metrics.

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@sdesrozis sdesrozis marked this pull request as draft April 25, 2020 20:32
@sdesrozis
Copy link
Contributor Author

@vfdev-5 thoughts on this draft ?

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Apr 25, 2020

We may have to take this comment into account for the usage : #644 (comment)

@sdesrozis
Copy link
Contributor Author

We may have to take this comment into account for the usage : #644 (comment)

Same issue??

@sdesrozis
Copy link
Contributor Author

sdesrozis commented Apr 26, 2020

@vfdev-5

Major refactoring

  • Add interface EngineMetric which defines methods used by Engine
  • Add functions attach, detach and is_attached external to Metric using Engine, MetricUsage and EngineMetric
  • MetricUsage moved from __init__ to attach, detach and is_attached (could simplify detach and is_attached)

The idea is to have Metric like an algorithm pluggable in any Engine wrt a MetricUsage. Today, attach, detach and is_attached are embedded in Metric but one could use external functions.

engine1 = ...
engine2 = ...

m = MyMetric()

# current API
m.attach(engine1, "m")
m.attach(engine2, "m", usage=BatchWise())

# possible API
attach(metric=m, engine=engine1, name="m")
attach(metric=m, engine=engine2, name="m", usage=BatchWise())

Thoughts ?

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Apr 26, 2020

@sdesrozis please, show an example of usage. For instance, I do not understand the need of another interface... Thanks

@sdesrozis
Copy link
Contributor Author

sdesrozis commented Apr 26, 2020

The idea is to have Metric like an algorithm with API to be plugged to engine but no reason to have the plug in the metric.

This is a separation of concerns.

However, this is just a draft :) The interface EngineMetric could be removed. The main point is to have MetricUsage at attachment.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Apr 26, 2020

@sdesrozis I'm not fan of "possible API", let's keep current API.
If I get it right, EngineMetric interface is only for "possible API" ?

@sdesrozis
Copy link
Contributor Author

@sdesrozis I'm not fan of "possible API", let's keep current API.

If I get it right, EngineMetric interface is only for "possible API" ?

Yes, I can remove it, no problem 😊

@sdesrozis
Copy link
Contributor Author

Removed

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Apr 26, 2020

@sdesrozis thanks ! What do you think about to enhance the following API by

engine1 = ...
engine2 = ...

m = MyMetric()

# current API
m.attach(engine1, "m")
m.attach(engine2, "m", usage="batch_wise")  # ~ BatchWise()
m.attach(engine2, "m", usage="epoch_wise")  # ~ EpochWise()

?

No need to import those classes.

@sdesrozis sdesrozis requested a review from vfdev-5 May 9, 2020 23:04
@vfdev-5
Copy link
Collaborator

vfdev-5 commented May 13, 2020

@sdesrozis code looks OK, documentation layout is not correct:

  • missing docs for "MetricUsage", "EpochWise", "BatchWise", "BatchFiltered"
  • missing indents renders badly docs, i'll comment out where.
    Please, try to render the docs locally and check it.

ignite/metrics/metric.py Outdated Show resolved Hide resolved
"""
Attaches current metric to provided engine. On the end of engine's run,
`engine.state.metrics` dictionary will contain computed metric's value under provided name.

Args:
engine (Engine): the engine to which the metric must be attached
name (str): the name of the metric to attach
usage (str or MetricUsage, optional): the usage of the metric. Valid string values should be
'epoch_wise' (default) or 'batch_wise'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing indent here

@@ -182,6 +293,8 @@ def detach(self, engine: Engine) -> None:

Args:
engine (Engine): the engine from which the metric must be detached
usage (str or MetricUsage, optional): the usage of the metric. Valid string values should be
'epoch_wise' (default) or 'batch_wise'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing indent here

ignite/metrics/metric.py Outdated Show resolved Hide resolved
@sdesrozis
Copy link
Contributor Author

sdesrozis commented May 13, 2020

@vfdev-5 thank you, I update soon :p

@sdesrozis
Copy link
Contributor Author

Doc done. Next, I would like to refactor a last thing after merge of fix for #1004 (if ok).

@sdesrozis sdesrozis requested a review from vfdev-5 May 18, 2020 08:27
Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good !

@vfdev-5 vfdev-5 merged commit 5d26c97 into pytorch:master May 18, 2020
@sdesrozis sdesrozis deleted the issue_874 branch May 18, 2020 12:40
@sdesrozis sdesrozis mentioned this pull request May 18, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom events for metrics update
5 participants