11 使用Tensorboard顯示圖片

    首先,下載一張png格式的圖片(注意:只支持png格式),命名爲1.png。而後,打開PythonShell,輸入如下代碼:瀏覽器

import tensorflow as tf

# 獲取圖片數據
file = open('1.png', 'rb')
data = file.read()
file.close()

# 圖片處理
image = tf.image.decode_png(data, channels=4)
image = tf.expand_dims(image, 0)

# 添加到日誌中
sess = tf.Session()
writer = tf.summary.FileWriter('logs')
summary_op = tf.summary.image("image1", image)

# 運行並寫入日誌
summary = sess.run(summary_op)
writer.add_summary(summary)

# 關閉
writer.close()
sess.close()

    而後,在相同目錄打開cmd,輸入tensorboard --logdir=logs,而後打開瀏覽器輸入http://localhost:6006/。在Tensorboard的Images標籤頁,就能夠看到咱們的png圖片了。spa

   

    參考資料:《Tensorflow: How to Display Custom Images in Tensorboard (e.g. Matplotlib Plots)》:http://stackoverflow.com/questions/38543850/tensorflow-how-to-display-custom-images-in-tensorboard-e-g-matplotlib-plots日誌

相關文章
相關標籤/搜索