在GPU上运行TensorFlow 2.0的正确方法是什么?

时间:2019-04-07 10:46:15

标签: tensorflow anaconda tensorflow2.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

此后没有错误,但是活动的env仍然是“ base *”

activate tensorflow-2.0

现在活动的env是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

1 个答案:

答案 0 :(得分:0)

Documentation当前建议使用此命令来安装具有GPU支持的Tensorflow2.0:

$ pip install tensorflow-gpu==2.0.0-alpha0

要在conda(如果您已启用CUDA的硬件)中安装它,必须首先在环境中安装pip,以便:

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

之后,发出pip命令。如果您是我,我将破坏该环境,只是为了确保并从头开始创建它。