Loading

打印tensorboard记录的数据(解决tf2下的问题)

读取并导出Tensorboard中数据
读取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()

tf2报错

在使用tf2.x的时候,执行上述代码会报错,AttributeError: module 'tensorflow._api.v2.errors' has no attribute 'raise_exception_on_not_ok_status',解决办法是卸载tensorboard,按照 https://github.com/tensorflow/tensorboard/issues/2619 的说法,Please uninstall any copies of tensorboard or tb-nightly that you may have installed, and then run pip install tb-nightly to grab the latest version. 进行适配,便可以直接使用了~

posted @ 2022-12-17 16:20  戴墨镜的长颈鹿  阅读(167)  评论(0编辑  收藏  举报