-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge_eventfiles.py
More file actions
71 lines (56 loc) · 2.48 KB
/
Copy pathmerge_eventfiles.py
File metadata and controls
71 lines (56 loc) · 2.48 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (c) 2026 Electronic Arts Inc. All rights reserved. See LICENSE for details.
import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
def load_event_file(event_file):
event_acc = EventAccumulator(event_file, size_guidance={'scalars': 0})
event_acc.Reload()
tags = event_acc.Tags()["scalars"]
data = {tag: [] for tag in tags}
for tag in tags:
events = event_acc.Scalars(tag)
data[tag] = [(e.step, e.value) for e in events]
return data
def merge_event_files(original_event_file, new_event_file, output_file):
original_data = load_event_file(original_event_file)
new_data = load_event_file(new_event_file)
# Determine the maximum step and wall time in the original event file
max_step = {}
for tag in original_data.keys():
# initialize the max_step and max_wall_time
max_step[tag] = 0
if original_data[tag]:
max_step[tag] = original_data[tag][-1][0]
# Offset the steps and wall times in the new event file
for tag in new_data.keys():
for i in range(len(new_data[tag])):
step, value = new_data[tag][i]
new_data[tag][i] = (step + max_step[tag], value)
# Merge the data
merged_data = {tag: [] for tag in original_data.keys()}
for tag in original_data.keys():
if tag not in new_data.keys():
merged_data[tag] = original_data[tag]
else:
merged_data[tag] = original_data[tag] + new_data[tag]
merged_data[tag].sort(key=lambda x: x[0])
tf.compat.v1.disable_v2_behavior()
metrics = [
'Rollout/agent_0/reward',
'Rollout/agent_0/win',
'Rollout/agent_0/lose',
'Training/agent_0/value_loss',
'Training/agent_0/policy_loss',
'Training/agent_0/entropy'
]
with tf.compat.v1.summary.FileWriter(output_file) as writer:
for tag in metrics:
for step, value in merged_data[tag]:
summary = tf.compat.v1.Summary(value=[tf.compat.v1.Summary.Value(tag=tag, simple_value=value)])
writer.add_summary(summary, global_step=step)
writer.flush()
writer.close()
if __name__ == "__main__":
file1 = 'path/to/first/eventfile'
file2 = 'path/to/second/eventfile'
output_file = 'path/to/output/directory/'
merge_event_files(file1, file2, output_file)