Debug
Partial Runs
- avoid side-effects from fetching tensor
- can re-create and run subset of graph
- reuse results which have been generated previously
a = tf.placeholder(tf.float32, shape=[])
b = tf.placeholder(tf.float32, shape=[])
c = tf.placeholder(tf.float32, shape=[])
r1 = tf.add(a, b)
r2 = tf.multiply(r1, c)
r3 = tf.square(r2)
with tf.Session() as sess:
h = sess.partial_run_setup([r1, r2, r3], [a, b, c])
r1_eval = sess.partial_run(h, r1, feed_dict={a:1, b:2})
r2_eval = sess.partial_run(h, r2, feed_dict={c:2})
r3_eval = sess.partial_run(h, [r3])
tf.Print()
node1 = tf.Print(node1, [node1], "message: ")
out = tf.Print(out, [tf.argmax(out, 1)], "Predicted value = ", summarize=20. first_n=10)
tf.Assert()
r1 = tf.add(a, b)
r2 = tf.multiply(r1, c)
final = tf.square(r2)
assert_op = tf.Assert(tf.reduce_all(r2>0), [r2], name="assert_r2_positive")
with tf.control_dependencies([assert_op]):
final = tf.identity(final)
with tf.Session() as sess:
final_eval = sess.run(final, {a: 1, b:-10, c:10})
print("Final result: ", final_eval)
assert_op = tf.assert_positive(r2, [r2])
tf.add_to_collection('Asserts', assert_op);
assert_op = tf.assert_equal(r2, r3)
tf.add_to_collection('Asserts', assert_op);
assert_op = tf.assert_type(r2, tf.float32)
tf.add_to_collection('Asserts', assert_op);
with tf.Session() as sess:
assert_op = tf.group(tf.get_collection('Asserts'))
final_eval, _ = sess.run([final, assert_op], {a: 1, b:10, c:10})
python debugger
import ipdb; ipdb.set_trace()
if (np.argmax(y_batch, axis=1)[:1] == [4]).all():
import ipdb; ipdb.set_trace()
TensorFlow tfdbg