使用TensorFlow遇到的若干问题

本文详细解答了TensorFlow在使用过程中遇到的常见问题,包括版本冲突、cuDNN不匹配、模块导入失败、API变更、语法错误及GPU资源管理等,提供了具体的排查和解决步骤。

一、查看版本:

进入到Python的命令行状态后,可以在终端输入查询命令如下:

import tensorflow
tensorflow.__version__

查询tensorflow安装路径为:

tensorflow.__path__

二、cuDNN无法使用

Loaded runtime CuDNN library: 7.0.5 but source was compiled with: 7.1.4.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.

我的开发环境是

ubuntu18.04   
cuda9.0   
cudnn7.0  
tensorflow 1.12.0  
python 3.6

发现错误原因是TensorFlow的版本太高了。

解決的方法是把tensorflow降到和我cudnn匹配的版本:

pip3 install --upgrade --force-reinstall tensorflow-gpu==1.9.0

 三.出现No module named 'object_detection' 的错误

File "object_detection/builders/model_builder_test.py", line 23, in <module>     
    from object_detection.builders import model_builder Module
NotFoundError: No module named 'object_detection'

这个是上一步的slim的导入路径问题,应该使用slim的绝对路径:

export PYTHONPATH="$PYTHONPATH:/home/user/models/research/slim"

 四、AttributeError:'module' object has no attribute 'mul'

原因:TensorFlow 发布的新版本的 API 修改了

tf.mul, tf.sub and tf.neg are deprecated in favor of tf.multiply, tf.subtract and tf.negative.

解决方法:使用时将 tf.mul 改成 tf.multiply 即可,其余的 tf.sub 和 tf.neg 也要相应修改为 tf.subtract 和 tf.negative。

五、SyntaxError: invalid syntax

print "Epoch {0}: {1} / {2}".format(
                                      ^
SyntaxError: invalid syntax

Python3中print函数需要加括号。

六、Dst tensor is not initialized

原因:GPU显存满了。

解决方法:如果是使用Jupyter,就把别的运行的Jupyter程序关了。

转载于:https://www.cnblogs.com/darklights/p/9985412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值