tensorflow —— Variable Scope 共享变量

def my_image_filter(input_images):
    with tf.variable_scope("conv1"):
        # Variables created here will be named "conv1/weights", "conv1/biases".
        relu1 = conv_relu(input_images, [5, 5, 32, 32], [32])
    with tf.variable_scope("conv2"):
        # Variables created here will be named "conv2/weights", "conv2/biases".
        return conv_relu(relu1, [5, 5, 32, 32], [32])
  1. 创建或返回给定名称的变量:tf.get_variable(<name>, <shape>, <initializer>)

  2. 管理传给get_variable()的变量名的作用域,作为变量名的前缀:tf.variable_scope(<scope_name>)

  • 当前环境的作用域可以通过函数tf.get_variable_scope()获取,并且reuse标志可以通过调用reuse_variables()设置为True。
  • 一旦设置为True,就不能返回到False,并且该作用域的子空间reuse都是True。如果不想重用变量,则退回到上层non-reusing作用域。
  1. 重用已经创建的变量:reuse_variables()tf.get_variable_scope().reuse == True

  2. 当使用with tf.variable_scope()打开一个已经存在的作用域时,就会跳转到这个作用域.
    如果tf.variable_scope()传入字符参数,创建变量作用域的同时会隐式创建同名的名称作用域。
    tf.variable_scope()传入的不是字符串而是scope对象,则不会隐式创建同名的名称作用域。

参考:https://www.cnblogs.com/MY0213/p/9208503.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值