从TensorBoard中导出数据并对其进行平滑处理

本文介绍了如何从TensorBoard导出训练数据,包括两种方法:通过界面控件和使用代码。同时,由于默认限制只导出10000条数据,文章提供了解决方案,在启动TensorBoard时设置参数以导出所有数据。此外,还分享了如何在本地对下载的原始数据进行平滑处理的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、 导出TensorBoard中的数据

1. 方式一:利用TensorBoard界面控件导出

1、在TensorBoard 页面右边框中有一个Show data download links 选项,勾选后就可以在图表下方看见下载标志,具体步骤如下图所示:
在这里插入图片描述

2.方式二:利用代码方式导出

导出TensorBoard中数据的代码如下所示:

from tensorboard.backend.event_processing import event_accumulator
 
#加载日志数据
ea=event_accumulator.EventAccumulator('events.out.tfevents.1550994567.vvd-Inspiron-7557') 
ea.Reload()
print(ea.scalars.Keys())
 
val_psnr=ea.scalars.Items('val_psnr')
print(len(val_psnr))
print([(i.step,i.value) for i in val_psnr])

导出结果:

['val_loss', 'val_psnr', 'loss', 'psnr', 'lr']
29
[(0, 33.70820617675781), (1, 34.52505874633789), (2, 34.26629638671875), (3, 35.47195053100586), (4, 35.45940017700195), (5, 35.336708068847656), (6, 35.467647552490234), (7, 35.919857025146484), (8, 35.29727554321289), (9, 35.63655471801758), (10, 36.219871520996094), (11, 36.178646087646484), (12, 35.93777847290039), (13, 35.587406158447266), (14, 36.198944091796875), (15, 36.241966247558594), (16, 36.379913330078125), (17, 36.28306198120117), (18, 36.03053665161133), (19, 36.20806121826172), (20, 36.21710968017578), (21, 36.42262268066406), (22, 36.00306701660156), (23, 36.4374885559082), (24, 36.163787841796875), (25, 36.53673553466797), (26, 35.99557113647461), (27, 36.96220016479492), (28, 36.63676452636719)]

3.总结

上述这两种方式都存在一个问题,从TensorBoard导出的数据只有10000条。但是我们需要的是导出所有的数据。
解决方法:在启动TensorBoard的时加上参数–samples_per_plugin scalars=0 如:

tensorboard --samples_per_plugin scalars=0

再利用第一种方式从TensorBoard页面中下载数据,此时就可下载所有数据了。

2、数据平滑处理

tensorboard提供了下载接口Show data download links ,可以下载没有进行平滑处理的数据,将下载的原始数据在本地进行平滑处理。代码如下所示:

import pandas as pd
import numpy as np
import os
def smooth(csv_path,weight=0.85):
    data = pd.read_csv(filepath_or_buffer=csv_path,header=0,names=['Step','Value'],dtype={'Step':np.int,'Value':np.float})
    scalar = data['Value'].values
    last = scalar[0]
    smoothed = []
    for point in scalar:
        smoothed_val = last * weight + (1 - weight) * point
        smoothed.append(smoothed_val)
        last = smoothed_val

    save = pd.DataFrame({'Step':data['Step'].values,'Value':smoothed})
    save.to_csv('smooth_'+csv_path)

if __name__=='__main__':
    smooth('test.csv')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值