Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit fbb6f9a

Browse files
authored
Merge pull request #116 from schani/encoding-fixes
Encoding fixes
2 parents d877e69 + 1d73633 commit fbb6f9a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: tensor2tensor/data_generators/generator_utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ def to_example(dictionary):
4646
elif isinstance(v[0], float):
4747
features[k] = tf.train.Feature(float_list=tf.train.FloatList(value=v))
4848
elif isinstance(v[0], six.string_types):
49+
v = [bytes(x, 'utf-8') for x in v]
50+
features[k] = tf.train.Feature(bytes_list=tf.train.BytesList(value=v))
51+
elif isinstance(v[0], bytes):
4952
features[k] = tf.train.Feature(bytes_list=tf.train.BytesList(value=v))
5053
else:
51-
raise ValueError("Value is neither an int nor a float; v: %s type: %s" %
52-
(str(v[0]), str(type(v[0]))))
54+
raise ValueError("Value for %s is neither an int nor a float; v: %s type: %s" %
55+
(k, str(v[0]), str(type(v[0]))))
5356
return tf.train.Example(features=tf.train.Features(feature=features))
5457

5558

Diff for: tensor2tensor/data_generators/image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def image_generator(images, labels):
6868
yield {
6969
"image/encoded": [enc_string],
7070
"image/format": ["png"],
71-
"image/class/label": [label],
71+
"image/class/label": [int(label)],
7272
"image/height": [height],
7373
"image/width": [width]
7474
}

0 commit comments

Comments
 (0)