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)

>>>   <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>

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值