Understand on the tf.variable_scope and tf.name_scope

Recent two weeks, I have spent much time on learning Tensorflow to implement my idea. Here, I would like to give some diferences between tf.variable_scope and tf.name_scope. Totally, these two method can summarize some basics operations into one node and show a clear graph visualized by TensorBoard. Next, I would like to highlight their differences.

First, we usually use the manner like w= tf.Variable(dtype=tf.float32, shape=[784, 10])) to define the variable w. Actually, the tensorflow would give a specific name for this variable in their graph, sometimes maybe like variable_1, variable_2, and so on like these. Occasionally, we would also like to define the w like this: w= tf.Variable(dtype=tf.float32, shape=[784, 10]), name=’w’). I think all these name methods are just for the compact visualization in the Tensorboard. In the same name_scope, variables with the same name would not allowed to be created andalso TF gives the errors.

Second, if the tf.variable_scope is used, the name of the variable would automatically be added a prefix with the variable scope name. In this regard, variables with the same names specified in the declaration would be fine, because a different variable scope name is added as their prefix.

Sometimes, we don’t not need to specify the variable name by the declaration, otherwise for reuse, which is another question and would be discussed when required in my future works.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值