jupyter notebook tensorflow打印device信息實(shí)例
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
補(bǔ)充知識(shí):Jupyter無法在控制臺(tái)打印
因?yàn)閿?shù)據(jù)有中文,所以我特意在jupter前面設(shè)置了
reload(sys)
sys.setdefaultencoding("utf-8")
結(jié)果使用print語句的時(shí)候無法輸入內(nèi)容。究其原因,是因?yàn)閞eload的時(shí)候把sdout變?yōu)閕python的對(duì)象了,所以要臨時(shí)儲(chǔ)存一下stdout的對(duì)象。
不妨試一試以下代碼
import sys stdo = sys.stdout reload(sys) sys.setdefaultencoding('utf-8') sys.stdout= stdo
以上這篇jupyter notebook tensorflow打印device信息實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- jupyter notebook中新建cell的方法與快捷鍵操作
- Jupyter Notebook折疊輸出的內(nèi)容實(shí)例
- 淺談JupyterNotebook導(dǎo)出pdf解決中文的問題
- 解決Jupyter notebook中.py與.ipynb文件的import問題
- jupyter notebook 添加kernel permission denied的操作
- Jupyter Notebook的連接密碼 token查詢方式
- 快速解決jupyter notebook啟動(dòng)需要密碼的問題
- jupyter notebook 的工作空間設(shè)置操作
- 查看jupyter notebook每個(gè)單元格運(yùn)行時(shí)間實(shí)例
相關(guān)文章
python每次處理固定個(gè)數(shù)的字符的方法總結(jié)
使用python每次處理固定個(gè)數(shù)的字符,很多情況下都會(huì)遇到。本文對(duì)可能的方法做下總結(jié),供各位朋友學(xué)習(xí)參考2013-01-01Django unittest 設(shè)置跳過某些case的方法
今天小編就為大家分享一篇Django unittest 設(shè)置跳過某些case的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12OpenCV+python實(shí)現(xiàn)膨脹和腐蝕的示例
這篇文章主要介紹了OpenCV+python實(shí)現(xiàn)膨脹和腐蝕的示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12pycharm中選中一個(gè)單詞替換所有重復(fù)單詞的實(shí)現(xiàn)方法
這篇文章主要介紹了pycharm中選中一個(gè)單詞替換所有重復(fù)單詞的實(shí)現(xiàn)方法,類似于sublime 里的ctrl+D功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2020-11-11