你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
匿名用户
赞同来自:
import tensorflow as tf w_1 = tf.get_variable(name="w_1",initializer=1) w_2 = tf.get_variable(name="w_1",initializer=2) #错误信息 #ValueError: Variable w_1 already exists, disallowed. Did #you mean to set reuse=True in VarScope?
import tensorflow as tf with tf.variable_scope("scope1"): w1 = tf.get_variable("w1", shape=) w2 = tf.Variable(0.0, name="w2") with tf.variable_scope("scope1", reuse=True): w1_p = tf.get_variable("w1", shape=) w2_p = tf.Variable(1.0, name="w2") print(w1 is w1_p, w2 is w2_p) #输出 #True False
要回复问题请先登录或注册
1 个回复
匿名用户
赞同来自:
当我们需要共享变量的时候,需要使用tf.get_variable()。在其他情况下,这两个的用法是一样的。
tf.Variable() 每次都在创建新对象,所有reuse=True 和它并没有什么关系。对于get_variable(),来说,如果已经创建的变量对象,就把那个对象返回,如果没有创建变量对象的话,就创建一个新的。