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
1ebd7ea6
Unverified
Commit
1ebd7ea6
authored
Jul 02, 2020
by
Jintao Lin
Committed by
GitHub
Jul 02, 2020
Browse files
add unittest for set_random_seed (#376)
parent
0970ae94
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
mmcv/runner/__init__.py
mmcv/runner/__init__.py
+2
-2
tests/test_runner/test_utils.py
tests/test_runner/test_utils.py
+28
-0
No files found.
mmcv/runner/__init__.py
View file @
1ebd7ea6
...
...
@@ -14,7 +14,7 @@ from .optimizer import (OPTIMIZER_BUILDERS, OPTIMIZERS,
DefaultOptimizerConstructor
,
build_optimizer
,
build_optimizer_constructor
)
from
.priority
import
Priority
,
get_priority
from
.utils
import
get_host_info
,
get_time_str
,
obj_from_dict
from
.utils
import
get_host_info
,
get_time_str
,
obj_from_dict
,
set_random_seed
__all__
=
[
'BaseRunner'
,
'Runner'
,
'EpochBasedRunner'
,
'IterBasedRunner'
,
'LogBuffer'
,
...
...
@@ -27,5 +27,5 @@ __all__ = [
'obj_from_dict'
,
'init_dist'
,
'get_dist_info'
,
'master_only'
,
'OPTIMIZER_BUILDERS'
,
'OPTIMIZERS'
,
'DefaultOptimizerConstructor'
,
'build_optimizer'
,
'build_optimizer_constructor'
,
'IterLoader'
,
'IterBasedRunner'
'IterBasedRunner'
,
'set_random_seed'
]
tests/test_runner/test_utils.py
0 → 100644
View file @
1ebd7ea6
import
os
import
random
import
numpy
as
np
import
torch
from
mmcv.runner
import
set_random_seed
def
test_set_random_seed
():
set_random_seed
(
0
)
a_random
=
random
.
randint
(
0
,
10
)
a_np_random
=
np
.
random
.
rand
(
2
,
2
)
a_torch_random
=
torch
.
rand
(
2
,
2
)
assert
torch
.
backends
.
cudnn
.
deterministic
is
False
assert
torch
.
backends
.
cudnn
.
benchmark
is
False
assert
os
.
environ
[
'PYTHONHASHSEED'
]
==
str
(
0
)
set_random_seed
(
0
,
True
)
b_random
=
random
.
randint
(
0
,
10
)
b_np_random
=
np
.
random
.
rand
(
2
,
2
)
b_torch_random
=
torch
.
rand
(
2
,
2
)
assert
torch
.
backends
.
cudnn
.
deterministic
is
True
assert
torch
.
backends
.
cudnn
.
benchmark
is
False
assert
a_random
==
b_random
assert
np
.
equal
(
a_np_random
,
b_np_random
).
all
()
assert
torch
.
equal
(
a_torch_random
,
b_torch_random
)
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