使用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

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM