Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
72e13e6a
Unverified
Commit
72e13e6a
authored
Feb 20, 2021
by
Miao Zheng
Committed by
GitHub
Feb 20, 2021
Browse files
fix baserunner bug (#840)
* fix baserunner bug * add unit test * hooks type check
parent
7fa78e7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
mmcv/runner/base_runner.py
mmcv/runner/base_runner.py
+1
-1
tests/test_runner/test_runner.py
tests/test_runner/test_runner.py
+24
-0
No files found.
mmcv/runner/base_runner.py
View file @
72e13e6a
...
@@ -420,7 +420,7 @@ class BaseRunner(metaclass=ABCMeta):
...
@@ -420,7 +420,7 @@ class BaseRunner(metaclass=ABCMeta):
return
return
if
isinstance
(
timer_config
,
dict
):
if
isinstance
(
timer_config
,
dict
):
timer_config_
=
copy
.
deepcopy
(
timer_config
)
timer_config_
=
copy
.
deepcopy
(
timer_config
)
hook
=
mmcv
.
buid_from_cfg
(
timer_config_
,
HOOKS
)
hook
=
mmcv
.
bui
l
d_from_cfg
(
timer_config_
,
HOOKS
)
else
:
else
:
hook
=
timer_config
hook
=
timer_config
self
.
register_hook
(
hook
)
self
.
register_hook
(
hook
)
...
...
tests/test_runner/test_runner.py
View file @
72e13e6a
...
@@ -13,6 +13,7 @@ import torch.nn as nn
...
@@ -13,6 +13,7 @@ import torch.nn as nn
from
mmcv.parallel
import
MMDataParallel
from
mmcv.parallel
import
MMDataParallel
from
mmcv.runner
import
(
RUNNERS
,
EpochBasedRunner
,
IterBasedRunner
,
from
mmcv.runner
import
(
RUNNERS
,
EpochBasedRunner
,
IterBasedRunner
,
build_runner
)
build_runner
)
from
mmcv.runner.hooks
import
IterTimerHook
class
OldStyleModel
(
nn
.
Module
):
class
OldStyleModel
(
nn
.
Module
):
...
@@ -257,3 +258,26 @@ def test_build_lr_momentum_hook(runner_class):
...
@@ -257,3 +258,26 @@ def test_build_lr_momentum_hook(runner_class):
step_ratio_up
=
0.4
)
step_ratio_up
=
0.4
)
runner
.
register_momentum_hook
(
mom_config
)
runner
.
register_momentum_hook
(
mom_config
)
assert
len
(
runner
.
hooks
)
==
8
assert
len
(
runner
.
hooks
)
==
8
@
pytest
.
mark
.
parametrize
(
'runner_class'
,
RUNNERS
.
module_dict
.
values
())
def
test_register_timer_hook
(
runner_class
):
model
=
Model
()
runner
=
runner_class
(
model
=
model
,
logger
=
logging
.
getLogger
())
# test register None
timer_config
=
None
runner
.
register_timer_hook
(
timer_config
)
assert
len
(
runner
.
hooks
)
==
0
# test register IterTimerHook with config
timer_config
=
dict
(
type
=
'IterTimerHook'
)
runner
.
register_timer_hook
(
timer_config
)
assert
len
(
runner
.
hooks
)
==
1
assert
isinstance
(
runner
.
hooks
[
0
],
IterTimerHook
)
# test register IterTimerHook
timer_config
=
IterTimerHook
()
runner
.
register_timer_hook
(
timer_config
)
assert
len
(
runner
.
hooks
)
==
2
assert
isinstance
(
runner
.
hooks
[
1
],
IterTimerHook
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment