Skip to content
New issue

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

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

Already on GitHub? # to your account

[Improvement] Modify default value of save_best #600

Merged
merged 3 commits into from
Feb 7, 2021

Conversation

irvingzhang0512
Copy link
Contributor

@irvingzhang0512 irvingzhang0512 commented Feb 5, 2021

Fix #599

@irvingzhang0512
Copy link
Contributor Author

irvingzhang0512 commented Feb 5, 2021

if save_best='auto', then we have to set self.rule manually.

def _init_rule(self, rule, key_indicator):
"""Initialize rule, key_indicator, comparison_func, and best score.
Args:
rule (str | None): Comparison rule for best score.
key_indicator (str | None): Key indicator to determine the
comparison rule.
"""
if rule not in self.rule_map and rule is not None:
raise KeyError(f'rule must be greater, less or None, '
f'but got {rule}.')
if rule is None:
if key_indicator != 'auto':
if any(key in key_indicator for key in self.greater_keys):
rule = 'greater'
elif any(key in key_indicator for key in self.less_keys):
rule = 'less'
else:
raise ValueError(f'Cannot infer the rule for key '
f'{key_indicator}, thus a specific rule '
f'must be specified.')
self.rule = rule
self.key_indicator = key_indicator
if self.rule is not None:
self.compare_func = self.rule_map[self.rule]

I'm a little confused about the codes. It seems that self.rule should not be None at all. Maybe we need to add assert for that self.rule is not None.

@dreamerlin Any suggestions?

@innerlee innerlee requested a review from dreamerlin February 5, 2021 14:55
@dreamerlin
Copy link
Collaborator

dreamerlin commented Feb 5, 2021

I guess you mean the case rule=None & save_best='auto. Actually in this case, self._init_rule will be called twice.

At first time:

if self.save_best is not None:
self.best_ckpt_path = None
self._init_rule(rule, self.save_best)

The result is: self.rule=None, self.key_indicator='auto', self.compare_func is not set

At second time:

if self.key_indicator == 'auto':
# infer from eval_results
self._init_rule(self.rule, list(eval_res.keys())[0])

This time, the key_indicator is not 'auto', and then the result: self.rule is not None but between 'greater' and 'less', self.key_indicator is not 'auto' and se;f.compare_func is determined.

@dreamerlin
Copy link
Collaborator

dreamerlin commented Feb 5, 2021

You may also need to change default value of DistvalHook. And since you are here, Could you also help to change the default of docstring ?

@irvingzhang0512
Copy link
Contributor Author

Thanks for your clarification. It turns out that test failure is caused by Mock. Tests, Docs & default values are updated.

BTW, do we still need The interval of EvalHook should be divisible by that of CheckpointHook in the docstring? I thought it was designed for symlink

@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #600 (b48afa7) into master (2f7368c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #600   +/-   ##
=======================================
  Coverage   84.31%   84.31%           
=======================================
  Files         124      124           
  Lines        8774     8774           
  Branches     1468     1468           
=======================================
  Hits         7398     7398           
  Misses       1019     1019           
  Partials      357      357           
Flag Coverage Δ
unittests 84.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmaction/core/evaluation/eval_hooks.py 86.09% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f7368c...3db17ed. Read the comment docs.

@dreamerlin
Copy link
Collaborator

Thanks for your clarification. It turns out that test failure is caused by Mock. Tests, Docs & default values are updated.

BTW, do we still need The interval of EvalHook should be divisible by that of CheckpointHook in the docstring? I thought it was designed for symlink

Yeah, it is outdated, thanks for your correction!

@innerlee innerlee merged commit 63c80cf into open-mmlab:master Feb 7, 2021
@irvingzhang0512 irvingzhang0512 deleted the save-best branch February 7, 2021 02:09
ZJU-lishuang added a commit to ZJU-lishuang/mmaction2 that referenced this pull request Feb 8, 2021
[Improvement] Modify default value of `save_best` (open-mmlab#600)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

About default value of save_best in EvalHook
3 participants