在python3.7中使用tensorflowgpu 2.0.0alpha0时出错

2024-04-16 04:50:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经按照tensorflow's website上所示的绝对字母进行了操作,但是在尝试在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.

当我运行以下代码时抛出

^{pr2}$

我的设置如下:

  • Windows 10
  • AMD 2700X CPU
  • 英伟达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

我使用visualstudio2019在一个全新的虚拟环境中运行python脚本(使用python3.7版本)。在该环境中,我运行了以下命令:

pip install tensorflow-gpu==2.0.0-alpha0

它安装了不同的软件包,在那个环境中我得到了前面提到的错误。在

另外,我的脚本在只使用CPU的tensorflow时运行得很好。在添加了包pip install tensorflow==2.0.0-alpha0的python3.7环境中,它都可以工作,但是它在我的CPU上运行,而且速度很慢!在

双重问题:

  • 如何让TensorFlow2.0在GPU而不是CPU上工作?在
  • 我对tensorflow 2.0 GPU的设置是否正确?在

Tags: inpygpulibtensorflowlineloadfiles
2条回答

新GPU?几周前也有同样的问题。我花了几个小时才找到问题。以下是一些想法:

截至2019年4月,我通过安装CUDA10.0(不是10.1或9.x)来解决Windows 10/Python 3.6.x/GPU RTX 20xx下的“DLL加载失败”问题!!!)和cuDNN 7.5.0。我还安装了Visual Studio 2015。在

确保它的CUDA10.0!!将cuDNN中的文件放入CUDA安装的相应目录中。别忘了将cuDNN*.dll文件(CUDA安装的/bin/文件夹)的位置添加到路径(win环境变量)中。在

Tensorflow可以使用pip install Tensorflow gpu安装(从4月份的1.13.1版开始)。tf2.0也应该以同样的方式工作。你的问题似乎和CUDA有关。但是,如果没有具体的原因需要tf2.0,我会选择标准安装。在

我的能够解决我的问题,使用了与我在原始文章中描述的完全相同的设置,但是使用了Python3.6而不是3.7。所有其他变量保持不变。在

我从Visual Studio 2019的全新环境开始,运行了以下导入:

pip install tensorflow-gpu==2.0.0-alpha0

然后我可以在CPU和GPU上运行我的代码。我通过运行以下命令确认GPU可用于tensorflow:

^{pr2}$

显示了什么

[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。在

问题解决了!在

相关问题 更多 >