首页 > 解决方案 > 在 GPU 上运行 TensorFlow 2.0 的正确方法是什么?

问题描述

我在没有 AVX 的 Windows 10 PC 上使用这些命令执行此操作,仅支持 SSE4.2、GTX1060 6GB 和最新驱动程序:

conda create --name tensorflow-2.0 python=3.6
activate tensorflow-2.0
pip install tf-nightly-gpu-2.0-preview
conda install -c anaconda cudatoolkit
conda install -c anaconda cudnn

一切都很好,直到我尝试使用 TensorFlow:

import tensorflow as tf

ImportError: Traceback (most recent call last):
  File "C:\Users\Frut\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Frut\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Frut\Anaconda3\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:\Users\Frut\Anaconda3\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Frut\Anaconda3\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: Не найден указанный модуль.


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.

我尝试了另一种方法:

conda remove -n tensorflow-2.0 --all

删除了“Anaconda3\envs”中的文件夹“tensorflow-2.0”

conda create --name tensorflow-2.0 python=3.6
conda activate tensorflow-2.0 && conda install -c anaconda pip

之后没有错误,但活动环境仍然是“base *”

activate tensorflow-2.0

现在活动环境是 tensorflow-2.0

conda install -c anaconda cudatoolkit
conda install -c anaconda cudnn
pip install tensorflow-gpu==2.0.0-alpha0

结果是同样的错误:

import tensorflow as tf
Failed to load the native TensorFlow runtime

标签: tensorflowanacondatensorflow2.0

解决方案


文档当前建议使用此命令安装支持 GPU 的 Tensorflow2.0:

$ pip install tensorflow-gpu==2.0.0-alpha0

为了在里面安装它conda(假设你有启用 CUDA 的硬件),你必须pip首先在环境中安装它:

$ conda activate your_environment && conda install -c anaconda pip

之后发出 pip 命令。如果我是你,我会破坏这个环境,只是为了确定并从头开始创建它。


推荐阅读