conda install -c anaconda tensorflow-gpu
进行安装:https://anaconda.org/anaconda/tensorflow-gpu。然而,即使我在一个全新的虚拟环境中安装了gpu版本(以避免与基础环境中安装的pip库发生冲突),tensorflow似乎出于某种神秘的原因甚至都没有识别到我的GPU。
我运行了一些代码片段(在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)
这里本应该通过显示执行op MatMul,设备为/job:localhost/replica:0/task:0/device:GPU:0
(如此写在这里:https://www.tensorflow.org/guide/gpu)来表明它是在GPU上运行的,但没有任何类似的情况出现。另外我不确定第二行之后的信息是什么意思。
我也在网上搜索了几个解决方案,包括这里,但几乎所有的问题都与第一种手动安装方法有关,而我还没有尝试过,因为每个人都推荐使用这种方法。
我不再使用cmd,因为在从基本环境中卸载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的处理器。
非常感谢您的帮助。提前致谢。
conda list
命令时,发现 cudatoolkit 并没有被安装,尽管 tensorflow-gpu 已经安装好了。我还发现 cudnn 也没有安装。我正在尝试使用conda install
命令来安装它们。当我执行conda install cudnn
命令时,它要求我将刚刚安装的 cudatoolkit 11 降级为 cudatoolkit 10。也许conda create -n tf-gpu tensorflow-gpu
在最近的版本(如 cudatoolkit 11)中效果不佳。 - user3731622