-
Notifications
You must be signed in to change notification settings - Fork 284
Decoupling metrics from benchmark to allow different kinds of forward process #14
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
Merged
fengyuentau
merged 2 commits into
opencv:master
from
fengyuentau:benchmark_framework_decoupling
Nov 9, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| numpy==1.21.2 | ||
| numpy | ||
| opencv-python==4.5.4.58 | ||
| tqdm | ||
| pyyaml | ||
| requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from .factory import (METRICS, DATALOADERS) | ||
| from .metrics import * | ||
|
|
||
| __all__ = ['METRICS', 'DATALOADERS'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class Registery: | ||
| def __init__(self, name): | ||
| self._name = name | ||
| self._dict = dict() | ||
|
|
||
| def get(self, key): | ||
| return self._dict[key] | ||
|
|
||
| def register(self, item): | ||
| self._dict[item.__name__] = item | ||
|
|
||
| METRICS = Registery('Metrics') | ||
| DATALOADERS = Registery('DataLoaders') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from .base import Base | ||
| from .detection import Detection | ||
| from .recognition import Recognition | ||
|
|
||
| __all__ = ['Base', 'Detection', 'Recognition'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import cv2 as cv | ||
|
|
||
| from .base_metric import BaseMetric | ||
| from ..factory import METRICS | ||
|
|
||
| @METRICS.register | ||
| class Base(BaseMetric): | ||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) | ||
|
|
||
| def forward(self, model, *args, **kwargs): | ||
| img = args[0] | ||
| if not self._sizes: | ||
| h, w, _ = img.shape | ||
| self._sizes.append([w, h]) | ||
|
|
||
| results = dict() | ||
| self._timer.reset() | ||
| for size in self._sizes: | ||
| input_data = cv.resize(img, size) | ||
| for _ in range(self._warmup): | ||
| model.infer(input_data) | ||
| for _ in range(self._repeat): | ||
| self._timer.start() | ||
| model.infer(input_data) | ||
| self._timer.stop() | ||
| results[str(size)] = self._getResult() | ||
|
|
||
| return results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import cv2 as cv | ||
|
|
||
| from ..timer import Timer | ||
|
|
||
| class BaseMetric: | ||
| def __init__(self, **kwargs): | ||
| self._sizes = kwargs.pop('sizes', None) | ||
| if self._sizes is None: | ||
| self._sizes = [] | ||
| self._warmup = kwargs.pop('warmup', 3) | ||
| self._repeat = kwargs.pop('repeat', 10) | ||
| self._reduction = kwargs.pop('reduction', 'median') | ||
|
|
||
| self._timer = Timer() | ||
|
|
||
| def _calcMedian(self, records): | ||
| ''' Return the median of records | ||
| ''' | ||
| l = len(records) | ||
| mid = int(l / 2) | ||
| if l % 2 == 0: | ||
| return (records[mid] + records[mid - 1]) / 2 | ||
| else: | ||
| return records[mid] | ||
|
|
||
| def _calcGMean(self, records, drop_largest=3): | ||
| ''' Return the geometric mean of records after drop the first drop_largest | ||
| ''' | ||
| l = len(records) | ||
| if l <= drop_largest: | ||
| print('len(records)({}) <= drop_largest({}), stop dropping.'.format(l, drop_largest)) | ||
| records_sorted = sorted(records, reverse=True) | ||
| return sum(records_sorted[drop_largest:]) / (l - drop_largest) | ||
|
|
||
| def _getResult(self): | ||
| records = self._timer.getRecords() | ||
| if self._reduction == 'median': | ||
| return self._calcMedian(records) | ||
| elif self._reduction == 'gmean': | ||
| return self._calcGMean(records) | ||
| else: | ||
| raise NotImplementedError('Reduction {} is not supported'.format(self._reduction)) | ||
|
|
||
| def getReduction(self): | ||
| return self._reduction | ||
|
|
||
| def forward(self, model, *args, **kwargs): | ||
| raise NotImplementedError('Not implemented') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fengyuentau how do you define the suffix? Isn't QRCode models trained quite some time ago?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suffix is the time I uploaded to zoo. Previous was wrong.