如何调试Tensorflow网络权重/输出/每个输入样本的成本?

4

我创建了一个TensorFlow模型,但是总是因为某些原因获得NAN损失。我想知道如何调试并查看每个张量中的每个值。

例如:

 out = tf.add(tf.matmul(outputs[-1], _weights['out']), _biases['out'])

在运行时,我希望查看此张量中的值,并了解出现问题的原因。

我在这篇文章中找到了类似的内容。

他们做了类似于以下的操作:

out = tf.add(tf.matmul(outputs[-1], _weights['out']), _biases['out'])
out = tf.Print(out, [out], message="This is softmax Output: ")

但是这会产生如下输出:

I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [2.148583e-08 5.9002307e-08 -9.90654e-08...]
I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [nan nan nan...]
I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [nan nan nan...]
Iter 64, Minibatch Loss= nan, Training Accuracy= 0.01562
Testing Accuracy: 0.0
I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [nan nan nan...]
I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [nan nan nan...]
I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [nan nan nan...]
I tensorflow/core/kernels/logging_ops.cc:79] This is softmax Output: [nan nan nan...]

这并不是非常有用,因为我无法查看所有的值。 我想知道是否有逐步调试选项?


你可以使用类似的方法打印中间张量。 - Yaroslav Bulatov
真的,但问题是它并没有打印整个张量,而是只打印了前几个值。如果我想对它执行一些数学测试,比如应用剪切并将其传递到下一个张量,我就无法做到。但是,作为最后的选择,我会使用它。 - Arsenal Fanatic
目前还没有方便的方法来进行逐步计算,尽管我们正在努力解决这个问题。一个解决方法是将所有内容重新定义为变量,并使用“tf.assign”将值放入其中。这样,您就可以在会话运行之间检查它们的状态。 - Yaroslav Bulatov
2个回答

1

0

tf.Print()函数可以通过传递可选参数summarize来显示更多结果。例如,summarize=100将显示张量的前100个元素。

API参考

(不确定该功能是否在提问时存在)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接