TensorFlow常见错误记录

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值