我正在使用Keras构建神经网络。我的目标是实现自定义损失函数,因此我试图出于调试目的从损失函数输出计算出的张量。我正在使用tfdbg
实用程序。不幸的是,我在张量列表中看不到我的张量。
我已经尝试打印出张量的名称并过滤获得的结果,但是没有成功。
这是我的损失函数内的代码:
# I want to debug these variables using tfdbg
# `y_true` variable can be shown using tfdbg
# `y_true_int` and `losses_current` are absent there
y_true_int = tf.cast(y_true, dtype=tf.int32)
losses_current = tf.gather(self.train_losses, y_true_int)
以下是tfdbg
实用程序经过几条run
命令后的结果:
tfdbg> lt -n loss.*
30 dumped tensor(s):
Node name regex filter: "loss.*"
t (ms) Size (B) Op type Tensor name
[64.359] 210 Const loss/dense_2_loss/Const:0
[85.986] 206 Const loss/dense_2_loss/sub:0
[109.804] 214 Const loss/dense_2_loss/sub_1/x:0
[168.746] 244 Const loss/dense_2_loss/Mean/reduction_indices:0
[204.870] 234 Print loss/dense_2_loss/Print:0
[228.713] 266 Minimum loss/dense_2_loss/clip_by_value/Minimum:0
[232.239] 244 Const loss/dense_2_loss/Mean_1/reduction_indices:0
[263.084] 250 Maximum loss/dense_2_loss/clip_by_value:0
[279.134] 234 Sub loss/dense_2_loss/sub_1:0
[294.109] 238 RealDiv loss/dense_2_loss/truediv:0
[312.494] 230 Log loss/dense_2_loss/Log:0
[323.764] 220 Const loss/dense_2_loss/NotEqual/y:0
[333.243] 272 ZerosLike loss/dense_2_loss/logistic_loss/zeros_like:0
[333.255] 258 Neg loss/dense_2_loss/logistic_loss/Neg:0
[333.264] 258 Mul loss/dense_2_loss/logistic_loss/mul:0
[343.374] 221 NotEqual loss/dense_2_loss/NotEqual:0
[376.065] 232 Cast loss/dense_2_loss/Cast_1:0
[376.088] 261 GreaterEqual loss/dense_2_loss/logistic_loss/GreaterEqual:0
[394.866] 212 Mean loss/dense_2_loss/Mean_2:0
[407.123] 264 Select loss/dense_2_loss/logistic_loss/Select:0
[407.123] 268 Select loss/dense_2_loss/logistic_loss/Select_1:0
[432.697] 258 Sub loss/dense_2_loss/logistic_loss/sub:0
[463.691] 250 Add loss/dense_2_loss/logistic_loss:0
[490.081] 228 Mean loss/dense_2_loss/Mean:0
[533.502] 232 Mean loss/dense_2_loss/Mean_1:0
[548.463] 226 Mul loss/dense_2_loss/mul:0
[569.905] 238 RealDiv loss/dense_2_loss/truediv_1:0
[599.461] 212 Mean loss/dense_2_loss/Mean_3:0
[628.107] 180 Mul loss/mul:0
[650.176] 180 Add loss/add:0
tfdbg>
如您所见,列表中没有'Gather'张量。
我正在使用以下行来处理tfdbg
:
keras.backend.set_session(tf_debug.LocalCLIDebugWrapperSession(tf.Session()))