Tensorflow has no attribute'Session' error reason

Introduction to errors

Error message:

AttributeError: module ‘tensorflow’ has no attribute ‘Session’

When installing tensorflow using conda install tensorflow-gpu, the version was not specified, resulting in the installation of tensorflow2.1 version. And tf.Session is the code in version 1.X of tensorflow.
Insert picture description here

Comparison of tensorflow 1.x and 2.x function interfaces

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

Solution

  1. Method: Use the interface of tensorflow 2.x version to call
    tf.Session() --> tf.compat.v1.Sesion()
  2. Method: Use the previous version.

reference:

AttributeError: module ‘tensorflow’ has no attribute ‘Session’

Guess you like

Origin blog.csdn.net/u013894391/article/details/104513714