4
def read_data_from_tensorboard(log_path, tag):
5
"""Get raw data (steps and values) from tensorboard events.
8
log_path (str): Path to the tensorboard log.
9
tag (str): tag to be read.
11
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
14
event_acc = EventAccumulator(log_path)
16
scalar_list = event_acc.Tags()['scalars']
17
print('tag list: ', scalar_list)
18
steps = [int(s.step) for s in event_acc.Scalars(tag)]
19
values = [s.value for s in event_acc.Scalars(tag)]
23
def read_data_from_txt_2v(path, pattern, step_one=False):
24
"""Read data from txt with 2 returned values (usually [step, value]).
27
path (str): path to the txt file.
28
pattern (str): re (regular expression) pattern.
29
step_one (bool): add 1 to steps. Default: False.
33
lines = [line.strip() for line in lines]
37
pattern = re.compile(pattern)
39
match = pattern.match(line)
41
steps.append(int(match.group(1)))
42
values.append(float(match.group(2)))
44
steps = [v + 1 for v in steps]
48
def read_data_from_txt_1v(path, pattern):
49
"""Read data from txt with 1 returned values.
52
path (str): path to the txt file.
53
pattern (str): re (regular expression) pattern.
57
lines = [line.strip() for line in lines]
60
pattern = re.compile(pattern)
62
match = pattern.match(line)
64
data.append(float(match.group(1)))
68
def smooth_data(values, smooth_weight):
69
""" Smooth data using 1st-order IIR low-pass filter (what tensorflow does).
71
Reference: https://github.com/tensorflow/tensorboard/blob/f801ebf1f9fbfe2baee1ddd65714d0bccc640fb1/tensorboard/plugins/scalar/vz_line_chart/vz-line-chart.ts#L704 # noqa: E501
74
values (list): A list of values to be smoothed.
75
smooth_weight (float): Smooth weight.
78
last_sm_value = values[0]
80
value_sm = last_sm_value * smooth_weight + (1 - smooth_weight) * value
81
values_sm.append(value_sm)
82
last_sm_value = value_sm