測試tensorflow是否用Gpu加速

方法一:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))

方法二:

import tensorflow as tf
version = tf.__version__
gpu_ok = tf.test.is_gpu_available()
print("tf version:",version,"\nuse GPU",gpu_ok)

方法三:程序運行時,使用相關軟件查看Gpu佔用,如

windows:任務管理器、GPU-Z,

Linux:$ watch -n 1 nvidia-smi(數字爲刷新時間,秒)

發佈了19 篇原創文章 · 獲贊 2 · 訪問量 5555
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章