首页 > 其他分享 >tf.get_variable()不能识别已存在的变量

tf.get_variable()不能识别已存在的变量

时间:2023-02-25 14:00:52浏览次数:54  
标签:变量 conv get tf variable reuse


with tf.variable_scope("conv", reuse=True): 
x = tf.get_variable("w",[1])

这个代码不能识别已存在的变量,但是显然现有在打印出变量 .name 之前创建的,如:conv/w:0

当使用 tf.get_variable() 时遇到这个错误

ValueError: Under-sharing: Variable conv/w does not exist, disallowed. Did you mean to set reuse=None in VarScope?

如果设置 reuse=None

with tf.variable_scope("conv", reuse=None): 
x = tf.get_variable("w",[1])

然后通过 .name conv/w_1:0 创建另一个变量

这就是个bug!我现在有两个变量,一个是 conv/w ,另一个是 conv/w_1

解决方案

在特拉字节上的方式是:​​https://telabytes.com/question/preview?qid=11​


标签:变量,conv,get,tf,variable,reuse
From: https://blog.51cto.com/u_14062833/6085445

相关文章