【琐碎】查看tensorflow安装版本、位置信息及是GPU版本还是CPU版本

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值