python - 通过 conda-forge 安装 tensorflow-gpu 会导致使用 CPU-only tensorflow
问题描述
我正在创建一个 conda 环境,仅用于使用频道中的tensorflow-gpu
包conda-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
问题:
- 当只需要前者时,为什么 conda 会同时安装
tensorflow-gpu
和包?tensorflow
- 两个包可以和平共存吗?如果可以,如何在两者之间切换?
- 加分项:为什么从主通道安装时一切正常,即
conda create -n tst tensorflow-gpu
?(我没有受过教育的猜测是,conda-forge
包tensorflow-gpu
实际上来自主渠道,因此在导入期间具有较低的优先级)。
解决方案
通过查看 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])
.
推荐阅读
- c# - SQL Query to Linq Query Result into complex object
- angular - 单击时获取子元素的 ID
- javascript - 按钮单击以提供随机图像背景(CSS + JavaScript + JQuery)
- python - 从 pandas 数据框到 xlwings 的 excel?
- php - ElephantIO 未发送到客户端并始终显示用户已断开连接
- python - 高度和宽度值在 Kivy Python 上不起作用
- python - 尝试 tk.root.state('zoomed') 时 Tkinter 窗口抛出错误
- azure - 使用已删除的名称创建 Azure API 管理会导致名称“已在使用”错误
- java - 无法在 Firebase 实时数据库上读取或写入
- python-3.x - 如何增加 PyQt5 app.processEvents() 队列深度?