-
-
Save ethan-funny/a3a570fd32136ba34551fd3b9d1bc05f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import datetime | |
import pytz | |
from tensorflow.contrib.session_bundle import exporter | |
from tensorflow.python.client import timeline | |
import glob | |
import json | |
import time | |
import math | |
import numpy as np | |
import os | |
import tensorflow as tf | |
steps_to_validate = 20 | |
epoch_number = 2 | |
thread_number = 2 | |
batch_size = 100 | |
min_after_dequeue = 1000 | |
capacity = thread_number * batch_size + min_after_dequeue | |
filename = "20161227/*.zlib" | |
filename_queue = tf.train.string_input_producer( | |
tf.train.match_filenames_once(filename), | |
shuffle=True, | |
seed = int(time.time()), | |
num_epochs=epoch_number) | |
def read_and_decode(filename_queue): | |
reader = tf.TFRecordReader(options = tf.python_io.TFRecordOptions(tf.python_io.TFRecordCompressionType.ZLIB)) | |
_, serialized_example = reader.read(filename_queue) | |
return serialized_example | |
serialized_example = read_and_decode(filename_queue) | |
batch_serialized_example = tf.train.shuffle_batch( | |
[serialized_example], | |
batch_size=batch_size, | |
num_threads=thread_number, | |
capacity=capacity, | |
min_after_dequeue=min_after_dequeue) | |
features = tf.parse_example( | |
batch_serialized_example, | |
features={ | |
"label": tf.FixedLenFeature([], tf.float32), | |
"ids": tf.VarLenFeature(tf.int64), | |
"values": tf.VarLenFeature(tf.float32), | |
}) | |
batch_labels = features["label"] | |
batch_ids = features["ids"] | |
batch_values = features["values"] | |
init_op = tf.global_variables_initializer() | |
with tf.Session() as sess: | |
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | |
run_metadata = tf.RunMetadata() | |
sess.run(init_op,options=run_options, run_metadata=run_metadata) | |
sess.run(tf.local_variables_initializer(),options=run_options, run_metadata=run_metadata) | |
coord = tf.train.Coordinator() | |
threads = tf.train.start_queue_runners(coord=coord, sess=sess) | |
start_time = datetime.datetime.now(pytz.timezone('Asia/Shanghai')) | |
step = 1 | |
try: | |
while not coord.should_stop(): | |
f1,f2,f3 = sess.run([batch_ids,batch_values,batch_labels],options=run_options, run_metadata=run_metadata) | |
step +=1 | |
if step % steps_to_validate == 0: | |
end_time = datetime.datetime.now(pytz.timezone('Asia/Shanghai')) | |
sec = (end_time - start_time).total_seconds() | |
print("[{}] time[{:6.2f}] step[{:10d}] speed[{:6d}]".format( | |
str(end_time).split(".")[0],sec, step, | |
int((steps_to_validate*batch_size)/sec) | |
)) | |
start_time = end_time | |
if step > 2000: | |
break | |
except tf.errors.OutOfRangeError: | |
print("Done training after reading all data") | |
finally: | |
coord.request_stop() | |
print("coord stopped") | |
coord.join(threads) | |
tl = timeline.Timeline(run_metadata.step_stats) | |
ctf = tl.generate_chrome_trace_format() | |
with open('timeline.json', 'w') as f: | |
f.write(ctf) | |
print "all done" |
This file contains hidden or 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
{ | |
"traceEvents": [ | |
{ | |
"ph": "M", | |
"args": { | |
"name": "Allocators" | |
}, | |
"pid": 0, | |
"name": "process_name" | |
}, | |
{ | |
"ph": "M", | |
"args": { | |
"name": "/job:localhost/replica:0/task:0/cpu:0 Compute" | |
}, | |
"pid": 1, | |
"name": "process_name" | |
}, | |
{ | |
"ph": "M", | |
"args": { | |
"name": "/job:localhost/replica:0/task:0/cpu:0 Tensors" | |
}, | |
"pid": 2, | |
"name": "process_name" | |
}, | |
{ | |
"name": "NoOp", | |
"args": { | |
"name": "_SOURCE", | |
"op": "NoOp" | |
}, | |
"pid": 1, | |
"ts": 1484406792814677, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 4 | |
}, | |
{ | |
"name": "Const", | |
"args": { | |
"name": "shuffle_batch/n", | |
"op": "Const" | |
}, | |
"pid": 1, | |
"ts": 1484406792814687, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 6 | |
}, | |
{ | |
"name": "RandomShuffleQueue", | |
"args": { | |
"name": "shuffle_batch/random_shuffle_queue", | |
"op": "RandomShuffleQueue" | |
}, | |
"pid": 1, | |
"ts": 1484406792814689, | |
"cat": "Op", | |
"tid": 1, | |
"ph": "X", | |
"dur": 7 | |
}, | |
{ | |
"name": "Const", | |
"args": { | |
"name": "ParseExample/Const", | |
"op": "Const" | |
}, | |
"pid": 1, | |
"ts": 1484406792814695, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 4 | |
}, | |
{ | |
"name": "Const", | |
"args": { | |
"name": "ParseExample/ParseExample/names", | |
"op": "Const" | |
}, | |
"pid": 1, | |
"ts": 1484406792814701, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 4 | |
}, | |
{ | |
"name": "Const", | |
"args": { | |
"name": "ParseExample/ParseExample/sparse_keys_0", | |
"op": "Const" | |
}, | |
"pid": 1, | |
"ts": 1484406792814708, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 4 | |
}, | |
{ | |
"name": "Const", | |
"args": { | |
"name": "ParseExample/ParseExample/sparse_keys_1", | |
"op": "Const" | |
}, | |
"pid": 1, | |
"ts": 1484406792814714, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 5 | |
}, | |
{ | |
"name": "Const", | |
"args": { | |
"name": "ParseExample/ParseExample/dense_keys_0", | |
"op": "Const" | |
}, | |
"pid": 1, | |
"ts": 1484406792814721, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 4 | |
}, | |
{ | |
"name": "QueueDequeueMany", | |
"args": { | |
"input0": "shuffle_batch/random_shuffle_queue", | |
"input1": "shuffle_batch/n", | |
"name": "shuffle_batch", | |
"op": "QueueDequeueMany" | |
}, | |
"pid": 1, | |
"ts": 1484406792814699, | |
"cat": "Op", | |
"tid": 1, | |
"ph": "X", | |
"dur": 8889 | |
}, | |
{ | |
"name": "shuffle_batch/n", | |
"pid": 1, | |
"ts": 1484406792814693, | |
"cat": "DataFlow", | |
"tid": 0, | |
"ph": "s", | |
"id": 0 | |
}, | |
{ | |
"name": "shuffle_batch/n", | |
"pid": 1, | |
"ts": 1484406792814699, | |
"cat": "DataFlow", | |
"tid": 1, | |
"ph": "t", | |
"id": 0 | |
}, | |
{ | |
"name": "ParseExample", | |
"args": { | |
"input2": "ParseExample/ParseExample/sparse_keys_0", | |
"input3": "ParseExample/ParseExample/sparse_keys_1", | |
"input0": "shuffle_batch", | |
"input1": "ParseExample/ParseExample/names", | |
"name": "ParseExample/ParseExample", | |
"input4": "ParseExample/ParseExample/dense_keys_0", | |
"input5": "ParseExample/Const", | |
"op": "ParseExample" | |
}, | |
"pid": 1, | |
"ts": 1484406792823598, | |
"cat": "Op", | |
"tid": 0, | |
"ph": "X", | |
"dur": 233 | |
}, | |
{ | |
"name": "shuffle_batch", | |
"pid": 1, | |
"ts": 1484406792823588, | |
"cat": "DataFlow", | |
"tid": 1, | |
"ph": "s", | |
"id": 1 | |
}, | |
{ | |
"name": "shuffle_batch", | |
"pid": 1, | |
"ts": 1484406792823598, | |
"cat": "DataFlow", | |
"tid": 0, | |
"ph": "t", | |
"id": 1 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment