Skip to content
Andrzej Pronobis edited this page Jun 1, 2017 · 5 revisions

Logging Device Placement

To see what device each operation is placed on, use:

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

Tracing Op Execution

    from tensorflow.python.client import timeline
    run_metadata = tf.RunMetadata()
    out = sess.run(...,
                   options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
                   run_metadata=run_metadata)
    trace = timeline.Timeline(step_stats=run_metadata.step_stats)
    trace_file = open('timeline.ctf.json', 'w')
    trace_file.write(trace.generate_chrome_trace_format())

Then open the file in chrome at chrome://tracing.

TensorFlow Test Case

When tf.test.TestCase is used, the default graph is destroyed before every new test.

If self.test_session is used to create session instead of tf.Session, the session will be cashed and re-used within a single test. This cached session will be destroyed at the end of the test and a new session will be created for a new test.

Checking Tensor Types

tensor.dtype.is_floating
tensor.dtype.is_integer
Clone this wiki locally