module 'tensorflow' has no attribute 'Session'. Did you mean: 'version'?
时间: 2023-09-21 21:02:54 浏览: 134
问题解决:module 'tensorflow.compat.v1' has no attribute '
5星 · 资源好评率100%
This error message usually occurs when you are using TensorFlow 2.x and trying to use the `Session` object, which was removed in TensorFlow 2.0. Instead, you should use the eager execution mode in TensorFlow 2.x, which allows for immediate evaluation of operations.
To enable eager execution, simply add the following line at the beginning of your code:
```python
import tensorflow as tf
tf.compat.v1.enable_eager_execution()
```
Then, you can use TensorFlow operations and evaluate them immediately, without the need for a `Session` object.
阅读全文