tensorflow的安装版本和安装位置
import tensorflow as tf
# 查看安装的tensorflow的版本
print(tf.__version__)
# 查看安装的tensorflow所在的位置信息
print(tf.__path__)
输出结果
2.3.0
['E:\\apps\\Anaconda3\\envs\\dome\\lib\\site-packages\\tensorflow', 'E:\\apps\\Anaconda3\\envs\\dome\\lib\\site-packages\\tensorflow_estimator\\python\\estimator\\api\\_v2', 'E:\\apps\\Anaconda3\\envs\\dome\\lib\\site-packages\\tensorboard\\summary\\_tf', 'E:\\apps\\Anaconda3\\envs\\dome\\lib\\site-packages\\tensorflow', 'E:\\apps\\Anaconda3\\envs\\dome\\lib\\site-packages\\tensorflow\\_api\\v2']
查看tensorflow所有的设备信息
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
rs=device_lib.list_local_devices()
print(type(rs))
print(rs)
运行结果
<class 'list'>
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 135652642977311002
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 13620921278231327063
physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 1408043828
locality {
bus_id: 1
links {
}
}
incarnation: 11405151038649355214
physical_device_desc: "device: 0, name: GeForce MX150, pci bus id: 0000:02:00.0, compute capability: 6.1"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 6404351628697723856
physical_device_desc: "device: XLA_GPU device"
]
查看Tensorflow-GPU是否可用,可用用于验证tensorflow-gpu是否安装成功
import tensorflow as tf
print(tf.test.is_gpu_available())
输出结果
True
查看GPU设备名
import tensorflow as tf
gpu_device_name = tf.test.gpu_device_name()
print(gpu_device_name)
输出
/device:GPU:0
查看所有GPU信息
from tensorflow.python.client import device_lib
# 列出所有的本地机器设备
local_device_protos = device_lib.list_local_devices()
# 打印
# print(local_device_protos)
# print("------------------")
# 只打印GPU设备
rs=[x for x in local_device_protos if x.device_type.find('GPU')!=-1]
print(rs)