調試tensorflow的常用方法是用numpy數組替換佔位符和/或變量,並將它們放入tf.const中。當你這樣做的時候,你可以通過設置一個斷點並在「pythoninc」中查看數字,而不僅僅是張量來檢查你的代碼的邏輯。這將是更容易幫助你,如果你會在這裏發表您的代碼,但這裏是一個虛擬的例子:
with tf.name_scope('scope_name'):
### This block is for debug only
import numpy as np
batch_size = 20
sess = tf.Session()
sess.run(tf.tables_initializer())
init_op = tf.global_variables_initializer()
sess.run(init_op)
### End of first debug block
## Replacing Placeholders for debug - uncomment the placehlolders and comment the numpy arrays to producation mode
const_a = tf.constant((np.random.rand(batch_size, 26) > 0.85).astype(int), dtype=tf.float32)
const_b = tf.constant(np.random.randint(0, 20, batch_size * 26).reshape((batch_size, 26)), dtype=tf.float32)
# real_a_placeholder = tf.log(input_placeholder_dict[A_DATA])
# real_b_placeholder = tf.log(input_placeholder_dict[B_DATA])
# dummy opreation
c = a - b
# selecting top k - in the sanity check you can see here that you actullay get the top items and top values
top_k = 5
top_k_values, top_k_indices = tf.nn.top_k(c,
k=top_k, sorted=True,
name="top_k")
## Replacing Variable for debug - uncomment the variables and comment the numpy arrays to producation mode
現在,斷點運行你的代碼,你有2個選項,看看在調試器的值: 1. sess.run(palceholder_name) 2.you可以使用eval - varaible_name.eval(sessnio = SESS)
調試tensorflow時要記住,tensorflow的C++部分可能會吐出一些警告/錯誤消息給標準輸出,你的jupyter筆記本會記下capture/display。 –
@ amo-ej1我已經完成了你的建議。這個unocerd也有一些錯字錯誤。問題依然存在,但現在我還有一個線索,python tensorflow與返回碼137和SIGKILL(9)信號一起存在。 – neurozen