【问题标题】:Tensorboard smoothing张量板平滑
【发布时间】:2020-06-26 06:18:23
【问题描述】:

我从 tesnorboard 下载了 CSV 文件,以便自己绘制损失,因为我希望它们平滑。

这是我目前的代码:

import pandas as pd

import numpy as np

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('C:\\Users\\ali97\\Desktop\\Project\\Database\\Comparing Outlier Fractions\\10 Percent (MAE)\\MSE Validation.csv',usecols=['Step','Value'],low_memory=True)

df2 = pd.read_csv('C:\\Users\\ali97\\Desktop\\Project\\Database\\Comparing Outlier Fractions\\15 Percent (MAE)\\MSE Validation.csv',usecols=['Step','Value'],low_memory=True)

df3 = pd.read_csv('C:\\Users\\ali97\\Desktop\\Project\\Database\\Comparing Outlier Fractions\\20 Percent (MAE)\\MSE Validation.csv',usecols=['Step','Value'],low_memory=True)




plt.plot(df['Step'],df['Value'] , 'r',label='10% Outlier Frac.' )
plt.plot(df2['Step'],df2['Value'] , 'g',label='15% Outlier Frac.' )
plt.plot(df3['Step'],df3['Value'] , 'b',label='20% Outlier Frac.' )

plt.xlabel('Epochs')
plt.ylabel('Validation score')
plt.show()

我正在阅读如何平滑图形,我发现这里的另一个成员编写了关于 tensorboard 如何实际平滑图形的代码,但我真的不知道如何在我的代码中实现它。

def smooth(scalars: List[float], weight: float) -> List[float]:  # Weight between 0 and 1
    last = scalars[0]  # First value in the plot (first timestep)
    smoothed = list()
    for point in scalars:
        smoothed_val = last * weight + (1 - weight) * point  # Calculate smoothed value
        smoothed.append(smoothed_val)                        # Save it
        last = smoothed_val                                  # Anchor the last smoothed value



    return smoothed

谢谢。

【问题讨论】:

    标签: python tensorflow tensorboard


    【解决方案1】:

    如果您正在使用 pandas 库,您可以使用函数 ewm (Pandas EWM) 并调整 alpha 因子以获得来自 tensorboard 的平滑函数的良好近似值。

    df.ewm(alpha=(1 - ts_factor)).mean()
    

    CSV 文件 mse_data.csv

               step      value
    0      0.000000   9.716303
    1      0.200401   9.753981
    2      0.400802   9.724551
    3      0.601202   7.926591
    4      0.801603  10.181700
    ..          ...        ...
    495   99.198400   0.298243
    496   99.398800   0.314511
    497   99.599200  -1.119387
    498   99.799600  -0.374202
    499  100.000000   1.150465
    
    import pandas as pd
    import matplotlib.pyplot as plt
    
    df = pd.read_csv("mse_data.csv")
    print(df)
    
    TSBOARD_SMOOTHING = [0.5, 0.85, 0.99]
    
    smooth = []
    for ts_factor in TSBOARD_SMOOTHING:
        smooth.append(df.ewm(alpha=(1 - ts_factor)).mean())
    
    for ptx in range(3):
        plt.subplot(1,3,ptx+1)
        plt.plot(df["value"], alpha=0.4)
        plt.plot(smooth[ptx]["value"])
        plt.title("Tensorboard Smoothing = {}".format(TSBOARD_SMOOTHING[ptx]))
        plt.grid(alpha=0.3)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2018-01-11
      • 1970-01-01
      • 2018-02-26
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 2016-12-12
      • 1970-01-01
      • 2021-08-08
      相关资源
      最近更新 更多