diff options
author | 2017-11-30 16:37:11 -0800 | |
---|---|---|
committer | 2017-11-30 16:41:01 -0800 | |
commit | b2db981a6731e978453862a73dab892bc674db68 (patch) | |
tree | c11a7c4038e2595268113c2859c1d0d3072ede4f /tensorflow/examples/how_tos | |
parent | 0438ac79bdb503ed267bec2146e7136ac8e99ff9 (diff) |
Merge changes from github.
PiperOrigin-RevId: 177526301
Diffstat (limited to 'tensorflow/examples/how_tos')
-rw-r--r-- | tensorflow/examples/how_tos/reading_data/convert_to_records.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/tensorflow/examples/how_tos/reading_data/convert_to_records.py b/tensorflow/examples/how_tos/reading_data/convert_to_records.py index d14c1f7c86..c89e839563 100644 --- a/tensorflow/examples/how_tos/reading_data/convert_to_records.py +++ b/tensorflow/examples/how_tos/reading_data/convert_to_records.py @@ -52,17 +52,19 @@ def convert_to(data_set, name): filename = os.path.join(FLAGS.directory, name + '.tfrecords') print('Writing', filename) - writer = tf.python_io.TFRecordWriter(filename) - for index in range(num_examples): - image_raw = images[index].tostring() - example = tf.train.Example(features=tf.train.Features(feature={ - 'height': _int64_feature(rows), - 'width': _int64_feature(cols), - 'depth': _int64_feature(depth), - 'label': _int64_feature(int(labels[index])), - 'image_raw': _bytes_feature(image_raw)})) - writer.write(example.SerializeToString()) - writer.close() + with tf.python_io.TFRecordWriter(filename) as writer: + for index in range(num_examples): + image_raw = images[index].tostring() + example = tf.train.Example( + features=tf.train.Features( + feature={ + 'height': _int64_feature(rows), + 'width': _int64_feature(cols), + 'depth': _int64_feature(depth), + 'label': _int64_feature(int(labels[index])), + 'image_raw': _bytes_feature(image_raw) + })) + writer.write(example.SerializeToString()) def main(unused_argv): |