使用python代码实现tensorflow event文件内容读取

tf_event_file读取

使用tensorboard可以对events.out.tfevents.进行可视化,如需读取

其内loss或acc等曲线进行custom处理的话,则需使用读取函数将其数值读取出来,读取函数如下:

import os
import json
import tensorflow as tf


def get_loss_from_tfevent_file(tfevent_filename):
    """

    :param tfevent_filename: the name of one tfevent file
    :return: loss (list)
    """
    loss_val_list = []
    for event in tf.train.summary_iterator(tfevent_filename):
        for value in event.summary.value:
            # print(value.tag)
            if value.HasField('simple_value'):
                if value.tag == "loss":
                    # print(value.simple_value)
                    loss_val_list.append(value.simple_value)

    return loss_val_list

函数输入为tfevent文件名,输出为loss取值列表。注意如需读取其他变量值,可以修改函数中value.tag项。

你可能感兴趣的:(Deep,Learning,tf,event,tensorflow,python)