-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
48 lines (41 loc) · 1.37 KB
/
plot.py
File metadata and controls
48 lines (41 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import tensorflow as tf
import matplotlib.pyplot as plt
import pandas as pd
def plot_run(name, log):
# Gather data
reward = []
run_len = []
for e in tf.compat.v1.train.summary_iterator(log):
for v in e.summary.value:
if v.tag == 'rollout/ep_rew_mean':
reward.append({
'step': e.step,
'value': v.simple_value
})
if v.tag == 'rollout/ep_len_mean':
run_len.append({
'step': e.step,
'value': v.simple_value
})
reward_df = pd.DataFrame(reward)
run_len_df = pd.DataFrame(run_len)
plt.figure(figsize=(4,4))
plt.title('Mean episode length')
plt.xlabel('step')
plt.ylabel('length')
plt.grid()
plt.tight_layout()
plt.plot(run_len_df.step, run_len_df.value)
plt.savefig(f'plots/ppo_length_{name}.png')
plt.clf()
plt.figure(figsize=(4,4))
plt.title('Mean episode reward')
plt.xlabel('step')
plt.ylabel('reward')
plt.grid()
plt.tight_layout()
plt.plot(reward_df.step, reward_df.value)
plt.savefig(f'plots/ppo_reward_{name}.png')
if __name__ == '__main__':
plot_run('1m', 'logs\PPO_13\events.out.tfevents.1746853937.JOHN-LAPTOP.33828.0')
plot_run('2m', 'logs\PPO_14\events.out.tfevents.1746855975.JOHN-LAPTOP.40200.0')