簡體   English   中英

在python3.7中使用tensorflow-gpu 2.0.0-alpha0時出錯

[英]Error when using tensorflow-gpu 2.0.0-alpha0 in python3.7

我已經按照tensorflow 網站顯示的說明進行了絕對字母操作,但是在嘗試在 python 中導入 tensorflow 時仍然出現以下錯誤:

Traceback (most recent call last):
File "C:\Users\redacted\source\Repos\TFTest1\TFTest1\tf2-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\redacted\source\Repos\TFTest1\TFTest1\tf2-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>     _pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\redacted\source\Repos\TFTest1\TFTest1\tf2-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper     _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\imp.py", line 242, in load_module     return load_dynamic(name, filename, file)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\imp.py", line 342, in load_dynamic     return _load(spec) ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.  See https://www.tensorflow.org/install/errors  for some common reasons and solutions.  Include the entire stack trace above this error message when asking for help.

當我運行以下代碼時拋出

import tensorflow as tf

我的設置如下:

  • 視窗 10
  • AMD 2700X 中央處理器
  • 英偉達 RTX 2080 GPU
  • Python 3.7(64 位)
  • CUDA 工具包 10.0
  • CUDAnn 7.5.1(適用於 CUDA 10.0)

我的用戶范圍 PATH 環境變量中有以下內容:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include
C:\tools\cuda\bin

然后,我可以通過在命令行中運行以下命令來確認 CUDA 已正確安裝:

nvcc -V

這讓我看到

nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA
Corporation Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130

我正在使用 Visual Studio 2019 在全新的虛擬環境中運行 python 腳本(使用 python 3.7 版)。 在那個環境中,我運行了以下命令:

pip install tensorflow-gpu==2.0.0-alpha0

它安裝了各種軟件包,在那個環境中我得到了上述錯誤。

作為旁注,我的腳本在僅使用 CPU tensorflow 時運行得很好。 在 python 3.7 環境中添加了包pip install tensorflow==2.0.0-alpha0一切正常,但它在我的 CPU 上運行,而且很慢!

雙重問題:

  • 如何讓 tensorflow 2.0 在 GPU 而不是 CPU 上工作?
  • 我的設置是否適用於 tensorflow 2.0 GPU?

通過使用與我在原始帖子中描述的完全相同的設置,我能夠解決我的問題,但使用 Python 3.6而不是 3.7。 所有其他變量保持不變。 (感謝彼得幫助找到答案!)

我從 Visual Studio 2019 中的新環境開始,並運行了以下導入:

pip install tensorflow-gpu==2.0.0-alpha0

然后我就可以在 CPU 和 GPU 上運行我的代碼了。 我通過運行來確認 GPU 可用於 tensorflow:

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())

其中顯示

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 18233115335171708614
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 6588081767
locality {
  bus_id: 1
  links {
  }
}
incarnation: 12253248400045769946
physical_device_desc: "device: 0, name: GeForce RTX 2080, pci bus id: 0000:1d:00.0, compute capability: 7.5"
]

我還可以看到使用任務管理器時 CPU 使用率為 25%,GPU 使用率為 10%。 我想我的神經網絡有點線性,還不能真正充分利用 GPU。

問題解決了!

新 GPU? 幾周前遇到了同樣的問題。 我花了幾個小時才找到問題。 這里有一些想法:

截至 2019 年 4 月,我通過使用 cuDNN 7.5.0 安裝 CUDA 10.0(不是 10.1 或 9.x!!! )解決了 Windows 10 / Python 3.6.x / GPU RTX 20xx 下的“DLL 加載失敗”問題。 我還安裝了 Visual Studio 2015。

確保它的 CUDA 10.0 !! 將 cuDNN 中的文件放在 CUDA 安裝的相應目錄中。 不要忘記將 cuDNN *.dll 文件的位置(CUDA 安裝的 /bin/ 文件夾)添加到 PATH(win 環境變量)。

Tensorflow 可以使用 pip install tensorflow-gpu 安裝(截至 4 月版本 1.13.1)。 TF 2.0 應該以同樣的方式工作。 您的問題似乎與 CUDA 有關。 但是,如果沒有特定原因需要 TF 2.0,我會選擇標准安裝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM