tf.control_dependencies()
2017-08-08 20:42
447 查看
参考这里点击打开链接的信息我们可以知道,TF可以协调多个数据流,在存在依赖的节点下非常有用,例如节点B要读取模型参数值V更新后的值,而节点A负责更新参数V,所以节点B就要等节点A执行完成后再执行,不然读到的就是更新以前的数据。这时候就需要个运算控制器tf.control_dependencies。
参考官方说明文档
format:control_dependencies(self, control_inputs)
arguments:control_inputs: A list of `Operation` or `Tensor` objects which must be executed or computed before running the operations defined in the context. (注意这里control_inputs是list)
return: A context manager that specifies control dependencies for all operations constructed within the context.(返回所有在环境中的控制依赖的上下文管理器)
其实用法很简单,只有在 control_inputs被执行以后,上下文管理器中的操作才会被执行。例如
with tf.control_dependencies([a, b, c]):
# `d` and `e` will only run after `a`, `b`, and `c` have executed.
d = ...
e = ...只有[a,b,c]都被执行了才会执行d和e操作,这样就实现了流的控制。
当然,官方文档里还介绍了嵌套多个流控制
with tf.control_dependencies([a, b]):
# Ops constructed here run after `a` and `b`.
with tf.control_dependencies([c, d]):
# Ops constructed here run after `a`, `b`, `c`, and `d`也能通过参数None清除控制依赖例如
with g.control_dependencies([a, b]):
# Ops constructed here run after `a` and `b`.
with g.control_dependencies(None):
# Ops constructed here run normally, not waiting for either `a` or `b`.
with g.control_dependencies([c, d]):
# Ops constructed here run after `c` and `d`, also not waiting
# for either `a` or `b`.
参考官方说明文档
format:control_dependencies(self, control_inputs)
arguments:control_inputs: A list of `Operation` or `Tensor` objects which must be executed or computed before running the operations defined in the context. (注意这里control_inputs是list)
return: A context manager that specifies control dependencies for all operations constructed within the context.(返回所有在环境中的控制依赖的上下文管理器)
其实用法很简单,只有在 control_inputs被执行以后,上下文管理器中的操作才会被执行。例如
with tf.control_dependencies([a, b, c]):
# `d` and `e` will only run after `a`, `b`, and `c` have executed.
d = ...
e = ...只有[a,b,c]都被执行了才会执行d和e操作,这样就实现了流的控制。
当然,官方文档里还介绍了嵌套多个流控制
with tf.control_dependencies([a, b]):
# Ops constructed here run after `a` and `b`.
with tf.control_dependencies([c, d]):
# Ops constructed here run after `a`, `b`, `c`, and `d`也能通过参数None清除控制依赖例如
with g.control_dependencies([a, b]):
# Ops constructed here run after `a` and `b`.
with g.control_dependencies(None):
# Ops constructed here run normally, not waiting for either `a` or `b`.
with g.control_dependencies([c, d]):
# Ops constructed here run after `c` and `d`, also not waiting
# for either `a` or `b`.
相关文章推荐
- tensorflow API:tf.control_dependencies
- (Tensorflow之十)tf.control_dependencies()用法
- tf.identity 和 tf.control_dependencies的用法
- Tensorflow 解惑[一]:关于tf.identity 和tf.control_dependencies
- tf.control_dependencies()
- tf.control_dependencies()和tf.identity()
- tf.control_dependencies与tf.identity组合详解
- TensorFlow入门基础知识(七)tf.control_dependencies的用法
- tf.control_dependencies()作用及用法
- tf.control_dependencies()作用及用法
- Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. The parameter is incorrect.
- TensorFlow流程控制函数:tf.group tf.control_dependencies
- Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. The parameter is incorrect. (Exception
- CruiseControl Enterprise 最佳实践 (2) : Keep your dependencies to yourself
- second order system analysis in adaptive control 自控 带零点的二阶系统matlab仿真分析
- UIPageControl
- Controls in .Net Framework 之 Context Menu Control
- Devpress.XtraGrid.GridControl笔记
- iOS开发基础控件--UISegmentedControl
- TF-IDF及其算法