首页 > 其他 > 详细

tf.name_scope和 tf.variable_scope区别

时间:2020-02-28 22:27:06      阅读:71      评论:0      收藏:0      [点我收藏+]

1、tf.Variables()和 tf.get_variable()区别

    tf.variable()会直接创建新的变量实例,如果已经存在,系统自己处理,变量名后缀增加0,1,2...

 tf.get_variable(“name”) 可以实现变量共享:使用默认值时reuse=False,当有相同变量存在时,系统不会自己处理,报有同名的标量存在的错;如果设置 reuse=True,如果变量已经存在,则返回存在的变量,如果不存在,则新创建一个

2、tf.name_scope和tf.variable_scope区别

  均为设置作用域。

  tf.name_scope下,仅对tf.Variable()创建的变量前面增加作用域,对tf.get_variable()创建的变量不增加作用域

       tf.variable_scope下,对tf.Variable()和tf.get_variable()创建的变量均增加作用域

       实例:

with tf.variable_scope("scope"):
  v1 = tf.get_variable("var1", [1], dtype=tf.float32)   // v1   scope/var1:0
  v2 = tf.Variable(1, name="var2", dtype=tf.float32) // v2 scope/var2:0

a = tf.add(v1, v2)      // a scope/add:0

with tf.name_scope("scope"):
  v1 = tf.get_variable("var1", [1], dtype=tf.float32)   // v1   var1:0
  v2 = tf.Variable(1, name="var2", dtype=tf.float32) // v2 scope/var2:0

a = tf.add(v1, v2)      // a scope/add:0

  

tf.name_scope和 tf.variable_scope区别

原文:https://www.cnblogs.com/pyclq/p/12380638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!