[英]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
我的设置如下:
我的用户范围 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 上运行,而且很慢!
双重问题:
通过使用与我在原始帖子中描述的完全相同的设置,我能够解决我的问题,但使用 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.