tf.train.shuffle_batch函数解析
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_listare enqueued.
一个由传入张量组成的随机乱序队列A
dequeue_manyoperation to create batches from the queue.
从张量队列中取出张量的出队操作A
QueueRunnertoQUEUE_RUNNERcollection, to enqueue the tensors
fromtensor_list.
一个队列运行器管理出队操作.
Ifenqueue_manyisFalse,tensor_listis 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_manyisTrue,tensor_listis assumed to represent a batch of examples, where the first dimension is indexed by example, and all members oftensor_listshould 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
capacityargument 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参数的值大,并且决定了我们可以进行预处理操作元素的最大值.
推荐其值为:
\]
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 enqueuingtensor_list.- 设置num_threads的值大于1,使用多个线程在tensor_list中读取文件,这样保证了同一时刻只在一个文件中进行读取操作(但是读取速度依然优于单线程),而不是之前的同时读取多个文件,这种方案的优点是:
- 避免了两个不同的线程从同一文件中读取用一个样本
- 避免了过多的磁盘操作
seed: Seed for the random shuffling within the queue.
打乱tensor队列的随机数种子enqueue_many: Whether each tensor intensor_listis a single example.
定义tensor_list中的tensor是否冗余.shapes: (Optional) The shapes for each example. Defaults to the
inferred shapes fortensor_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函数解析的更多相关文章
- tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数(转)
tensorflow数据读取机制 tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...
- tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数
tensorflow数据读取机制 tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...
- 【转载】 tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数
原文地址: https://blog.csdn.net/dcrmg/article/details/79776876 ----------------------------------------- ...
- tensorflow数据读取机制tf.train.slice_input_producer 和 tf.train.batch 函数
tensorflow中为了充分利用GPU,减少GPU等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数据读入到一个内存队列中,另一个线程 ...
- tf.train.examle函数
在自定义数据集中: example = tf.train.Example(features=tf.train.Features(feature={ 'img_raw': tf.train.Featur ...
- tf.train.batch的偶尔乱序问题
tf.train.batch的偶尔乱序问题 觉得有用的话,欢迎一起讨论相互学习~Follow Me tf.train.batch的偶尔乱序问题 我们在通过tf.Reader读取文件后,都需要用batc ...
- tensorflow|tf.train.slice_input_producer|tf.train.Coordinator|tf.train.start_queue_runners
#### ''' tf.train.slice_input_producer :定义样本放入文件名队列的方式[迭代次数,是否乱序],但此时文件名队列还没有真正写入数据 slice_input_prod ...
- tfsenflow队列|tf.train.slice_input_producer|tf.train.Coordinator|tf.train.start_queue_runners
#### ''' tf.train.slice_input_producer :定义样本放入文件名队列的方式[迭代次数,是否乱序],但此时文件名队列还没有真正写入数据 slice_input_pr ...
- Tensorflow滑动平均模型tf.train.ExponentialMovingAverage解析
觉得有用的话,欢迎一起讨论相互学习~Follow Me 移动平均法相关知识 移动平均法又称滑动平均法.滑动平均模型法(Moving average,MA) 什么是移动平均法 移动平均法是用一组最近的实 ...
随机推荐
- centos6.x升级protobuf操作流程.
1.首先卸载protobuf,使用命令如下: sudo yum remove protobuf 2.下载protobuf源,依据自己的需要下载: 2.1下载地址:https://github.com/ ...
- JavaScript for in的缺陷
for in 语句用来列举对象的属性(成员),如下 1 2 3 4 5 6 7 var obj = { name:"jack", getName:function(){ ...
- struts2(三)之表单参数自动封装与参数类型自动转换
前言 对struts2的使用不外乎这几点,参数自动封装,拦截器的使用,数据校验,ognl表达(值栈和actionContext的讲解),struts2的标签,struts2的国际化, struts2的 ...
- UVA11039-Building designing
Building designing Time limit: 3.000 seconds An architect wants to design a very high building. The ...
- B. OR in Matrix
B. OR in Matrix time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- three.js 入门案例
最近公司需要用tree.js实现一个3D图的显示,就看了官方文档,正好有时间,就记录下来. 由于我们公司的前端框架用的是angular,所以我就把我的treejs封装在一个directives里面.后 ...
- Spark算子--SortBy
转载请标明出处http://www.cnblogs.com/haozhengfei/p/39edcbb10b5076599c0e5609b7136b88.html SortBy--Transforma ...
- 《You dont know JS》类型篇总结
类型 javaScript中的类型和熟知的一些强类型语言的有关类型的定义是不一样的.在js中,类型的含义是值的内部特征,它定义了值得行为,以使其区别于其他值.(a type is an intrins ...
- for循环去重排序
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 微信公众号中ip白名单用谁的ip
https://segmentfault.com/q/1010000010201211 白名单怎么说 我该填写谁的 我的ip地址每天都变化的 服务器ip啊,为了防止未授权的代码盗用你的权限.写你ip是 ...