Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you

时间:2024-03-13 19:09:36

运行tensorflow程序出错:

ValueError: Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

其中详细错误如下图所示:

Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you

可以看到报错的位置为File "/home/liuyh/IDcar/Face-Aging/Face-Aging-CAAE-master/FaceAging.py", line 223, in train

    var_list=self.E_variables + self.G_variables

找到FaceAging.py的223行的位置,我的程序如下图所示:

Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you

找到了报错的位置,一开始我就在报错的位置附近找原因,最后发现并不是应该在这个地方改Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you。随后我参考了其他大神的博文,发现应该在

if reuse_variables:

                tf.get_variable_scope().reuse_variables()

这句代码前加上一句:with tf.variable_scope("encoder") as scope:

下面放上修改前后的图,修改前我的代码如下图所示:

Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you

修改后如下图所示,新加了红色箭头的那一句:

Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you

最后,上面那个错成功解决了。

参考链接:点击打开链接