tensorflow:讀取event文件(image)

在使用tensorflow訓練網絡時,爲了能方便地檢測訓練的細節(損失值、變量直方圖、圖像),一般使用

tf.summary.FileWriter(self.tbdir, sess.graph)來生成event文件,並能利用tensorboard方便看到訓練的數據。

但有時需要將數據提取出來,則可用tf.train.summary_iterator()      (ps:tensorboard也有event文件的數據下載)

根據標籤讀取對應的數據,for example,標量標籤cons_bbox_loss和圖像ground_truth/image/0:

code:

import tensorflow as tf
import cv2
import os
path='path/events.out.tfevents.*********'
load_num=200
scalars=[]
imgs=[]
try:
    for vs in tf.train.summary_iterator(path):
        for v in vs.summary.value:
            if v.tag=='cons_bbox_loss':
                scalars.append(v.simple_value)
            elif v.tag=='ground_truth/image/0':
                imgs.append(tf.image.decode_jpeg(v.image.encoded_image_string))
        if len(imgs) > load_num:
            break

sess=tf.Session()
imgs=sess.run(imgs[0:load_num])

 

參考鏈接:https://tensorflow.google.cn/versions/r1.15/api_docs/python/tf/train/summary_iterator

 

完~

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章