zl程序教程

您现在的位置是:首页 >  其它

当前栏目

TensorFlow报错ValueError: Variable layer1-conv1/weight already exists,

报错 already exists Tensorflow variable weight ValueError
2023-06-13 09:11:57 时间

一个程序中有tf.variable_scope()函数,第一次运行报错之后,第二次修改bug再次运行会报如下错误:

详细错误信息

ValueError: Variable layer1-conv1/weight already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

  File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1740, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access
  File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 3414, in create_op
    op_def=op_def)
  File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)

报错原因

tf.name_scope() 主要是用来管理命名空间的,这样子让我们的整个模型更加有条理。而 tf.variable_scope() 的作用是为了实现变量共享,它和 tf.get_variable() 来完成变量共享的功能。

解决办法

我是在Anaconda3中运行,关掉jupyter程序,重新打开jupyter,再次运行即没问题。