From 8b79f49bb928df881d8c3454ee54309d6f84a099 Mon Sep 17 00:00:00 2001 From: Vedant Dave Date: Thu, 25 May 2023 17:53:46 +0200 Subject: [PATCH] Add graphs --- graphs_plot.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/graphs_plot.py b/graphs_plot.py index 6e99084..9e8178e 100644 --- a/graphs_plot.py +++ b/graphs_plot.py @@ -1,10 +1,11 @@ import os +import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from tensorboard.backend.event_processing.event_accumulator import EventAccumulator - +""" def tabulate_events(dpath): files = os.listdir(dpath)[0] summary_iterators = [EventAccumulator(os.path.join(dpath, files)).Reload()] @@ -43,7 +44,43 @@ for tag, values in events.items(): df = pd.DataFrame(data) print(df.head()) +exit() plt.figure(figsize=(10,6)) 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() \ No newline at end of file