本篇文章记录作者在使用Tensorflow时所遇到的问题,希望能帮助到需要的同志
目录
- 1.报错:ImportError: No module named 'tensorflow'
- 2.报错:AttributeError: module ‘tensorflow‘ has no attribute ‘flags‘
- 3.报错:RuntimeError: tf.placeholder() is not compatible with eager execution.
- 4.报错:ImportError: cannot import name ‘_tf_stack‘ from ‘tensorflow.python‘
- 5.将TensorFlow 1.X 的代码转换为 TensorFlow 2.0
- 6.将TensorFlow2.x转为TensorFlow1.x
- 7.在anaconda中降低python版本
- 8.安装OpenEXR失败
- 未完待续
1.报错:ImportError: No module named ‘tensorflow’
报错原因:没有安装tensorflow包。
解决办法:
pip install tensorflow
2.报错:AttributeError: module ‘tensorflow‘ has no attribute ‘flags‘
报错原因:pycharm1.x与2.x版本问题不兼容。
解决办法1:
FLAGS = tf.compat.v1.flags.FLAGS
解决办法2:
import tensorflow.compat.v1 as tf
3.报错:RuntimeError: tf.placeholder() is not compatible with eager execution.
报错原因:这是因为在运行**tf.compat.v1.placeholder(dtype, shape = None, name = None)**的时候急切执行了这条语句,但是我们一般都是在一个Session前先去定义placeholder,但是不会去执行,然后再在Sesion上下文管理器中去传入我们的数据,然后执行。
解决办法(在代码中添加这一句):
tf.compat.v1.disable_eager_execution()
例子:
import tensorflow as tf
import numpy as np
# tf.compat.v1.disable_eager_execution()
x = tf.compat.v1.placeholder(tf.float32, shape=(1024, 1024))
y = tf.matmul(x, x)
with tf.compat.v1.Session() as sess:
print(sess.run(y))
4.报错:ImportError: cannot import name ‘_tf_stack‘ from ‘tensorflow.python‘
报错原因:没有安装好tensorflow
解决办法:重新安装tensorflow
5.将TensorFlow 1.X 的代码转换为 TensorFlow 2.0
传送门
6.将TensorFlow2.x转为TensorFlow1.x
CMD:
pip uninstall tensorflow
pip install tensorflow==1.15
TensorFlow全版本传送门
python -m pip install xxx.whl
7.在anaconda中降低python版本
conda install python=3.x
8.安装OpenEXR失败
强效解决办法:
在网站中下载需要的版本:传送门
python -m pip install xxx.whl
暂时只能想到真么多,有问题的同志可以在评论区告诉我