tf.train.shuffle_batch函数解析

觉得有用的话,欢迎一起讨论相互学习~



tf.train.shuffle_batch

  • (tensor_list, batch_size, capacity, min_after_dequeue, num_threads=1, seed=None, enqueue_many=False, shapes=None, name=None)

  • Creates batches by randomly shuffling tensors. 通过随机打乱张量的顺序创建批次.

简单来说就是读取一个文件并且加载一个张量中的batch_size行

This function adds the following to the current Graph:

这个函数将以下内容加入到现有的图中.

  • A shuffling queue into which tensors from tensor_list are enqueued.

    一个由传入张量组成的随机乱序队列

  • A dequeue_many operation to create batches from the queue.

    从张量队列中取出张量的出队操作

  • A 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].

  • If 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"

  • The capacity argument controls the how long the prefetching is allowed to grow the queues. capacity控制了预抓取操作对于增加队列长度操作的长度.

  • For example:

# 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

Args:
  • 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参数的值大,并且决定了我们可以进行预处理操作元素的最大值.

推荐其值为:

\[capacity=(min\_after\_dequeue+(num\_threads+a\ small\ safety\ margin*batch_size)
\]

  • 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.
  • 设置num_threads的值大于1,使用多个线程在tensor_list中读取文件,这样保证了同一时刻只在一个文件中进行读取操作(但是读取速度依然优于单线程),而不是之前的同时读取多个文件,这种方案的优点是:
  1. 避免了两个不同的线程从同一文件中读取用一个样本
  2. 避免了过多的磁盘操作
  • 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.
Returns:
  • A list of tensors with the same number and types as tensor_list.

    默认返回一个和读取tensor_list数据和类型一个tensor列表.

tf.train.shuffle_batch函数解析的更多相关文章

  1. tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数(转)

    tensorflow数据读取机制 tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...

  2. tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数

    tensorflow数据读取机制 tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...

  3. 【转载】 tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数

    原文地址: https://blog.csdn.net/dcrmg/article/details/79776876 ----------------------------------------- ...

  4. tensorflow数据读取机制tf.train.slice_input_producer 和 tf.train.batch 函数

    tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数据读入到一个内存队列中,另一个线程 ...

  5. tf.train.examle函数

    在自定义数据集中: example = tf.train.Example(features=tf.train.Features(feature={ 'img_raw': tf.train.Featur ...

  6. tf.train.batch的偶尔乱序问题

    tf.train.batch的偶尔乱序问题 觉得有用的话,欢迎一起讨论相互学习~Follow Me tf.train.batch的偶尔乱序问题 我们在通过tf.Reader读取文件后,都需要用batc ...

  7. tensorflow|tf.train.slice_input_producer|tf.train.Coordinator|tf.train.start_queue_runners

    #### ''' tf.train.slice_input_producer :定义样本放入文件名队列的方式[迭代次数,是否乱序],但此时文件名队列还没有真正写入数据 slice_input_prod ...

  8. tfsenflow队列|tf.train.slice_input_producer|tf.train.Coordinator|tf.train.start_queue_runners

      #### ''' tf.train.slice_input_producer :定义样本放入文件名队列的方式[迭代次数,是否乱序],但此时文件名队列还没有真正写入数据 slice_input_pr ...

  9. Tensorflow滑动平均模型tf.train.ExponentialMovingAverage解析

    觉得有用的话,欢迎一起讨论相互学习~Follow Me 移动平均法相关知识 移动平均法又称滑动平均法.滑动平均模型法(Moving average,MA) 什么是移动平均法 移动平均法是用一组最近的实 ...

随机推荐

  1. deeplearning.ai 改善深层神经网络 week3 超参数调试、Batch正则化和程序框架 听课笔记

    这一周的主体是调参. 1. 超参数:No. 1最重要,No. 2其次,No. 3其次次. No. 1学习率α:最重要的参数.在log取值空间随机采样.例如取值范围是[0.001, 1],r = -4* ...

  2. POJ1163-The Triangle-动态规划

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 50122   Accepted: 30285 De ...

  3. tinyxml的封装与使用(转载)

    tinyxml是个高效精简的xml解析开源代码. 针对tinyxml直接使用对于对xml不是很熟悉的入门新手来说,有些概念难以理解,因此我将其封装后,供大家使用. 头文件: #include &quo ...

  4. css3渐变之线性渐变

    css3定义了两种类型的渐变,即线性渐变和径向渐变.这里我要说的是线性渐变. 为了创建一个线性渐变,你必须至少定义两种颜色结点.颜色结点即你想要呈现平稳过渡的颜色.同时,你也可以设置一个起点和一个方向 ...

  5. 把织梦安装到子目录,不读取CSS 没有样式?

    我在A5上找的一个模板,照着说明安装到根目录就正常,我想安装到子目录下面,结果很乱 应该是不读取CSS. {dede:global.cfg_templets_skin/}/style/about.cs ...

  6. 将本地的项目导入到github仓库总结lxw

    关键步骤: 第一:git clone https://github.com/lxw18231857001/demo-.git           #把github上面的仓库克隆到本地 本地项目文件夹下 ...

  7. 织梦dedecsm系统"企业简介"类单栏目模版如何修改和调用

    2013-1-12 14:46 | 发布者: moke | 栏目:dedecms教程        我们的模版里应该都有article_article.htm这个模版,这个模版是文章内容页模板,也就是 ...

  8. 邓_laravel框架——news

    ----------------------------------------------------------------------------------- [laravel框架] 路由+中 ...

  9. CCF系列之出现次数最多的数(201312-1)

    试题名称: 出现次数最多的数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定n个正整数,找出它们中出现次数最多的数.如果这样的数有多个,请输出其中最小的一个.   输入格 ...

  10. H5+混合移动app应用开发——坑我太甚

    用了MUI之后,才发现,那坑比我想象之中的要多得多,有些是H5的坑,有些是plus的坑,接下来我一一来吐槽一番. IOS下面,上拉的时候,速度稍微快一点,表头自动隐藏,等你不拉的时候又自动显示 这种情 ...