gpt4 book ai didi

tensorflow - 如何在 TensorFlow 2.0 中调试 Keras?

转载 作者:行者123 更新时间:2023-12-03 14:33:07 25 4
gpt4 key购买 nike

实际上,我在 TensorFlow 1.13.0 中已经发现了这个问题。 (tensorflow1.12.0 运行良好)。

我的代码被列为一个简单的例子:

def Lambda layer(temp):
print(temp)
return temp

在我的 Keras 模型中用作 lambda 层。
在 tensorflow1.12.0 中, print(temp)可以输出如下的详细数据
[<tf.Tensor: id=250, shape=(1024, 2, 32), dtype=complex64, numpy=
array([[[ 7.68014073e-01+0.95353246j, 7.01403618e-01+0.64385843j,
8.30483198e-01+1.0340731j , ..., -8.88018191e-01+0.4751519j ,
-1.20197642e+00+0.6313924j , -1.03787208e+00+0.22964947j],
[-7.94382274e-01+0.56390345j, -4.73938555e-01+0.55901265j,
-8.73749971e-01+0.67095983j, ..., -5.81580341e-01-0.91620034j,
-7.04443693e-01-1.2709806j , -3.23135853e-01-1.0887597j ]],

这是因为我使用 1024 作为 batch_size。但是当我更新到 tensorflow1.13.0 或 TensorFlow 2.0 时,同样的代码输出
Tensor("lambda_1/truediv:0", shape=(None, 1), dtype=float32)


这太可怕了,因为我不知道确切的错误。
那么,关于如何解决它的任何想法?

最佳答案

您会看到该输出,因为 Keras 模型正在转换为其图形表示,因此 print打印 tf.Tensor图描述。

查看tf.Tensor的内容使用 Tensorflow 2.0 时,您应该使用 tf.print而不是 print因为前者被转换为其图形表示,而后者则不会。

关于tensorflow - 如何在 TensorFlow 2.0 中调试 Keras?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55682941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com