Skip to content

Instantly share code, notes, and snippets.

@tomrunia
Created July 13, 2016 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomrunia/b2da1c31f3dc3f139a47b02567e25098 to your computer and use it in GitHub Desktop.
Save tomrunia/b2da1c31f3dc3f139a47b02567e25098 to your computer and use it in GitHub Desktop.
import os
import sys
import pickle
import numpy as np
import tensorflow as tf
from tensorflow.python.summary.event_accumulator import EventAccumulator
event_file = "/home/trunia1/dev/python/LSTMCounting/output/screens/" \
"summaries/004_rmsprop_0.0005_lstm_512x2_grad_10_batch_128_dropkp_0.75/" \
"events.out.tfevents.1468336776.DTA16004"
size_guidance = {
'compressedHistograms': 1,
'images': 1,
'audio': 1,
'scalars': 10000,
'histograms': 1,
}
event_acc = EventAccumulator(event_file, size_guidance=size_guidance)
event_acc.Reload()
tags = event_acc.Tags()
print(tags)
tags_to_save = [
"loss/total",
"loss/classification",
"loss/attention_explore",
"loss/attention_smooth",
"loss/weight_decay",
"train/abs_error",
"train/examples_per_second",
"train/learning_rate",
"train/mse_error",
"train/predictions_non_zero",
"validation/loss",
"validation/mse_error"
]
output_dir = os.path.join(os.path.dirname(event_file), "scalar_events")
if not os.path.exists(output_dir):
os.makedirs(output_dir)
for tag in tags_to_save:
if tag not in tags['scalars']:
print("Skipping tag '%s' because no events founds in file." % tag)
continue
print("Exporting events for tag '%s'..." % tag)
# ScalarEvent(wall_time=double, step=1L, value=double)
events = event_acc.Scalars(tag)
data = np.zeros([len(events), 2], dtype=np.float32)
for step in range(len(events)):
data[step, 0] = float(events[step].step)
data[step, 1] = float(events[step].value)
#print(data[step,])
output_file = os.path.join(output_dir, tag.replace('/', '_') + ".pickle")
pickle.dump(data, open(output_file, 'w'))
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment