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, theGraphKeys
class contains many standard names for collections.scope
: (Optional.) A string. If supplied, the resulting list is filtered to include only items whosename
attribute matchesscope
usingre.match
. Items without aname
attribute are never returned if a scope is supplied. The choice ofre.match
means that ascope
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)
>>> <tf.Variable 'conv1/weights:0' shape=(3, 3, 3, 96) dtype=float32_ref>
<tf.Variable 'conv1/biases:0' shape=(96,) dtype=float32_ref>
<tf.Variable 'conv2/weights:0' shape=(3, 3, 96, 64) dtype=float32_ref>
<tf.Variable 'conv2/biases:0' shape=(64,) dtype=float32_ref>
<tf.Variable 'local3/weights:0' shape=(16384, 384) dtype=float32_ref>
<tf.Variable 'local3/biases:0' shape=(384,) dtype=float32_ref>
<tf.Variable 'local4/weights:0' shape=(384, 192) dtype=float32_ref>
<tf.Variable 'local4/biases:0' shape=(192,) dtype=float32_ref>
<tf.Variable 'softmax_linear/softmax_linear:0' shape=(192, 10) dtype=float32_ref>
<tf.Variable 'softmax_linear/biases:0' shape=(10,) dtype=float32_ref>