tensorflow查看电脑的CPU和GPU

编程入门 行业动态 更新时间:2024-10-07 22:24:08

tensorflow查看<a href=https://www.elefans.com/category/jswz/34/1770036.html style=电脑的CPU和GPU"/>

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)#关闭sessionsess.close()


更多推荐

tensorflow查看电脑的CPU和GPU

本文发布于:2024-02-19 14:18:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1764756.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电脑   tensorflow   GPU   CPU

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!