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

How did “people you might know” find you on social software>>>

Copyright notice: This article is the original article of the blogger, following the CC 4.0 by-sa copyright agreement. Please attach the link of the original source and this notice for reprint.

Link to this article:

https://blog.csdn.net/qq_ 33440324/article/details/94200046

Operation:

import tensorflow as tf
sess=tf.Session(config=tf.ConfigProto(log_device_placement=True))

1

2

appears:

AttributeError: module 'tensorflow' has no attribute 'Session'

Reason:
because it is tensorflow version 2.0

How to solve this problem:
it is necessary to use

tf.compat.v1.Session()

Substitution

tf.Session()`

The above code must be:

import tensorflow as tf
sess=tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))

Two versions tensor flows relative to: https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0

Similar Posts: