jupyter notebook tensorflow打印device信息實例
juypter notebook中直接使用log_device_placement=True打印不出來device信息
# Creates a graph. with tf.device('/device:CPU:0'): 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) # Creates a session with log_device_placement set to True. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True,allow_soft_placement=True)) # Runs the op. print(sess.run(c))
需要使用output_partition_graphs來輸出device信息
# Creates a graph. with tf.device('/device:GPU:0'): 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) # Creates a session with log_device_placement set to True. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True,allow_soft_placement=True)) # Runs the op. options = tf.RunOptions(output_partition_graphs=True) metadata = tf.RunMetadata() c_val = sess.run(c, options=options, run_metadata=metadata) print metadata.partition_graphs
補充知識:Jupyter無法在控制臺打印
因為數(shù)據(jù)有中文,所以我特意在jupter前面設置了
reload(sys)
sys.setdefaultencoding("utf-8")
結(jié)果使用print語句的時候無法輸入內(nèi)容。究其原因,是因為reload的時候把sdout變?yōu)閕python的對象了,所以要臨時儲存一下stdout的對象。
不妨試一試以下代碼
import sys stdo = sys.stdout reload(sys) sys.setdefaultencoding('utf-8') sys.stdout= stdo
以上這篇jupyter notebook tensorflow打印device信息實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
python每次處理固定個數(shù)的字符的方法總結(jié)
使用python每次處理固定個數(shù)的字符,很多情況下都會遇到。本文對可能的方法做下總結(jié),供各位朋友學習參考2013-01-01pycharm中選中一個單詞替換所有重復單詞的實現(xiàn)方法
這篇文章主要介紹了pycharm中選中一個單詞替換所有重復單詞的實現(xiàn)方法,類似于sublime 里的ctrl+D功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2020-11-11