【问题标题】:Tensorflow cannot use GPUTensorFlow 无法使用 GPU
【发布时间】:2018-03-12 23:36:48
【问题描述】:

我已经安装了 CUDA,因为我需要运行一些深度神经网络模型,但是 Tensorflow 仍然无法看到 gpu

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

它只显示 CPU。

如何让 Tensorflow 使用我的 GPU?

当我导入安装了 tensorflow-gpu 的 keras 时得到的错误日志 ImportError: Traceback (最近一次调用最后一次): 文件“C:\Users\Monviso\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 18 行,在 swig_import_helper 返回 importlib.import_module(mname) 文件“C:\Users\Monviso\Anaconda3\lib\importlib__init__.py”,第 126 行,在 import_module return _bootstrap._gcd_import(name[level:], package, level) _gcd_import 中的文件“”,第 978 行 _find_and_load 中的文件“”,第 961 行 文件“”,第 950 行,在 _find_and_load_unlocked 文件“”,第 648 行,在 _load_unlocked 文件“”,第 560 行,在 module_from_spec 文件“”,第 922 行,在 create_module _call_with_frames_removed 中的文件“”,第 205 行 ImportError: DLL load failed: 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Monviso\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Monviso\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Monviso\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\Monviso\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

【问题讨论】:

  • 您有哪些版本的 Nvidia 驱动程序和 cudNN?你安装的是什么型号的显卡?
  • 你为 GPU 或 CPU 安装了张量流吗?
  • +1 对 deaspo 的评论。 tensorflow 有两个版本(如果我没记错的话,tensorflow 和 tensorflow-gpu)
  • 我已经安装了两个 tensorflow 版本。我的 gpu 是 gtx960M ,因此兼容,我有 CUDA 9.0
  • @Alex:你需要去掉tensorflow CPU版本才能访问tensorflow的GPU版本。

标签: python tensorflow


【解决方案1】:

您的 Cuda 版本是问题所在。只有 tensorflow 1.5 版支持 CUDA 9 和 cuDNN 7。之前的 Tensorflows 版本只支持 CUDA 8 和 cuDNN 6。如果你使用 anaconda 安装,很可能你没有安装 1.5 版。使用 pip 或 pip3 安装。

由于您使用的是 Windows 机器,请检查 this 链接以安装支持 gpu 的 tensorflow。

查看link 以查看哪个版本需要什么 Cuda 和 Cudnn

我建议你卸载 tensorflow 的 CPU 和 GPU 版本并重新安装。

如果您想将 cuda 版本保持为 9,请安装 tensorflow 版本 1.5。如果您使用 anaconda 安装,您可能会获得仅支持 Cuda 8 的 1.4 版

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 2020-01-14
    • 2018-12-20
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 2018-06-12
    相关资源
    最近更新 更多