Last active
October 15, 2019 20:51
-
-
Save ruslangrimov/c5c1a14343823a53e1eec972f591536d to your computer and use it in GitHub Desktop.
Profiling a Keras-TensorFlow model
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 tensorflow as tf | |
from tensorflow.python.client import timeline | |
from keras import backend as K | |
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | |
run_metadata = tf.RunMetadata() | |
model = ... # A Keras model | |
fn = K.function(model.inputs, model.outputs, options=run_options, run_metadata=run_metadata) | |
for i in range(4): | |
x = K.variable(...) | |
fn([x]) | |
tl = timeline.Timeline(run_metadata.step_stats) | |
ctf = tl.generate_chrome_trace_format() | |
with open('timeline_%d.json' % (i), 'w') as f: | |
f.write(ctf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment