码迷,mamicode.com
首页 > 其他好文 > 详细

TFRecord学习

时间:2017-12-30 00:59:46      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:imp   .bat   ali   als   import   shuff   time   文件   post   

# Author : Hellcat
# Time : 2017/12/30

import tensorflow as tf

example,label = features[‘i‘],features[‘j‘]

# 每个batch的中样例的个数
batch_size = 3
# 队列中样例的个数
capacity = 1000 + 3*batch_size

suffer = True
suffer_join = False
# batch操作实际代指的就是数据读取和预处理操作
if suffer is not True:
example_batch, label_batch = tf.train.batch(
[example,label],batch_size=batch_size,capacity=capacity)
elif suffer_join is True:
# 不同线程处理同一个文件
# 随机只存在文件内部数据读取的顺序
example_batch, label_batch = tf.train.shuffle_batch_join(
[example, label],batch_size=batch_size,capacity=capacity,
min_after_dequeue=30)
else:
# 不同线程处理各自的文件
# 随机包含各个线程选择文件名的随机和文件内部数据读取的随机
example_batch, label_batch = tf.train.shuffle_batch(
[example,label],batch_size=batch_size,capacity=capacity,
min_after_dequeue=30)

tf.global_variables_initializer().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess,coord=coord)
for i in range(2):
cur_example_batch, cur_label_batch = sess.run([example_batch,label_batch])
print(cur_example_batch,cur_label_batch)

coord.request_stop()
coord.join(threads)

TFRecord学习

标签:imp   .bat   ali   als   import   shuff   time   文件   post   

原文地址:https://www.cnblogs.com/hellcat/p/8146748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!