我當時正在運行TensorFlow,並且碰巧產生NaN。我想知道它是什麼,但我不知道如何做到這一點。主要問題是,在「正常」程序程序中,我只是在執行操作之前編寫一個打印語句。 TensorFlow的問題是我無法做到這一點,因爲我首先聲明(或定義)圖形,因此向圖形定義添加打印語句無濟於事。是否有任何規則,建議,啓發式方法,追查可能導致NaN的原因?如何在TensorFlow中調試NaN值?
在這種情況下,我知道更準確地看,因爲我有以下哪一行:
Delta_tilde = 2.0*tf.matmul(x,W) - tf.add(WW, XX) #note this quantity should always be positive because its pair-wise euclidian distance
Z = tf.sqrt(Delta_tilde)
Z = Transform(Z) # potentially some transform, currently I have it to return Z for debugging (the identity)
Z = tf.pow(Z, 2.0)
A = tf.exp(Z)
時,這條線是目前我有它,它返回NaN通過我的總結作家聲明。爲什麼是這樣?有沒有辦法可以至少探索Z在平方根之後的價值?
對於我張貼的具體的例子,我試圖tf.Print(0,Z)
但沒有成功它印什麼。如在:
Delta_tilde = 2.0*tf.matmul(x,W) - tf.add(WW, XX) #note this quantity should always be positive because its pair-wise euclidian distance
Z = tf.sqrt(Delta_tilde)
tf.Print(0,[Z]) # <-------- TF PRINT STATMENT
Z = Transform(Z) # potentially some transform, currently I have it to return Z for debugging (the identity)
Z = tf.pow(Z, 2.0)
A = tf.exp(Z)
我其實不明白tf.Print
應該做什麼。爲什麼需要兩個參數?如果我想打印1張張爲什麼我需要通過2張?對我來說似乎很奇怪。
我一直在尋找的功能tf.add_check_numerics_ops(),但它並沒有說如何使用它(加上文檔似乎不是超級有用)。有誰知道如何使用它?
由於我對解決數據問題的評論可能不好,因此我使用了標準MNIST。然而,我計算的是一個正數量(pair-wise eucledian distance),然後對其進行平方根。因此,我不會看到這些數據具體會成爲一個問題。
FYI該錯過在使用優化的一些OPS - https://github.com/tensorflow/tensorflow/issues/2288 –