【发布时间】:2021-03-24 03:41:50
【问题描述】:
我是深度学习的新手,过去 2 天我一直在尝试在我的电脑上安装 tensorflow-gpu 版本,但徒劳无功。我避免安装 CUDA 和 cuDNN 驱动程序,因为由于许多兼容性问题,一些在线论坛不推荐它。由于我之前已经在使用 python 的 conda 发行版,所以我选择了conda install -c anaconda tensorflow-gpu,在他们的官方网站上写着:https://anaconda.org/anaconda/tensorflow-gpu。
然而,即使在新的虚拟环境中安装了 gpu 版本(为了避免与基础环境中安装的 pip 库发生潜在冲突),tensorflow 似乎出于某种神秘原因甚至无法识别我的 GPU。
我运行的一些代码 sn-ps(在 anaconda 提示符中)以了解它无法识别我的 GPU:-
1.
>>>from tensorflow.python.client import device_lib
>>>print(device_lib.list_local_devices())
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 7692219132769779763
]
如您所见,它完全忽略了 GPU。
2.
>>>tf.debugging.set_log_device_placement(True)
>>>a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
2020-12-13 10:11:30.902956: I tensorflow/core/platform/cpu_feature_guard.cc:142] This
TensorFlow
binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU
instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
>>>b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
>>>c = tf.matmul(a, b)
>>>print(c)
tf.Tensor(
[[22. 28.]
[49. 64.]], shape=(2, 2), dtype=float32)
在这里,它应该通过显示Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0(如这里写的:https://www.tensorflow.org/guide/gpu)来表明它使用 GPU 运行,但没有类似的东西存在。我也不确定第二行之后的消息是什么意思。
我也在网上搜索了几个解决方案,包括这里,但几乎所有的问题都与第一种手动安装方法有关,因为大家都推荐这种方法,所以我还没有尝试过。
我不再使用 cmd,因为在从基本 env 卸载 tensorflow-cpu 并重新安装后,环境变量以某种方式搞砸了,它与 anaconda 提示符但不是 cmd 完美配合。这是一个单独的问题(也很普遍),但我提到了它,以防它在这里发挥作用。我在一个全新的虚拟环境中安装了 gpu 版本,以确保安装干净,据我所知,路径变量只需要设置用于手动安装 CUDA 和 cuDNN 库。
我使用的卡:-(启用了 CUDA)
C:\WINDOWS\system32>wmic path win32_VideoController get name
Name
NVIDIA GeForce 940MX
Intel(R) HD Graphics 620
我目前使用的 Tensorflow 和 python 版本:-
>>> import tensorflow as tf
>>> tf.__version__
'2.3.0'
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
系统信息:Windows 10 Home、64 位操作系统、基于 x64 的处理器。
任何帮助将不胜感激。提前致谢。
【问题讨论】:
-
抱歉格式错误,StackOverflow 不允许我在没有“缩进”终端代码的情况下发布问题。
-
我遇到了同样的问题。我发现,当我执行
conda list时,我发现即使安装了 tensorflow-gpu,也没有为我安装 cudatoolkit。我还看到 cudnn 没有安装。我现在正在尝试conda install这些。当我执行conda install cudnn时,它要求我从我刚刚安装的 cudatoolkit 11 降级到 cudatoolkit 10。也许conda create -n tf-gpu tensorflow-gpu对于最近的版本(例如 cudatoolkit 11)来说效果不佳。 -
@user3731622 是的,我也不得不降级。看起来 conda 还不支持较新的 Tf 和 CUDA 库
-
我能够使用 conda 安装 TensorFlow 2.1,然后使用 pip 安装 TensorFlow 2.4。我不喜欢混合使用 conda 和 pip,但这是让新版本 TensorFlow 运行的一种方式。
标签: python tensorflow anaconda gpu path-variables