tf.train.shuffle_batch
This function adds the following to the current Graph
:这个函数将以下内容加入到现有的图中.
tensor_list
are enqueued.
一个由传入张量组成的随机乱序队列dequeue_many
operation to create batches from the queue.
从张量队列中取出张量的出队操作QueueRunner
to QUEUE_RUNNER
collection, to enqueue the tensors from tensor_list
. 一个队列运行器管理出队操作. If enqueue_many
is False
, tensor_list
is assumed to represent a single example. An input tensor with shape [x, y, z]
will be output as a tensor with shape [batch_size, x, y, z]
.enqueue_many
is True
, tensor_list
is assumed to represent a batch of examples, where the first dimension is indexed by example, and all members of tensor_list
should have the same size in the first dimension. If an input tensor has shape [*, x, y, z]
, the output will have shape [batch_size, x, y, z]
.enqueue_many主要是设置tensor中的数据是否能重复,如果想要实现同一个样本多次出现可以将其设置为:"True",如果只想要其出现一次,也就是保持数据的唯一性,这时候我们将其设置为默认值:"False"
capacity
argument controls the how long the prefetching is allowed to grow the queues. capacity控制了预抓取操作对于增加队列长度操作的长度.# Creates batches of 32 images and 32 labels.
image_batch, label_batch = tf.train.shuffle_batch( [single_image, single_label], batch_size=32, num_threads=4,capacity=50000,min_after_dequeue=10000)
这段代码写的是从[single_image, single_label]利用4个线程读取32个数据作为一个batch
tensor_list
: The list of tensors to enqueue.
入队的张量列表batch_size
: The new batch size pulled from the queue.
表示进行一次批处理的tensors数量.capacity
: An integer. The maximum number of elements in the queue.容量:一个整数,队列中的最大的元素数. 这个参数一定要比min_after_dequeue参数的值大,并且决定了我们可以进行预处理操作元素的最大值. 推荐其值为:
min_after_dequeue
: Minimum number elements in the queue after a dequeue(出列), used to ensure a level of mixing of elements.num_threads
: The number of threads enqueuing tensor_list
.seed
: Seed for the random shuffling within the queue.
打乱tensor队列的随机数种子enqueue_many
: Whether each tensor in tensor_list
is a single example.
定义tensor_list中的tensor是否冗余.shapes
: (Optional) The shapes for each example. Defaults to the inferred shapes for tensor_list
.
用于改变读取tensor的形状,默认情况下和直接读取的tensor的形状一致.name
: (Optional) A name for the operations.tensor_list
.
默认返回一个和读取tensor_list数据和类型一个tensor列表.