File tree 1 file changed +12
-1
lines changed
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 9
9
import struct
10
10
import sys
11
11
12
+ import six
12
13
import tensorflow as tf
13
14
from tensorflow .core .example import example_pb2
14
15
@@ -32,7 +33,15 @@ def _binary_to_text():
32
33
tf_example = example_pb2 .Example .FromString (tf_example_str )
33
34
examples = []
34
35
for key in tf_example .features .feature :
35
- examples .append ('%s=%s' % (key , tf_example .features .feature [key ].bytes_list .value [0 ]))
36
+ value = tf_example .features .feature [key ].bytes_list .value [0 ]
37
+
38
+ # Convert to byte strings (PY2) or unicode strings (PY3)
39
+ if six .PY2 :
40
+ key = key .encode ('utf-8' )
41
+ else :
42
+ value = value .decode ('utf-8' )
43
+
44
+ examples .append ('%s=%s' % (key , value ))
36
45
writer .write ('%s\n ' % '\t ' .join (examples ))
37
46
reader .close ()
38
47
writer .close ()
@@ -45,6 +54,8 @@ def _text_to_binary():
45
54
tf_example = example_pb2 .Example ()
46
55
for feature in inp .strip ().split ('\t ' ):
47
56
(k , v ) = feature .split ('=' )
57
+ if six .PY3 :
58
+ v = v .encode ('utf-8' )
48
59
tf_example .features .feature [k ].bytes_list .value .extend ([v ])
49
60
tf_example_str = tf_example .SerializeToString ()
50
61
str_len = len (tf_example_str )
You can’t perform that action at this time.
0 commit comments