更新:
在我尝试了并碰壁了两个周之后,
摸索出一套适合jupyter notebook和pycharm都适合的版本套餐,虽然有些warning,但是最终可以运行起来了。(由于各种原因,版本不适配,pycharm不支持python3.5;tensorflow1和2不兼容,网上的很多资料还是基于版本1的;…博主为小白入门,欢迎大佬批评指正!)
python3.6.1
tensorflow 1.14.0
keras2.2.5
以下为原博客。
1、安装时注意版本兼容问题!!!!
tensorflow、keras、python版本兼容问题
https://docs.floydhub.com/guides/environments/
2、查看版本时
version前后是两条横线(天坑)
区别:
tf._ version _
tf.__ version __
3、代码show_train_history(train_history, ‘accuracy’, ‘val_accuracy’)
由于版本问题。acc,val_acc是不对的,补全即可
4、AttributeError: module ‘tensorflow’ has no attribute 'Session’错误解决
因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码
tf.compat.v1.Session()
init = tf.compat.v1.global_variables_initializer()
5、RuntimeError: The Session graph is empty. Add operations to the graph before calling run().解决方法
问题产生的原因:无法执行sess.run()的原因是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.
解决办法:加上一行代码
tf.compat.v1.disable_eager_execution()
6、AttributeError: module ‘tensorflow’ has no attribute 'Session’错误解决
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()