tensorflow2版本不包含session问题记录

报错信息为:AttributeError: module ‘tensorflow’ has no attribute ‘Session
解决办法:
将import tensorflow as tf 写为import tensorflow.compat.v1 as tf

import tensorflow.compat.v1 as tf

后面又报错:RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
此时添加:

tf.compat.v1.disable_eager_execution()

然后问题解决!
激活TensorFlow:

conda activate tf

退出TensorFlow:

conda deactivate

参考资料:
添加链接描述


版权声明:本文为weixin_44382664原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。