TensorFlow基础用法——tf.control_dependencies()函数用法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dongdong9223/article/details/83574333

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/83574333
本文出自【我是干勾鱼的博客

Ingredient:

tf.control_dependencies()函数是用来控制计算流图的,也就是给图中的某些计算指定顺序。有的时候我们想要指定某些操作执行的依赖关系,比如想要让参数先更新,然后再获取参数更新后的值等。

tf.control_dependencies(control_inputs)会返回一个控制依赖的上下文管理器,使用了with关键字就可以让在这个上下文环境中的操作都在control_inputs 执行,比如:

with g.control_dependencies([a, b, c]):
  # `d` and `e` will only run after `a`, `b`, and `c` have executed.
  d = ...
  e = ...

d、e的操作会在a、b、c的操作执行完之后再执行。

参考:

tf.control_dependencies()作用及用法

tensorflow学习笔记:control dependencies

TensorFlow中tf.control_dependencies和tf.no_op的意义和用法?

tensorflow随笔-条件循环控制 - tf.no_op(4)

猜你喜欢

转载自blog.csdn.net/dongdong9223/article/details/83574333
今日推荐