tensorflow 中 name_scope和variable_scope

import tensorflow as tf
with tf.name_scope("hello") as name_scope:
    arr1 = tf.get_variable("arr1", shape=[2,10],dtype=tf.float32)

    print (name_scope)
    print (arr1.name)
    print ("scope_name:%s " % tf.get_variable_scope().original_name_scope)

运行后的结果如下:

hello/
arr1:0
scope_name: 

 

import tensorflow as tf
with tf.name_scope('hidden') as scope:
  a = tf.constant(5, name='alpha')
  W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0), name='weights')
  b = tf.Variable(tf.zeros([1]), name='biases')
  print (a.name)
  print (W.name)
  print (b.name)

运行的结果:

 

hidden/alpha:0
hidden/weights:0
hidden/biases:0

红色字体要强调的部分所以把字体改成了红色,理解name_scope 对 tf.get_variable()的作用和 tf.Variable()的不同
 

参考文献:http://blog.csdn.net/u012436149/article/details/53081454

tf.variable_scope的详细说明,我觉得讲的非常清楚明白

https://www.jianshu.com/p/ab0d38725f88

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值