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
e9e6d17c
Commit
e9e6d17c
authored
May 07, 2020
by
A. Unique TensorFlower
Browse files
Support constant argument in restriction checking in params_dict.
PiperOrigin-RevId: 310431197
parent
b39ce6bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
official/modeling/hyperparams/params_dict.py
official/modeling/hyperparams/params_dict.py
+18
-5
official/modeling/hyperparams/params_dict_test.py
official/modeling/hyperparams/params_dict_test.py
+8
-0
No files found.
official/modeling/hyperparams/params_dict.py
View file @
e9e6d17c
...
...
@@ -42,6 +42,10 @@ _PARAM_RE = re.compile(r"""
\[[^\]]*\])) # list of values
($|,\s*)"""
,
re
.
VERBOSE
)
# pylint: disable=anomalous-backslash-in-string
_CONST_VALUE_RE
=
re
.
compile
(
'(\d.*|-\d.*|None)'
)
# pylint: enable=anomalous-backslash-in-string
class
ParamsDict
(
object
):
"""A hyperparameter container class."""
...
...
@@ -239,11 +243,20 @@ class ParamsDict(object):
ValueError: if the restriction defined in the string is not supported.
"""
def
_get_kv
(
dotted_string
,
params_dict
):
tokenized_params
=
dotted_string
.
split
(
'.'
)
v
=
params_dict
for
t
in
tokenized_params
:
v
=
v
[
t
]
return
tokenized_params
[
-
1
],
v
"""Get keys and values indicated by dotted_string."""
if
_CONST_VALUE_RE
.
match
(
dotted_string
)
is
not
None
:
const_str
=
dotted_string
if
const_str
==
'None'
:
constant
=
None
else
:
constant
=
float
(
const_str
)
return
None
,
constant
else
:
tokenized_params
=
dotted_string
.
split
(
'.'
)
v
=
params_dict
for
t
in
tokenized_params
:
v
=
v
[
t
]
return
tokenized_params
[
-
1
],
v
def
_get_kvs
(
tokens
,
params_dict
):
if
len
(
tokens
)
!=
2
:
...
...
official/modeling/hyperparams/params_dict_test.py
View file @
e9e6d17c
...
...
@@ -155,6 +155,14 @@ class ParamsDictTest(tf.test.TestCase):
with
self
.
assertRaises
(
KeyError
):
params
.
validate
()
# Valid restrictions with constant.
params
=
params_dict
.
ParamsDict
(
{
'a'
:
None
,
'c'
:
{
'a'
:
1
}},
[
'a == None'
,
'c.a == 1'
])
params
.
validate
()
with
self
.
assertRaises
(
KeyError
):
params
=
params_dict
.
ParamsDict
(
{
'a'
:
4
,
'c'
:
{
'a'
:
1
}},
[
'a == None'
,
'c.a == 1'
])
class
ParamsDictIOTest
(
tf
.
test
.
TestCase
):
...
...
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