读取tensorboard日志数据

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/nima1994/article/details/82844988

问题描述

目前的问题是,使用keras的callback将日志数据(acc、loss、val_acc、val_loss)写入文件,然后使用Tensorboard在浏览器查看变化,现在打算读出相关数据,并自行绘图。

解决方案

from tensorboard.backend.event_processing import event_accumulator

#加载日志数据
ea=event_accumulator.EventAccumulator(r'E:\Code\lastExp\output\logs\pm_last\events.out.tfevents.1535713476.DESKTOP-KMHR70T') 
ea.Reload()
print(ea.scalars.Keys())

val_acc=ea.scalars.Items('val_acc')
print(len(val_acc))
print([(i.step,i.value) for i in val_acc])

import matplotlib.pyplot as plt
fig=plt.figure(figsize=(6,4))
ax1=fig.add_subplot(111)
val_acc=ea.scalars.Items('val_acc')
ax1.plot([i.step for i in val_acc],[i.value for i in val_acc],label='val_acc')
ax1.set_xlim(0)
acc=ea.scalars.Items('acc')
ax1.plot([i.step for i in acc],[i.value for i in acc],label='acc')
ax1.set_xlabel("step")
ax1.set_ylabel("")

plt.legend(loc='lower right')
plt.show()

输出如下:

[‘val_loss’, ‘val_acc’, ‘loss’, ‘acc’]
500
[(0, 0.34734734892845154), (1, 0.4454454481601715), (2, 0.42184367775917053), (3, 0.5355355143547058), …

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/nima1994/article/details/82844988
今日推荐