tensorboard中的loss曲线在网页中可以通过设置平滑参数,画出比较漂亮的曲线,但是平滑后的曲线是没办法直接提取出来的
这里我们直接从tensorboard的页面中点击Show data download links,然后把曲线的csv文件下载下来,通过下面的代码平滑处理:
定义smooth函数,输入tensorboard下载的csv,然后保存平滑之后的csv文件
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('lo