Created
October 16, 2019 03:22
-
-
Save enh6/02dc72a1a948cb45f42d93424d3ff296 to your computer and use it in GitHub Desktop.
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
import sys | |
import tensorflow as tf | |
pb_file = sys.argv[1] | |
log_dir = 'logdir' | |
with open(pb_file, "rb") as f: | |
g_def = tf.GraphDef() | |
g_def.ParseFromString(f.read()) | |
tf.import_graph_def(g_def) | |
import tempfile | |
import os | |
with tempfile.TemporaryDirectory() as log_dir: | |
tf.summary.FileWriter(log_dir, tf.get_default_graph()) | |
os.system('tensorboard --logdir=' + log_dir) | |
#timeline | |
from tensorflow.python.client import timeline | |
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | |
run_metadata = tf.RunMetadata() | |
for loop in range(8): | |
sess.run(output_node, feed_dict = {}, options=run_options, run_metadata=run_metadata) | |
tl = timeline.Timeline(run_metadata.step_stats) | |
ctf = tl.generate_chrome_trace_format() | |
with open('timeline.json', 'w') as f: | |
f.write(ctf) | |
#profile | |
from tensorflow.python.profiler import model_analyzer | |
from tensorflow.python.profiler import option_builder | |
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | |
run_metadata = tf.RunMetadata() | |
profiler = model_analyzer.Profiler(graph=sess.graph) | |
for loop in range(8): | |
sess.run(output_node, feed_dict = {}, options=run_options, run_metadata=run_metadata) | |
profiler.add_step(step=loop, run_meta=run_metadata) | |
profile_op_opt_builder = option_builder.ProfileOptionBuilder() | |
profile_op_opt_builder.select(['micros','occurrence', 'float_ops', 'input_shapes']) | |
profile_op_opt_builder.order_by('micros') | |
profile_op_opt_builder.with_max_depth(50) | |
profiler.profile_operations(profile_op_opt_builder.build()) | |
#profiler.profile_operations(option_builder.ProfileOptionBuilder().time_and_memory()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment