Created
July 10, 2018 16:11
-
-
Save willwhitney/9cecd56324183ef93c2424c9aa7a31b4 to your computer and use it in GitHub Desktop.
load tensorboard log files into pandas dataframes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorboard.backend.event_processing import event_accumulator | |
import tensorflow as tf | |
import glob | |
import pandas as pd | |
tf.logging.set_verbosity(tf.logging.ERROR) | |
basedir = "/path/to/log/directory/" | |
def load_tf(dirname): | |
prefix = basedir + "tboard/VisibleSwimmer-v2/" | |
dirname = prefix + dirname | |
dirname = glob.glob(dirname + '/*')[0] | |
ea = event_accumulator.EventAccumulator(dirname, size_guidance={event_accumulator.SCALARS: 0}) | |
ea.Reload() | |
dframes = {} | |
mnames = ea.Tags()['scalars'] | |
for n in mnames: | |
dframes[n] = pd.DataFrame(ea.Scalars(n), columns=["wall_time", "epoch", n.replace('val/', '')]) | |
dframes[n].drop("wall_time", axis=1, inplace=True) | |
dframes[n] = dframes[n].set_index("epoch") | |
return pd.concat([v for k,v in dframes.items()], axis=1) | |
def load_tf_jobs(regex): | |
prefix = basedir + "results/" | |
job_dirs = glob.glob(prefix + regex) | |
rows = [] | |
for job in job_dirs: | |
job_name = os.path.basename(os.path.normpath(job)) | |
# this loads in all the hyperparams from another file, | |
# do your own thing here instead | |
options = load_json(job + '/opt.json') | |
try: | |
results = load_tf(job.replace(prefix, '')) | |
except: | |
continue | |
for opt in options: | |
results[opt] = options[opt] | |
rows.append(results) | |
for row in rows: | |
row['epoch'] = row.index | |
row.reset_index(drop=True, inplace=True) | |
df = pd.concat(rows) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment