问题描述:
提示:使用tensorflow 2.x版本以上,而运行代码为tensorflow 1.x版本
AttributeError: mode 'tensorflow' has no attribute 'variable_scope'
原因分析:
此问题出现在2.X版本,造成这种现象的原因是版本不匹配。
第一种办法:大部分在tf后面加上.compat.v1,即可解决
tf.get_default_graph() 改为 tf.compat.v1.get_default_graph()
tf.Session() 改为 tf.compat.v1.Session()
tf.placeholder 改为 tf.compat.v1.placeholder
第二种办法:屏蔽tensorflow 2.x版本
import tensorflow.compat.v1 as tf
tf.disable_eager_execution()