Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'

前端 未结 10 1248
小鲜肉
小鲜肉 2020-12-02 05:41

When I am executing the command sess = tf.Session() in Tensorflow 2.0 environment, I am getting an error message as below:

Traceback (most recent         


        
10条回答
  •  情歌与酒
    2020-12-02 06:05

    I faced this problem when I first tried python after installing windows10 + python3.7(64bit) + anacconda3 + jupyter notebook.

    I solved this problem by refering to "https://vispud.blogspot.com/2019/05/tensorflow200a0-attributeerror-module.html"

    I agree with

    I believe "Session()" has been removed with TF 2.0.

    I inserted two lines. One is tf.compat.v1.disable_eager_execution() and the other is sess = tf.compat.v1.Session()

    My Hello.py is as follows:

    import tensorflow as tf
    
    tf.compat.v1.disable_eager_execution()
    
    hello = tf.constant('Hello, TensorFlow!')
    
    sess = tf.compat.v1.Session()
    
    print(sess.run(hello))
    

提交回复
热议问题