Tensorflow 2.0-AttributeError:模块"tensorflow"没有属性"Session" [英] Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'

查看:997
本文介绍了Tensorflow 2.0-AttributeError:模块"tensorflow"没有属性"Session"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Tensorflow 2.0环境中执行命令sess = tf.Session()时,出现如下错误消息:

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 call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'

系统信息:

System Information:

  • OS平台和发行版:Windows 10
  • Python版本:3.7.1
  • Tensorflow版本:2.0.0-alpha0(与pip一起安装)
  • 复制步骤:

    Steps to reproduce:

    安装:

    1. pip install --upgrade pip
    2. 点安装tensorflow == 2.0.0-alpha0
    3. pip install keras
    4. pip install numpy == 1.16.2
    1. pip install --upgrade pip
    2. pip install tensorflow==2.0.0-alpha0
    3. pip install keras
    4. pip install numpy==1.16.2

    执行:

    1. 执行命令:将tensorflow导入为tf
    2. 执行命令:sess = tf.Session()

    推荐答案

    根据TF 1:1 Symbols Map,在TF 2.0中,您应该使用tf.compat.v1.Session()而不是tf.Session()

    According to TF 1:1 Symbols Map, in TF 2.0 you should use tf.compat.v1.Session() instead of tf.Session()

    https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid = 0

    要获得TF 2.0中类似TF 1.x的行为,可以运行

    To get TF 1.x like behaviour in TF 2.0 one can run

    import tensorflow.compat.v1 as tf
    tf.disable_v2_behavior()
    

    但是,这样的开发人员无法从TF 2.0中进行的许多改进中受益.有关更多详细信息,请参阅迁移指南 https://www.tensorflow.org/guide/migrate

    but then one cannot benefit of many improvements made in TF 2.0. For more details please refer to the migration guide https://www.tensorflow.org/guide/migrate

    这篇关于Tensorflow 2.0-AttributeError:模块"tensorflow"没有属性"Session"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆