1、No module named 'tensorflow.example
from tensorflow.examples.tutorials.mnist import input_data
ModuleNotFoundError: No module named 'tensorflow.examples'
分析:tensorflow目录下没有examples这个文件夹
解决:去https://github.com/tensorflow/tensorflow下载tensorflow_master(觉得下载太慢也可点这下载),将里面的examples文件夹复制到tensorflow目录下,示例指令:
sudo cp -rf /你的下载路径/tensorflow-master/tensorflow/examples /usr/local/lib/python3.6/dist-packages/tensorflow
如何查找rensorflow安装路径:
import tensorflow as tf
tf.__version__ # 查看版本
tf.__path__ # 查看安装路径
2、No module named ‘tensorflow.examples.tutorials’
ModuleNotFoundError: No module named 'tensorflow.examples.tutorials'
分析:上述examples里没有tutorials这个文件夹。
解决:下载添加进去(链接:https://pan.baidu.com/s/1XfVaE20UaGc2AONVTQQnpA 提取码:tkon)。
3、module ‘tensorflow’ has no attribute ‘placeholder’
x = tf.placeholder(tf.float32, [None, 784])
AttributeError: module 'tensorflow' has no attribute 'placeholder'
分析:在tf2下使用了tf1的API
解决:
import tensorflow as tf
替换成
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
4、tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
(0) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
[[node Conv2D/Conv2D (defined at /home/.../.local/lib/python3.6/site-packages/tflearn/layers/conv.py:104) ]]
[[FullyConnected_5/Softmax/_139]]
(1) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
[[node Conv2D/Conv2D (defined at /home/.../.local/lib/python3.6/site-packages/tflearn/layers/conv.py:104) ]]
分析:可能是显存太小
解决:添加如下代码
# 设置GPU内存按需分配
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
参考:
https://blog.csdn.net/csdnliwenqi/article/details/103299885
https://blog.csdn.net/qq_43263950/article/details/112237192
https://www.cnblogs.com/ping2yingshi/p/12920537.html
https://blog.csdn.net/u014027421/article/details/107325936