tf.control_dependencies和tf.Graph.control_dependencies

简介:
用来控制计算流图的,给图中的某些计算指定顺序
control_dependencies(control_inputs)
    Wrapper (封装)for `Graph.control_dependencies()` using the default graph.
    
    See @{tf.Graph.control_dependencies}
    for more details.
    
    Args:
      control_inputs: A list of `Operation` or `Tensor` objects which
        must be executed or computed before running the operations
        defined in the context.  Can also be `None` to clear the control
        dependencies.
    
    Returns:
     A context manager that specifies control dependencies for all
     operations constructed within the context.


control_dependencies(self, control_inputs)
    Returns a context manager that specifies control dependencies.
    
    Use with the `with` keyword to specify that all operations constructed
    within the context should have control dependencies on
    `control_inputs`. For example:
    
    ```python
    with g.control_dependencies([a, b, c]):
      # `d` and `e` will only run after `a`, `b`, and `c` have executed.
      d = ...
      e = ...
    ```
    
    Multiple calls to `control_dependencies()` can be nested, and in
    that case a new `Operation` will have control dependencies on the union
    of `control_inputs` from all active contexts.
    
    ```python
    with g.control_dependencies([a, b]):
      # Ops constructed here run after `a` and `b`.
      with g.control_dependencies([c, d]):
        # Ops constructed here run after `a`, `b`, `c`, and `d`.
    ```
    
    You can pass None to clear the control dependencies:
    
    ```python
    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`.
    ```
    
    *N.B.* The control dependencies context applies *only* to ops that
    are constructed within the context. Merely using an op or tensor
    in the context does not add a control dependency. The following
    example illustrates this point:
    
    ```python
    # WRONG
    def my_func(pred, tensor):
      t = tf.matmul(tensor, tensor)
      with tf.control_dependencies([pred]):
        # The matmul op is created outside the context, so no control
        # dependency will be added.
        return t
    
    # RIGHT
    def my_func(pred, tensor):
      with tf.control_dependencies([pred]):
        # The matmul op is created in the context, so a control dependency
        # will be added.
        return tf.matmul(tensor, tensor)
    ```
    
    Args:
      control_inputs: A list of `Operation` or `Tensor` objects which
        must be executed or computed before running the operations
        defined in the context.  Can also be `None` to clear the control
        dependencies.
    
    Returns:
     A context manager that specifies control dependencies for all
     operations constructed within the context.
    
    Raises:
      TypeError: If `control_inputs` is not a list of `Operation` or
        `Tensor` objects.
目录
相关文章
|
算法框架/工具
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
|
3月前
|
TensorFlow 算法框架/工具
【Tensorflow】解决A `Concatenate` layer should be called on a list of at least 2 inputs
在TensorFlow 2.0中,使用Concatenate函数时出现错误,可以通过替换为tf.concat 来解决。
44 4
|
3月前
|
TensorFlow API 算法框架/工具
【Tensorflow】解决Inputs to eager execution function cannot be Keras symbolic tensors, but found [<tf.Te
文章讨论了在使用Tensorflow 2.3时遇到的一个错误:"Inputs to eager execution function cannot be Keras symbolic tensors...",这个问题通常与Tensorflow的eager execution(急切执行)模式有关,提供了三种解决这个问题的方法。
42 1
|
PyTorch 算法框架/工具
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
2126 0
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
|
机器学习/深度学习 算法
【RLchina第五讲】Control as Inference(下)
【RLchina第五讲】Control as Inference(下)
|
机器学习/深度学习
【RLchina第五讲】Control as Inference(上)
【RLchina第五讲】Control as Inference(上)
103 0
|
数据格式
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
212 0
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
【解决方案】The opset version of the onnx model is 12, only model with opset_version 10/11 is supported.
【解决方案】The opset version of the onnx model is 12, only model with opset_version 10/11 is supported.
770 0
|
计算机视觉
成功解决sklearn\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 i
成功解决sklearn\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 i
|
IDE Linux 编译器
hostguest nativelangsys及uniform cui cross compile system
本文关键字:windows host targetting at linux,Compile for linux on windows using mingw64,Cross-compiling on Windows for Linux
200 0
hostguest nativelangsys及uniform cui cross compile system