1、说明
tf.train.shuffle_batch()
这个函数的功能是:Creates batches by randomly shuffling tensors.
但需要注意的是它是一种图运算,要跑在sess.run()里
This function adds the following to the current Graph:
在运行这个函数时它会在当前图上创建如下的东西:
A shuffling queue into which tensors from tensors are enqueued.
一个乱序的队列,进队的正是传入的tensors
A dequeue_many operation to create batches from the queue.
一个dequeue_many的操作从队列中推出成batch的tensor
A QueueRunner to QUEUE_RUNNER collection, to enqueue the tensors from tensors.
一个QueueRunner的线程,正是这个线程将传入的数据推进队列中.
创建一个队列之后,最好手动关闭。形式如下:
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
// do your things
coord.request_stop()
coord.join(threads)
2、例子:将图片存为tfreader格式,然后读出并恢复图片。
tensorflow数据读取机制: