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

前端 未结 10 1247
小鲜肉
小鲜肉 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:26

    Using Anaconda + Spyder (Python 3.7)

    [code]

    import tensorflow as tf
    valor1 = tf.constant(2)
    valor2 = tf.constant(3)
    type(valor1)
    print(valor1)
    soma=valor1+valor2
    type(soma)
    print(soma)
    sess = tf.compat.v1.Session()
    with sess:
        print(sess.run(soma))
    

    [console]

    import tensorflow as tf
    valor1 = tf.constant(2)
    valor2 = tf.constant(3)
    type(valor1)
    print(valor1)
    soma=valor1+valor2
    type(soma)
    Tensor("Const_8:0", shape=(), dtype=int32)
    Out[18]: tensorflow.python.framework.ops.Tensor
    
    print(soma)
    Tensor("add_4:0", shape=(), dtype=int32)
    
    sess = tf.compat.v1.Session()
    
    with sess:
        print(sess.run(soma))
    5
    

提交回复
热议问题