读取tensorboard的event数据图表再用plot绘制保存

from tensorboard.backend.event_processing import event_accumulator
import matplotlib.pyplot as plt
 
def read_tensorboard_data(tensorboard_path, val_name):
    """读取tensorboard数据,
    tensorboard_path是tensorboard数据地址val_name是需要读取的变量名称"""
    ea = event_accumulator.EventAccumulator(tensorboard_path)
    ea.Reload()
    print(ea.scalars.Keys())
    val = ea.scalars.Items(val_name)
    return val
 
def draw_plt(val, val_name):
    """将数据绘制成曲线图,val是数据,val_name是变量名称"""
    plt.figure()
    plt.plot([i.step for i in val], [j.value for j in val], label=val_name)
    """横坐标是step,迭代次数
    纵坐标是变量值"""
    plt.xlabel('step')
    plt.ylabel(val_name)
    plt.show()
 
if __name__ == "__main__":
    tensorboard_path = 'G:\events.out.tfevents.1562917214.omnisky'
    val_name = 'cross_entropy'
    val = read_tensorboard_data(tensorboard_path, val_name)
    draw_plt(val, val_name)

 

你可能感兴趣的:(学习工具及问题记录)