Skip to content

Commit d4aa1a2

Browse files
committed
Fix string to bytes conversion in deeplab data input. tensorflow#3885
The current code does not work in py2 since the input string could contain unicode string, and default encoding in ASCII in py2. Change the method to only do encode() which convert string to byte array when running python3.
1 parent 310f70d commit d4aa1a2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

research/deeplab/datasets/build_data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
image/segmentation/class/format: semantic segmentation file format.
3131
"""
3232
import collections
33+
import six
3334
import tensorflow as tf
3435

3536
FLAGS = tf.app.flags.FLAGS
@@ -126,7 +127,7 @@ def _bytes_list_feature(values):
126127
A TF-Feature.
127128
"""
128129
def norm2bytes(value):
129-
return value.encode() if isinstance(value, str) else value
130+
return value.encode() if isinstance(value, str) and six.PY3 else value
130131

131132
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[norm2bytes(values)]))
132133

0 commit comments

Comments
 (0)