首页 > 解决方案 > 通过 conda-forge 安装 tensorflow-gpu 会导致使用 CPU-only tensorflow

问题描述

我正在创建一个 conda 环境,仅用于使用频道中的tensorflow-gpuconda-forge

conda create -n tst -c conda-forge tensorflow-gpu

这将导致安装tensorflow-gpu 和包: tensorflow

The following NEW packages will be INSTALLED:

    _tflow_1100_select: 0.0.1-gpu
    ...
    tensorboard:        1.10.0-py36_0         conda-forge
    tensorflow:         1.10.0-py36_0         conda-forge
    tensorflow-gpu:     1.10.0-hf154084_0
    ...

然后当我导入 tensorflow 时,它看不到 GPU:

>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
2018-09-20 15:29:21.778708: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
False

问题:

标签: pythontensorflowconda

解决方案


通过查看 conda-forge ( https://conda-forge.org/feedstocks/ )上的软件包列表,看起来那里没有 tensorflow-gpu 软件包。conda-forge 和默认的 anaconda 包之间存在一些奇怪的兼容性问题——我通常会尽量避免将两者混为一谈。

即使你安装 as conda install -c anaconda tensorflow-gpu,它也会同时拉入非 GPU 的 tensorflow 包,但运行

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

找到 GPU。所以它似乎会自动使用启用 GPU 的版本。如果我想避免使用 GPU,我可能会使用with tf.device([CPU ID here]).


推荐阅读