代码:
with tf.VariableScope('******') as scope:
if reuse_variables == True:
scope.reuse_variables()
报错提示信息:AttributeError: __enter__
C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "F:/*******/*******.py", line 214, in <module>
model.*******_model()
File "F:/*******/*******.py", line 37, in *******_model
*******, ******* = self.*******_net(self.batch_data, self.batch_labels, False)
File "F:/*******/*******.py", line 117, in *******_net
with tf.VariableScope('*******') as scope:
AttributeError: __enter__
仔细查看源代码,with tf.VariableScope('******') as scope 中的 VariableScope 应该是小写
所以修改为:with tf.variable_scope('******') as scope 即可
这对于 TensorFlow 初学者来说可能是一个比较常犯的错误,尤其是在智能提示代码辅助输入时,很容易一不小心就回车键入了大写的错误形式,实际上 TensorFlow 中也没有 Variable_Scope 这个类,只有 VariableScope 和 variable_scope 这两个类