从tensorboard导出数据,自己用python画折线图

有大佬有更好的方法,请狠狠踢我,我很爱学习的!!

写论文时,我们可能需要这样的:

但是tensorboard展示的是这样的(虽然tensorboard可以导出svg,但是使用visio去除不了背景,同门亲手验证的):

 办法就是从tensorboard导出csv,然后自己用python画,还能设置标签:



import matplotlib.pyplot as plt
import pandas as pd

#做平滑处理,我觉得应该可以理解为减弱毛刺,,吧  能够更好地看数据走向
def tensorboard_smoothing(x,smooth=0.99):
    x = x.copy()
    weight = smooth
    for i in range(1,len(x)):
        x[i] = (x[i-1] * weight + x[i]) / (weight + 1)
        weight = (weight + 1) * smooth
    return x

if __name__ == '__main__':
    
    fig, ax1 = plt.subplots(1, 1)    # a figure with a 1x1 grid of Axes
    
    #设置上方和右方无框
    ax1.spines['top'].set_visible(False)                   # 不显示图表框的上边框
    ax1.spines['right'].set_visible(False)  
 
    len_mean = pd.read_csv("run-FedDC_0.01Resnet18_S20_F1.000000_Lr0.001000_1_1.000000_B16_E5_W0.000100_a0.010000_seed0_lrdecay0.998000_Accuracy_train_Current cloud-tag-Accuracy_train.csv")
  

    #设置折线颜色,折线标签
    #使用平滑处理
    ax1.plot(len_mean['Step'], tensorboard_smoothing(len_mean['Value'], smooth=0.6), color="red",label='all_data')
    #不使用平滑处理
    # ax1.plot(len_mean['Step'], len_mean['Value'], color="red",label='all_data')


    #s设置标签位置,lower upper left right,上下和左右组合
    plt.legend(loc = 'lower right')

   
    ax1.set_xlabel("epoch")
    ax1.set_ylabel("accuracy")
    ax1.set_title("test Accuracy")
    plt.show()
    #保存图片,也可以是其他格式,如pdf
    fig.savefig(fname='./a2'+'.png', format='png')

要不要使用平滑,可以看一下下面的图:

 突然发现我在tensorboard的图也平滑了。。

 

参考:

【深度学习】tensorboard中的图片放到论文中

  • 12
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值