Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何知道是导入tensorflow还是tensorflow gpu?_Python_Tensorflow - Fatal编程技术网

Python 如何知道是导入tensorflow还是tensorflow gpu?

Python 如何知道是导入tensorflow还是tensorflow gpu?,python,tensorflow,Python,Tensorflow,我开始使用tensorflow cpu版本,但后来我安装了tensorflow gpu以加快处理速度,但我不确定哪一个当前正在工作。如何确认当前运行的版本确实是tensorflow gpu AFAIK您无法直接从python判断您是从tensorflow(仅限CPU)还是从tensorflow gpu包导入tensorflow 但是,您可以询问tensorflow了解的设备: from tensorflow.python.client.device_lib import list_local_d

我开始使用tensorflow cpu版本,但后来我安装了tensorflow gpu以加快处理速度,但我不确定哪一个当前正在工作。如何确认当前运行的版本确实是tensorflow gpu

AFAIK您无法直接从python判断您是从
tensorflow
(仅限CPU)还是从
tensorflow gpu
包导入tensorflow

但是,您可以询问tensorflow了解的设备:

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

如果有任何设备的
设备类型
类型为
GPU
,那么您肯定是从
tensorflow GPU

导入的,它基于上述p-Gns代码,并使某些东西更自动化,如下所示:

from tensorflow.python.client.device_lib import list_local_devices
ss = "\n".join([str(s) for s in list_local_devices()]
numGpus = ss.count("device:GPU")
print("There are {} GPUs present".format(numGpus))
它获取本地设备列表,将其属性转换为一个大字符串,并计算其中的GPU数量。因此,将上述文本复制并粘贴到我的python中给了我:

>>> from tensorflow.python.client.device_lib import list_local_devices
>>> ss = "\n".join([str(s) for s in list_local_devices()])
2018-06-27 09:30:43.309703: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1423] Adding visible gpu devices: 0
2018-06-27 09:30:43.309796: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-06-27 09:30:43.309836: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917]      0
2018-06-27 09:30:43.309869: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0:   N
2018-06-27 09:30:43.310186: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/device:GPU:0 with 5185 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> print(ss)
name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 4228992220605196898

name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 5436997632
locality {
  bus_id: 1
  links {
  }
}
incarnation: 6685330293620217138
physical_device_desc: "device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1"

>>> numGpus = ss.count("device:GPU")
>>> print("There are {} GPUs present".format(numGpus))
There are 1 GPUs present
>>>