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
f6437667
Commit
f6437667
authored
Jul 20, 2018
by
Chris Shallue
Committed by
Christopher Shallue
Oct 16, 2018
Browse files
Add bytes_encoding parameter to set_feature().
PiperOrigin-RevId: 205427760
parent
8793267f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
research/astronet/astronet/util/BUILD
research/astronet/astronet/util/BUILD
+1
-0
research/astronet/astronet/util/example_util.py
research/astronet/astronet/util/example_util.py
+14
-4
No files found.
research/astronet/astronet/util/BUILD
View file @
f6437667
...
@@ -47,6 +47,7 @@ py_library(
...
@@ -47,6 +47,7 @@ py_library(
name
=
"example_util"
,
name
=
"example_util"
,
srcs
=
[
"example_util.py"
],
srcs
=
[
"example_util.py"
],
srcs_version
=
"PY2AND3"
,
srcs_version
=
"PY2AND3"
,
visibility
=
[
"//visibility:public"
],
)
)
py_test
(
py_test
(
...
...
research/astronet/astronet/util/example_util.py
View file @
f6437667
...
@@ -79,7 +79,12 @@ def _infer_kind(value):
...
@@ -79,7 +79,12 @@ def _infer_kind(value):
return
"bytes_list"
return
"bytes_list"
def
set_feature
(
ex
,
name
,
value
,
kind
=
None
,
allow_overwrite
=
False
):
def
set_feature
(
ex
,
name
,
value
,
kind
=
None
,
allow_overwrite
=
False
,
bytes_encoding
=
"latin-1"
):
"""Sets a feature value in a tf.train.Example.
"""Sets a feature value in a tf.train.Example.
Args:
Args:
...
@@ -89,6 +94,7 @@ def set_feature(ex, name, value, kind=None, allow_overwrite=False):
...
@@ -89,6 +94,7 @@ def set_feature(ex, name, value, kind=None, allow_overwrite=False):
kind: Optional: one of 'bytes_list', 'float_list', 'int64_list'. Inferred if
kind: Optional: one of 'bytes_list', 'float_list', 'int64_list'. Inferred if
not specified.
not specified.
allow_overwrite: Whether to overwrite the existing value of the feature.
allow_overwrite: Whether to overwrite the existing value of the feature.
bytes_encoding: Codec for encoding strings when kind = 'bytes_list'.
Raises:
Raises:
ValueError: If `allow_overwrite` is False and the feature already exists, or
ValueError: If `allow_overwrite` is False and the feature already exists, or
...
@@ -105,7 +111,7 @@ def set_feature(ex, name, value, kind=None, allow_overwrite=False):
...
@@ -105,7 +111,7 @@ def set_feature(ex, name, value, kind=None, allow_overwrite=False):
kind
=
_infer_kind
(
value
)
kind
=
_infer_kind
(
value
)
if
kind
==
"bytes_list"
:
if
kind
==
"bytes_list"
:
value
=
[
str
(
v
).
encode
(
"latin-1"
)
for
v
in
value
]
value
=
[
str
(
v
).
encode
(
bytes_encoding
)
for
v
in
value
]
elif
kind
==
"float_list"
:
elif
kind
==
"float_list"
:
value
=
[
float
(
v
)
for
v
in
value
]
value
=
[
float
(
v
)
for
v
in
value
]
elif
kind
==
"int64_list"
:
elif
kind
==
"int64_list"
:
...
@@ -121,9 +127,13 @@ def set_float_feature(ex, name, value, allow_overwrite=False):
...
@@ -121,9 +127,13 @@ def set_float_feature(ex, name, value, allow_overwrite=False):
set_feature
(
ex
,
name
,
value
,
"float_list"
,
allow_overwrite
)
set_feature
(
ex
,
name
,
value
,
"float_list"
,
allow_overwrite
)
def
set_bytes_feature
(
ex
,
name
,
value
,
allow_overwrite
=
False
):
def
set_bytes_feature
(
ex
,
name
,
value
,
allow_overwrite
=
False
,
bytes_encoding
=
"latin-1"
):
"""Sets the value of a bytes feature in a tf.train.Example."""
"""Sets the value of a bytes feature in a tf.train.Example."""
set_feature
(
ex
,
name
,
value
,
"bytes_list"
,
allow_overwrite
)
set_feature
(
ex
,
name
,
value
,
"bytes_list"
,
allow_overwrite
,
bytes_encoding
)
def
set_int64_feature
(
ex
,
name
,
value
,
allow_overwrite
=
False
):
def
set_int64_feature
(
ex
,
name
,
value
,
allow_overwrite
=
False
):
...
...
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