AttributeError: module 'tensorflow' has no attribute 'random_normal'python
AttributeError: module 'tensorflow' has no attribute 'Session'session
查了不少,发现是tensorflow2.0不支持session了,以前试了dom
sess = tf.compat.v1.Session()
ui
这句无效。lua
with tf.compat.v1.Session() as ses:spa
# Build a graph.
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# Evaluate the tensor `c`.
print(ses.run(c))code
这种写法能够解决,可是不兼容,我换个代码就不行了。。orm
而后在博客的回复里看到一个,能够解决这个问题:博客
import os
import tensorflow as tf
import matplotlib.pyplot as plt
import tensorflow.compat.v1 as tf
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
tf.disable_v2_behavior()
a = tf.random_([2, 30])
sess = tf.Session()
out = sess.run(a)
x, y = out
plt.scatter(x, y)
plt.show()
it
导入的时候直接导入tensorflow1的包