Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support old-style TensorFlow events (tensorboard) #2467

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@
import rfc3339
import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
from tensorboard.backend.event_processing.tag_types import TENSORS
from tensorboard.backend.event_processing.tag_types import SCALARS, TENSORS

from pkg.metricscollector.v1beta1.common import const


def _should_consider(tag: str, metric_name: str, tfefile: str) -> bool:
tfefile_parent_dir = (
os.path.dirname(metric_name)
if len(metric_name.split("/")) >= 2
else os.path.dirname(tfefile)
)
basedir_name = os.path.dirname(tfefile)
return tag.startswith(metric_name.split("/")[-1]) and basedir_name.endswith(
tfefile_parent_dir
)


class TFEventFileParser:
def __init__(self, metric_names):
self.metric_names = metric_names
Expand All @@ -47,21 +59,15 @@ def find_all_files(directory):

def parse_summary(self, tfefile):
metric_logs = []
event_accumulator = EventAccumulator(tfefile, size_guidance={TENSORS: 0})
event_accumulator = EventAccumulator(
tfefile, size_guidance={SCALARS: 0, TENSORS: 0}
)
event_accumulator.Reload()
for tag in event_accumulator.Tags()[TENSORS]:
tags = event_accumulator.Tags()
for tag in tags[TENSORS]:
for m in self.metric_names:
tfefile_parent_dir = (
os.path.dirname(m)
if len(m.split("/")) >= 2
else os.path.dirname(tfefile)
)
basedir_name = os.path.dirname(tfefile)
if not tag.startswith(m.split("/")[-1]) or not basedir_name.endswith(
tfefile_parent_dir
):
if not _should_consider(tag, m, tfefile):
continue

for tensor in event_accumulator.Tensors(tag):
ml = api_pb2.MetricLog(
time_stamp=rfc3339.rfc3339(
Expand All @@ -72,7 +78,19 @@ def parse_summary(self, tfefile):
),
)
metric_logs.append(ml)

# support old-style tensorboard metrics too
for tag in tags[SCALARS]:
for m in self.metric_names:
if not _should_consider(tag, m, tfefile):
continue
for scalar in event_accumulator.Scalars(tag):
ml = api_pb2.MetricLog(
time_stamp=rfc3339.rfc3339(
datetime.fromtimestamp(scalar.wall_time)
),
metric=api_pb2.Metric(name=m, value=str(scalar.value)),
)
metric_logs.append(ml)
return metric_logs


Expand Down