导入具有GPU支持的TensorFlow时DLL加载失败
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导入具有GPU支持的TensorFlow时DLL加载失败相关的知识,希望对你有一定的参考价值。
我试图在Windows 10上安装带有GPU支持的TensorFlow,但导入时出现错误(如下所示)。 CPU版本工作正常。
我有
- 通过pip安装
tensorflow-gpu
- 使用GeForce Experience更新了我的GTX 1050的NVidia驱动程序
- 使用NVidia的网络安装程序安装了CUDA 10.1
- installed cuDNN 7.5.0.56,负责复制正确的CUDA文件夹中的每个文件
- installed TensorRT 5.1.2.2通过zip方法再次复制CUDA中的相关DLL
这是错误:
> python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:UsersuserAppDataLocalProgramsPythonPython37libimp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:UsersuserAppDataLocalProgramsPythonPython37libimp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpython\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:UsersuserAppDataLocalProgramsPythonPython37libimp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:UsersuserAppDataLocalProgramsPythonPython37libimp.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.
我的PATH环境变量(我删除了所有非Microsoft和非NVidia条目):
> echo $env:PATH.Split(';')
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.1in
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.1libnvvp
C:Program FilesMicrosoft MPIBin
C:WINDOWSsystem32
C:WINDOWS
C:WINDOWSSystem32Wbem
C:WINDOWSSystem32WindowsPowerShellv1.0
C:WINDOWSSystem32OpenSSH
C:Program FilesMicrosoft SQL Server130ToolsBinn
C:Program Filesdotnet
C:Program Files (x86)dotnet
C:Program Files (x86)NVIDIA CorporationPhysXCommon
C:Program FilesNVIDIA CorporationNsight Compute 2019.1
C:Program FilesNVIDIA CorporationNVIDIA NvDLISR
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.1extrasCUPTIlib64
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.1include
C:Program FilesTensorRT-5.1.2.2lib
C:Program FilesTensorRT-5.1.2.2in
C: oolscudain
TensorRT安装在C:Program FilesTensorRT-5.1.2.2
中。
CUDA bin
文件夹的内容:
PS C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.1in> ls
Directory: C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.1in
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 18/04/2019 12:39 crt
-a---- 09/02/2019 06:57 202752 bin2c.exe
-a---- 09/02/2019 06:57 74850816 cublas64_10.dll
-a---- 09/02/2019 06:57 36055552 cublasLt64_10.dll
-a---- 09/02/2019 06:57 374272 cuda-memcheck.exe
-a---- 09/02/2019 06:57 4320256 cudafe++.exe
-a---- 09/02/2019 06:57 339968 cudart32_101.dll
-a---- 09/02/2019 06:57 408064 cudart64_101.dll
-a---- 18/04/2019 15:19 392566784 cudnn64_7.dll
-a---- 09/02/2019 06:57 115644416 cufft64_10.dll
-a---- 09/02/2019 06:57 225792 cufftw64_10.dll
-a---- 09/02/2019 06:57 4785664 cuinj64_101.dll
-a---- 09/02/2019 06:57 2074624 cuobjdump.exe
-a---- 09/02/2019 06:57 49030656 curand64_10.dll
-a---- 09/02/2019 06:57 171052032 cusolver64_10.dll
-a---- 09/02/2019 06:57 87930368 cusparse64_10.dll
-a---- 09/02/2019 06:57 285184 fatbinary.exe
-a---- 09/02/2019 06:57 1323008 gpu-library-advisor.exe
-a---- 09/02/2019 06:57 233472 nppc64_10.dll
-a---- 09/02/2019 06:57 10049024 nppial64_10.dll
-a---- 09/02/2019 06:57 3719680 nppicc64_10.dll
-a---- 09/02/2019 06:57 1003008 nppicom64_10.dll
-a---- 09/02/2019 06:57 7227904 nppidei64_10.dll
-a---- 09/02/2019 06:57 46016512 nppif64_10.dll
-a---- 09/02/2019 06:57 24603136 nppig64_10.dll
-a---- 09/02/2019 06:57 5848064 nppim64_10.dll
-a---- 09/02/2019 06:57 17426944 nppist64_10.dll
-a---- 09/02/2019 06:57 194560 nppisu64_10.dll
-a---- 09/02/2019 06:57 2610688 nppitc64_10.dll
-a---- 09/02/2019 06:57 8202240 npps64_10.dll
-a---- 09/02/2019 06:57 247296 nvblas64_10.dll
-a---- 09/02/2019 06:57 384000 nvcc.exe
-a---- 09/02/2019 06:57 310 nvcc.profile
-a---- 09/02/2019 06:57 22919168 nvdisasm.exe
-a---- 09/02/2019 06:57 149298688 nvgraph64_10.dll
-a---- 18/04/2019 16:46 131539456 nvinfer.dll
-a---- 18/04/2019 16:46 3663360 nvinfer_plugin.dll
-a---- 09/02/2019 06:57 5960192 nvlink.exe
-a---- 18/04/2019 16:46 4457472 nvonnxparser.dll
-a---- 18/04/2019 16:46 2447872 nvparsers.dll
-a---- 09/02/2019 06:57 4243456 nvprof.exe
-a---- 09/02/2019 06:57 221696 nvprune.exe
-a---- 09/02/2019 06:57 4580352 nvrtc-builtins64_101.dll
-a---- 09/02/2019 06:57 15659520 nvrtc64_101_0.dll
-a---- 09/02/2019 06:57 53 nvvp.bat
-a---- 09/02/2019 06:57 5838336 ptxas.exe
和C: ools
的内容:
PS C: ools> tree /F
Folder PATH listing
Volume serial number is 6A54-3EA7
C:.
└───cuda
│ NVIDIA_SLA_cuDNN_Support.txt
│
├───bin
│ cudnn64_7.dll
│
├───include
│ cudnn.h
│
└───lib
└───x64
cudnn.lib
答案
问题是我安装了CUDA 10.1而不是10.0。 TensorFlow尚未与10.1兼容。
另一答案
是的,某些版本的TensorFlow不支持CUDA 10.1,在这种情况下,CUDA 10.0或更低版本将解决您的问题。
另一答案
这就是我如何解决它,如果你使用pip或pip3,你第一次成功的机会就会减少。
- 卸载Python,CUDA,CuNN,Tensorflow-gpu(如果已安装)
- 安装ANACONDA或MINICONDA
- 打开ANACONDA提示符并运行以下命令:
conda create --name tf_gpu tensorflow-gpu
- 这将创建一个环境tf_gpu,它将安装Python,CUDA,CuNN和Tensorflow的所有兼容版本
- 安装完所有软件包后,打开ANACONDA提示符并输入以下命令
conda激活tf_gpu
- 这会将conda'(base)'更改为'(tf_gpu)'环境
- 然后像往常一样键入python以激活python提示符
- 如果要停用'tf_gpu'环境
conda停用
以上是关于导入具有GPU支持的TensorFlow时DLL加载失败的主要内容,如果未能解决你的问题,请参考以下文章
Windows 上的 TensorFlow:“无法打开 CUDA 库 cudnn64_5.dll”
TensorFlow Lite GPU 对 python 的支持
Tensorflow GPU 无法加载动态库“cusolver64_10.dll”; dlerror: 未找到 cusolver64_10.dll