tensorflow2报错AttributeError: module ‘tensorflow’ has no attribute ‘variable_scope’
代码
w = tf.get_variable('w', shape=[10, 10], initializer=w_init)
报错信息
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-1e342a9e77b5> in <module>()
1 var_graph = tf.Graph()
----> 2 with var_graph.as_default(), tf.variable_scope('my_var_scope'):
3 w_init = tf.truncated_normal_initializer()
4 b_init = tf.zeros_initializer()
5 w = tf.get_variable('w', shape=[10, 10], initializer=w_init)
AttributeError: module 'tensorflow' has no attribute 'variable_scope'
解决方法
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
欢迎大家交流学习,任何问题都可以留言