tensorflow学习笔记:tf.control_dependencies,tf.GraphKeys.UPDATE_OPS,tf.get_collection

tf.control_dependencies(control_inputs):
control_dependencies(control_inputs)

ARGS:

  • control_inputs:在运行上下文中定义的操作之前必须执行或计算的 Operation 列表或 Tensor 对象.也可以是不清除控件依赖项.

返回:

指定上下文中构建的所有操作的控制依赖关系的上下文管理器.

这个上下文就是with里边的内容

Use with the with keyword to specify that all operations constructed within the context should have control dependencies on control_inputs. For example:

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

关于tf.GraphKeys.UPDATE_OPS,这是一个tensorflow的计算图中内置的一个集合,其中会保存一些需要在训练操作之前完成的操作,并配合tf.control_dependencies函数使用。

tf.get_collection():

get_collection(
    name,
    scope=None
)

Args:

  • name: The key for the collection. For example, the GraphKeys class contains many standard names for collections.
  • scope: (Optional.) A string. If supplied, the resulting list is filtered to include only items whose nameattribute matches scope using re.match. Items without a name attribute are never returned if a scope is supplied. The choice of re.match means that a scope without special tokens filters by prefix.
# 在'My-TensorFlow-tutorials-master/02 CIFAR10/cifar10.py'代码中

  variables = tf.get_collection(tf.GraphKeys.VARIABLES)
  for i in variables:
  print(i)

>>>   
      
      
      
      
      
      
      
      
      

 

你可能感兴趣的:(深度学习)