Add graphs

This commit is contained in:
Vedant Dave 2023-05-25 17:53:46 +02:00
parent 82e8a23918
commit 8b79f49bb9

View File

@ -1,10 +1,11 @@
import os import os
import numpy as np
import pandas as pd import pandas as pd
import seaborn as sns import seaborn as sns
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
"""
def tabulate_events(dpath): def tabulate_events(dpath):
files = os.listdir(dpath)[0] files = os.listdir(dpath)[0]
summary_iterators = [EventAccumulator(os.path.join(dpath, files)).Reload()] summary_iterators = [EventAccumulator(os.path.join(dpath, files)).Reload()]
@ -43,7 +44,43 @@ for tag, values in events.items():
df = pd.DataFrame(data) df = pd.DataFrame(data)
print(df.head()) print(df.head())
exit()
plt.figure(figsize=(10,6)) plt.figure(figsize=(10,6))
sns.lineplot(data=df, x='step', y='value', hue='tag', ci='sd') sns.lineplot(data=df, x='step', y='value', hue='tag', ci='sd')
plt.show()
"""
from tensorboard.backend.event_processing import event_accumulator
def data_from_tb(files):
all_steps, all_rewards = [], []
for file in files:
ea = event_accumulator.EventAccumulator(file, size_guidance={'scalars': 0})
ea.Reload()
episode_rewards = ea.Scalars('train/episode_reward')
steps = [event.step for event in episode_rewards][:990000]
rewards = [event.value for event in episode_rewards][:990000]
all_steps.append(steps)
all_rewards.append(rewards)
return all_steps, all_rewards
files = ['/home/vedant/pytorch_sac_ae/log/runs/tb_21_05_2023-13_19_36/events.out.tfevents.1684667976.cpswkstn6-nvidia4090.1749060.0',
'/home/vedant/pytorch_sac_ae/log/runs/tb_22_05_2023-09_56_30/events.out.tfevents.1684742190.cpswkstn6-nvidia4090.1976229.0']
all_steps, all_rewards = data_from_tb(files)
mean_rewards = np.mean(all_rewards, axis=0)
std_rewards = np.std(all_rewards, axis=0)
mean_steps = np.mean(all_steps, axis=0)
df = pd.DataFrame({'Steps': mean_steps,'Rewards': mean_rewards,'Standard Deviation': std_rewards})
sns.relplot(x='Steps', y='Rewards', kind='line', data=df, ci="sd")
plt.fill_between(df['Steps'], df['Rewards'] - df['Standard Deviation'], df['Rewards'] + df['Standard Deviation'], color='b', alpha=.1)
plt.title("Mean Rewards vs Steps with Standard Deviation")
plt.show() plt.show()