Tensorboard平滑

问题描述 投票:0回答:1

我从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()

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

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个回答
0
投票

如果您正在使用pandas库,则可以使用函数ewmPandas EWM)并调整alpha因子以从张量板获得平滑函数的良好近似。

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()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.