《Tensorflow+Keras深度学习人工智能实践应用》的坑们

更新:
在我尝试了并碰壁了两个周之后,
摸索出一套适合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()
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值