tensorflow2.0版本无法使用1.0版本的api

    科技2022-07-12  152

    tensorflow使用Session模块时报错:AttributeError: module ‘tensorflow’ has no attribute ‘Session’

    安装好tensorflow2.0之后,当使用Session时,报错AttributeError: module ‘tensorflow’ has no attribute ‘Session’:

    错误的意思是tensortflow模块没有Session属性,后来查阅资料发现,tensorflow2.0版本中的确没有Session这个属性,如果安装的是tensorflow2.0版本又想利用Session属性,可以将tf.Session()更改为:

    tf.compat.v1.disable_eager_execution()

    就可以正常运行了。

    更简单的方法,在引用tensorflow时,直接用:

    import tensorflow.compat.v1 as tf

    Processed: 0.009, SQL: 8