Skip to content

Instantly share code, notes, and snippets.

@hysts
Last active November 6, 2020 13:51
Show Gist options
  • Save hysts/35ddba717a7846bba5c7d53b6410d4f4 to your computer and use it in GitHub Desktop.
Save hysts/35ddba717a7846bba5c7d53b6410d4f4 to your computer and use it in GitHub Desktop.
Extract scalars from Tensorboard log
#!/usr/bin/env python
import argparse
import json
import pathlib
from tensorboard.backend.event_processing import event_accumulator
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--path', type=str, required=True)
parser.add_argument('--outdir', type=str, required=True)
args = parser.parse_args()
event_acc = event_accumulator.EventAccumulator(
args.path, size_guidance={'scalars': 0})
event_acc.Reload()
scalars = {}
for tag in event_acc.Tags()['scalars']:
events = event_acc.Scalars(tag)
scalars[tag] = [event.value for event in events]
outdir = pathlib.Path(args.outdir)
outdir.mkdir(exist_ok=True, parents=True)
outpath = outdir / 'all_scalars.json'
with open(outpath, 'w') as fout:
json.dump(scalars, fout)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment