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
ModelZoo
ResNet50_tensorflow
Commits
800d1dbb
Commit
800d1dbb
authored
Oct 21, 2019
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Oct 21, 2019
Browse files
implements more container methods for ParamsDict
PiperOrigin-RevId: 275879424
parent
9ca59f8a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
official/modeling/hyperparams/params_dict.py
official/modeling/hyperparams/params_dict.py
+8
-0
official/modeling/hyperparams/params_dict_test.py
official/modeling/hyperparams/params_dict_test.py
+15
-0
No files found.
official/modeling/hyperparams/params_dict.py
View file @
800d1dbb
...
...
@@ -117,6 +117,14 @@ class ParamsDict(object):
raise
KeyError
(
'The key `{}` does not exist. '
.
format
(
k
))
return
self
.
__dict__
[
k
]
def
__contains__
(
self
,
key
):
"""Implements the membership test operator."""
return
key
in
self
.
__dict__
def
get
(
self
,
key
,
value
=
None
):
"""Accesses through built-in dictionary get method."""
return
self
.
__dict__
.
get
(
key
,
value
)
def
override
(
self
,
override_params
,
is_strict
=
True
):
"""Override the ParamsDict with a set of given params.
...
...
official/modeling/hyperparams/params_dict_test.py
View file @
800d1dbb
...
...
@@ -69,6 +69,21 @@ class ParamsDictTest(tf.test.TestCase):
self
.
assertEqual
(
params
.
b
,
2
)
self
.
assertEqual
(
params
.
c
,
None
)
def
test_contains
(
self
):
params
=
params_dict
.
ParamsDict
()
params
.
override
(
{
'a'
:
'aa'
},
is_strict
=
False
)
self
.
assertIn
(
'a'
,
params
)
self
.
assertNotIn
(
'b'
,
params
)
def
test_get
(
self
):
params
=
params_dict
.
ParamsDict
()
params
.
override
(
{
'a'
:
'aa'
},
is_strict
=
False
)
self
.
assertEqual
(
params
.
get
(
'a'
),
'aa'
)
self
.
assertEqual
(
params
.
get
(
'b'
,
2
),
2
)
self
.
assertEqual
(
params
.
get
(
'b'
),
None
)
def
test_override_is_strict_true
(
self
):
params
=
params_dict
.
ParamsDict
(
{
'a'
:
'aa'
,
'b'
:
2
,
'c'
:
{
'c1'
:
'cc'
,
'c2'
:
20
}})
...
...
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