tensorflow查看电脑的CPU和GPU

1、查看电脑GPU和CPU
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"

if __name__ == "__main__":
    print(device_lib.list_local_devices())

2、指定CPU或GPU进行计算
    #使用CPU进行计算
    with tf.device("/cpu:0"):
        a = tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[2,3])
        b = tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[3,2])
        c = tf.matmul(a,b)
        #查看计算时硬件的使用情况
        sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
        print(sess.run(c))

通过tf.device可以指定计算时使用的设备,0表示设备的个数,如果想要使用GPU进行计算,将CPU改成GPU即可。

3、查看tensor详细情况
        #设置运行时候的参数
        options = tf.RunOptions(output_partition_graphs=True)
        metadata = tf.RunMetadata()
        c_val = sess.run(c,options=options,run_metadata=metadata)
        print(metadata.partition_graphs)
        #关闭session
        sess.close()


  • 7
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

修炼之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值