def data_to_tfrecord(images, labels, filename):
if os.path.isfile(filename):<EOL><INDENT>print("<STR_LIT>" % filename)<EOL>return<EOL><DEDENT>print("<STR_LIT>" % filename)<EOL>writer = tf.python_io.TFRecordWriter(filename)<EOL>for index, img in enumerate(images):<EOL><INDENT>img_raw = img.tobytes()<EOL>label = int(labels[index])<EOL>example = tf.train.Example(<EOL>features=tf.train.Features(<EOL>feature={<EOL>"<STR_LIT:label>": tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),<EOL>'<STR_LIT>': tf.train.Feature(bytes_list=tf.train.BytesList(value=[img_raw])),<EOL>}<EOL>)<EOL>)<EOL>writer.write(example.SerializeToString())  <EOL><DEDENT>writer.close()<EOL>
Save data into TFRecord.