我最近在我的计算机上安装了tensorflow 2.0,但是当我试图在我的GPU上运行它时,在木星上的函数tf.config.experimental.list_physical_devices('GPU')或虚拟工作室代码会返回一个空数组。你知道为什么吗?
我的设置:
计算机: MSI
处理器: Intel(R) Core(TM) i7-8750H CPU @ 2.220GHz
GPU 0: Intel(R) UHD Graphics 630
GPU : NVIDIA GeForce GTX 1060
Python : Ananconda 3和Python 3.7
安装了pip install tensorflow的Tensenflow 2.0
的测试代码:
physical_devices = tf.config.experimental.list_physical_devices('GPU')
print(physical_devices)
if physical_devices:
tf.config.experimental.set_memory_growth(physical_devices[0], True)谢谢!)
发布于 2020-06-04 04:41:21
在这里提供解决方案(答案部分),即使它存在于评论部分,以造福社区。
而不是pip install tensorflow,您可以尝试pip3 install --upgrade tensorflow-gpu或删除tensorflow,然后installing "tensorflow-gpu将解决您的问题。
安装Tensorflow GPU后,您可以检查GPU如下
physical_devices = tf.config.experimental.list_physical_devices('GPU')
print(physical_devices)
if physical_devices:
tf.config.experimental.set_memory_growth(physical_devices[0], True)输出:
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]发布于 2020-09-11 13:03:51
升级对我来说是有效的。
pip3 install --upgrade tensorflow-gpu并且搜索的设备名称必须是'XLA_GPU',而不是响应solo 'GPU‘搜索术语。但是,当设置“XLA”gpus不支持的内存增长时,也会引发另一个错误。
发布于 2022-11-27 06:07:21
使用Conda用gpu安装tensorflow
首先在您的系统上安装anaconda或mini-anaconda,并确保设置了conda命令的环境路径。
在下面的命令中,将
tensor替换为您选择的环境名称:
conda create -n tensor tensorflow-gpu cudatoolkit=9.0
conda activate tensor然后使用
pip更新您的pip包,并确保您的环境是conda中的激活的。
pip3 install --upgrade tensorflow-gpu验证天气tensorflow和gpu支持是否成功安装
(tensor) C:\> python
Python 3.8.15 (default, Nov 24 2022, 14:38:14) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.config.list_physical_devices("GPU")
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]终端的输出[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]意味着我们安装了带有gpu的tensorflow。
这个答案来自安纳康达安装链接。
https://stackoverflow.com/questions/58956619
复制相似问题