使用TensorFlow遇到的若干问题

一、查看版本:

进入到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程序关了。

七、numpy的版本更换

每次运行代码都会出现这个警告,其实就是numpy的版本比较高

/home/eason/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/eason/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/eason/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/eason/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/eason/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/eason/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

先卸载numpy:

pip3 uninstall numpy

再安装,只要在1.17版本以下都可以

pip3 install numpy==1.16

八、ImportError: No module named ‘_tkinter’

解决方法:

sudo apt-get install python3-tk

  

 

    原文作者:tensorflow
    原文地址: https://www.cnblogs.com/darklights/p/9985412.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞