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

Posted iiiLISA

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了《Tensorflow+Keras深度学习人工智能实践应用》的坑们相关的知识,希望对你有一定的参考价值。

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()

以上是关于《Tensorflow+Keras深度学习人工智能实践应用》的坑们的主要内容,如果未能解决你的问题,请参考以下文章