Skip to content

561 497 Provide metrics base APIs#2314

Merged
Nic-Ma merged 23 commits intodevfrom
feature/561-metrics-api
Jun 11, 2021
Merged

561 497 Provide metrics base APIs#2314
Nic-Ma merged 23 commits intodevfrom
feature/561-metrics-api

Conversation

@Nic-Ma
Copy link
Copy Markdown
Contributor

@Nic-Ma Nic-Ma commented Jun 6, 2021

Fixes #561
Part of #497
Closes #303
Closes #565

Description

This PR added base class for the metrics.
And add support for list of channel-first Tensor.
It's a breaking change.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

* [DLMED] add metric base class

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] update meandice and auc

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] extract reduce API

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] update regression metrics

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] update all the other metrics and enhance unit tests

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] add doc-strings and update unit tests

Signed-off-by: Nic Ma <[email protected]>

* [MONAI] python code formatting

Signed-off-by: monai-bot <[email protected]>

* [DLMED] fix flake8 issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix pytype issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix all the mypy issues

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix integration test

Signed-off-by: Nic Ma <[email protected]>

* [MONAI] python code formatting

Signed-off-by: monai-bot <[email protected]>

* [DLMED] fix flake8 issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix pytype issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] add more sanity check

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] update according to comments

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] update according to Yiheng's comments

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] update according to Wenqi's comments

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] change to "_compute()" and "aggregate()"

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] add compute_list()

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix flake8 issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix flake8 issue

Signed-off-by: Nic Ma <[email protected]>

Co-authored-by: monai-bot <[email protected]>
Co-authored-by: Yiheng Wang <[email protected]>
@Nic-Ma Nic-Ma changed the title 561 497 Provide metrics base APIs (#2291) 561 497 Provide metrics base APIs Jun 6, 2021
@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 6, 2021

Hi @wyli ,

Thanks for providing the detection metrics example:
https://github.com/rafaelpadilla/Object-Detection-Metrics/blob/master/lib/Evaluator.py#L24
I checked the code and seems we can implement it based on this Metric, something like:

class PascalVOCMetric(Metric):
    def __init__(self, IOUThreshold=0.5, method="EveryPointInterpolation"):
        self.IOUThreshold = IOUThreshold
        self.method = method
        self._ groundtruths = []
        self._detections = []
        self._classes = []

    # here the args and arg type don't match base class
    def _compute(self, bb):
        if bb.getBBType() == BBType.GroundTruth:
            self._groundtruths.append([
                bb.getImageName(),
                bb.getClassId(), 1,
                bb.getAbsoluteBoundingBox(BBFormat.XYX2Y2)
            ])
        else:
            self._detections.append([
                bb.getImageName(),
                bb.getClassId(),
                bb.getConfidence(),
                bb.getAbsoluteBoundingBox(BBFormat.XYX2Y2)
            ])
        if bb.getClassId() not in classes:
            classes.append(bb.getClassId())

    def aggregate(self, data):
        # final metric computation progress

    def reset(self):
        self._ groundtruths = []
        self._detections = []
        self._classes = []

I got several questions with current Metric design:

  1. python doesn't support overload for different arg list, how to define the API for both the metrics with pred_y & y and the metrics with only pred_y? The data type of args may be also unknown. Can we define a API interface with uncertain length args? def __call__(...)?
  2. Although this PR doesn't include member variables in the Metric base class, I agree we should add a reset() API to unify the logic for member variables.
  3. Should we include the multi-gpus distributed syncing logic in Metric or put this task to the upper layer or let users to do it? I have a draft idea is to add a _sync(self, data) interface in Metric, will be called at the beginning of aggregate(), every metric class can implement the real _sync() logic for itself.
  4. Should we keep the Metric base class simple, and make several subclasses for different categories of metrics?

Thanks.

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Jun 7, 2021

This PR should try to close #303 #565 #561 with a lightweight solution, perhaps also try to be compatible with a few existing packages:

So, I think we can have reset and _sync API in a simple base class. could you finish this PR, and then we can get feedback from the working group.

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 8, 2021

Hi @wyli ,

Thanks for your sharing.
I investigated several other projects and got some ideas, let me try to update this PR ASAP.

Thanks.

Nic-Ma added 3 commits June 9, 2021 06:08
1. re-define base classes in 3 levels to make it more clear and flexible to extend
2. added self-contained variables in metrics to provide easier API
3. added reset() and sync() logic
4. added distributed data parallel logic for all the metrics

Signed-off-by: Nic Ma <[email protected]>
@Nic-Ma Nic-Ma force-pushed the feature/561-metrics-api branch from 6ffc74a to 8cc8e36 Compare June 9, 2021 08:04
@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 9, 2021

/black

monai-bot and others added 2 commits June 9, 2021 08:08
@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 9, 2021

/black

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 9, 2021

Hi @wyli @ericspod ,

I updated the PR based on your comments and some further investigation, could you please help review it again?

Thanks in advance.

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 9, 2021

/integration-test

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 9, 2021

/integration-test

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 10, 2021

/black

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 10, 2021

/integration-test

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 10, 2021

Hi @wyli ,

I have totally updated the PR based on the latest design, could you please help review it again?

Thanks in advance.

Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

thanks, please see some comments for the details. would be great to have some more docstrings in the base class, but we can also do that in follow up PRs

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 10, 2021

/black

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 10, 2021

/integration-test

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 10, 2021

Hi @wyli ,

Thanks for your review and comments.
I updated the PR based on your comments and enhanced the doc-string of base classes.
I can refine the doc-strings again according to future feedback from users and metrics working group.
Could you please help review it again?

Thanks.

@Nic-Ma Nic-Ma requested a review from wyli June 10, 2021 16:44
Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

thanks, just wanted to confirm that the use case of single machine multiprocesing is also covered by the design? I put detailed comments inline

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 11, 2021

/black

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Jun 11, 2021

/integration-test

@wyli wyli mentioned this pull request Jun 11, 2021
4 tasks
@wyli wyli enabled auto-merge (squash) June 11, 2021 09:19
Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

thanks!

@Nic-Ma Nic-Ma disabled auto-merge June 11, 2021 10:00
@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 11, 2021

/black

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Jun 11, 2021

/integration-test

@Nic-Ma Nic-Ma enabled auto-merge (squash) June 11, 2021 10:37
@Nic-Ma Nic-Ma merged commit 0c0d95d into dev Jun 11, 2021
@Nic-Ma Nic-Ma deleted the feature/561-metrics-api branch June 11, 2021 11:36
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.

Additional Metric Interface to compute quantities over dataset Evaluation subpackage and metric implementations

3 participants