【转载】 tf.train.slice_input_producer()和tf.train.batch()
原文地址:
https://www.jianshu.com/p/8ba9cfc738c2
------------------------------------------------------------------------------------------------
1. tf.train.slice_input_producer
函数,一种模型数据的排队输入方法。
tf.train.slice_input_producer(
tensor_list,
num_epochs=None,
shuffle=True,
seed=None,
capacity=32,
shared_name=None,
name=None
)
其参量为:
Args:
tensor_list: A list of Tensor objects.
Every Tensor in tensor_list must have the same size in the first dimension. # 循环Queue输入次数
num_epochs: An integer (optional).
If specified, slice_input_producer produces each slice num_epochs times before generating an OutOfRange error.
If not specified, slice_input_producer can cycle through the slices an unlimited number of times.
shuffle: Boolean. If true, the integers are randomly shuffled within each epoch.
seed: An integer (optional). Seed used if shuffle == True. # Queue的容量
capacity: An integer. Sets the queue capacity. shared_name: (optional). If set, this queue will be shared under the given name across multiple sessions.
name: A name for the operations (optional).
相关代码实例:
# 生成包含输入和目标图片地址名的list
input_files = [os.path.join(dirname, 'input', f) for f in flist]
output_files = [os.path.join(dirname, 'output', f) for f in flist] # 内部自动转换为Constant String的Tensor,并排队进入队列
input_queue, output_queue = tf.train.slice_input_producer(
[input_files, output_files], shuffle=self.shuffle,
seed=0123, num_epochs=self.num_epochs) # tf.train.slice_input_producer()每次取一对【输入-目标】对,交给ReadFile这
# 个Op
input_file = tf.read_file(input_queue)
output_file = tf.read_file(output_queue) # 生成RGB格式的图像tensor
im_input = tf.image.decode_jpeg(input_file, channels=3)
im_output = tf.image.decode_jpeg(output_file, channels=3)
2. tf.train.batch()
函数
tf.train.batch(
tensors,
batch_size,
num_threads=1,
capacity=32,
enqueue_many=False,
shapes=None,
dynamic_pad=False,
allow_smaller_final_batch=False,
shared_name=None,
name=None
)
其参量为:
Args:
tensors: The list or dictionary of tensors to enqueue.
batch_size: The new batch size pulled from the queue.
num_threads: The number of threads enqueuing tensors. The batching will be nondeterministic if num_threads > 1.
capacity: An integer. The maximum number of elements in the queue. #进行shuffle的输入是否为单个tensor
enqueue_many: Whether each tensor in tensors is a single example. shapes: (Optional) The shapes for each example. Defaults to the inferred shapes for tensors. dynamic_pad: Boolean.
Allow variable dimensions in input shapes.
The given dimensions are padded upon dequeue so that tensors within a batch have the same shapes. allow_smaller_final_batch: (Optional) Boolean.
If True, allow the final batch to be smaller if there are insufficient items left in the queue. shared_name: (Optional).
If set, this queue will be shared under the given name across multiple sessions. name: (Optional) A name for the operations.
相关代码实例
samples = tf.train.batch(
sample,
batch_size=self.batch_size,
num_threads=self.nthreads,
capacity=self.capacity)
【转载】 tf.train.slice_input_producer()和tf.train.batch()的更多相关文章
- 【转载】 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等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数据读入到一个内存队列中,另一个线程 ...
- 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等待数据的空闲时间,使用了两个线程分别执行数据读入和数据计算. 具体来说就是使用一个线程源源不断的将硬盘中的图片数 ...
- tf.train.slice_input_producer()
tf.train.slice_input_producer处理的是来源tensor的数据 转载自:https://blog.csdn.net/dcrmg/article/details/7977687 ...
- 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 ...
- 深度学习原理与框架-图像补全(原理与代码) 1.tf.nn.moments(求平均值和标准差) 2.tf.control_dependencies(先执行内部操作) 3.tf.cond(判别执行前或后函数) 4.tf.nn.atrous_conv2d 5.tf.nn.conv2d_transpose(反卷积) 7.tf.train.get_checkpoint_state(判断sess是否存在
1. tf.nn.moments(x, axes=[0, 1, 2]) # 对前三个维度求平均值和标准差,结果为最后一个维度,即对每个feature_map求平均值和标准差 参数说明:x为输入的fe ...
- tensorflow 的 Batch Normalization 实现(tf.nn.moments、tf.nn.batch_normalization)
tensorflow 在实现 Batch Normalization(各个网络层输出的归一化)时,主要用到以下两个 api: tf.nn.moments(x, axes, name=None, kee ...
随机推荐
- Java8 Stream 流使用场景和常用操作
JAVA8内置的函数式编程接口应用场景和方式 pojo类对象和默认创建list的方法 import lombok.AllArgsConstructor; import lombok.Data; imp ...
- ORACLE11g:No Dialect mapping for JDBC type: -9解决方案
问题来源: 某个zhizhang同事不干活 好不容易干了个活 改了个字段长度,从varchar2(50) 改成了nvarchar(100) 结果因为方言问题,程序起不来了 字段类型也改不回来了 nnd ...
- 【CSP-S 2019】【洛谷P5665】划分【单调队列dp】
前言 \(csp\)时发现自己做过类似这道题的题目 : P4954 [USACO09Open] Tower of Hay 干草塔 然后回忆了差不多\(15min\)才想出来... 然后就敲了\(88p ...
- MySQL 数据库,主键为何不宜太长长长长长长长长?
回答星球水友提问:沈老师,我听网上说,MySQL数据表,在数据量比较大的情况下,主键不宜过长,是不是这样呢?这又是为什么呢? 这个问题嘛,不能一概而论: (1)如果是InnoDB存储引擎,主键不宜过长 ...
- 复习题之Blah数集
题目描述: 大数学家高斯小时候偶然间发现一种有趣的自然数集合Blah,对于已a为基的集合Ba定义如下: (1)a是集合Ba的基,且a是Ba的第一个元素: (2)如果x在集合Ba中,则2x+1,3x+1 ...
- LOJ2719. 「NOI2018」冒泡排序 [组合计数]
LOJ 思路 这题我看着题解还搞了几个小时?我也不知道自己在干啥-- 首先你要通过出色的分析能力得到一个结论:一个排列合法当且仅当它的最长下降子序列长度不超过2. 证明?懒得写了. 然后我们不管字典序 ...
- 《挑战30天C++入门极限》新手入门:C/C++中枚举类型(enum)
新手入门:C/C++中枚举类型(enum) 如果一个变量你需要几种可能存在的值,那么就可以被定义成为枚举类型.之所以叫枚举就是说将变量或者叫对象可能存在的情况也可以说是可能的值一一例举出来. ...
- CSP-S 2019 考试分析
Day 0 考试前几天心情比较浮躁,一些题目要调个两三天,还有许多模板题打不对,看来注定凉凉: 坐大巴去日照的路上还打算复习算法来着,没想到我晕车这么厉害,几乎一睁眼就晕,想安安静静的睡会,那个电视播 ...
- Pytest权威教程05-Pytest fixtures:清晰 模块化 易扩展
目录 Pytest fixtures:清晰 模块化 易扩展 Fixtures作为函数参数使用 Fixtures: 依赖注入的主要例子 conftest.py: 共享fixture函数 共享测试数据 生 ...
- CF1209题解
E 每列都可以沿下滚动若干次,使得各行最大值之和最大 对每列的元素计算最大值,降序排,显然取前\(min(n,m)\)个列处理即可 比较巧妙的动规,设\(f(i,S)\)为前\(i\)列,已经确定最大 ...