AttributeError:' nonepy'对象没有属性' _inbound_nodes'当在恒定张量和keras张量之间实现操作时

发布于 01-24 14:21 字数 588 浏览 4 评论 0原文

我正在KERAS中实施Convrnn,并且实现遵循

当类Convrnn返回KERAS模型(输入,输出)时,发生错误:

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

无论如何,我重新检查了我的代码,最后找到了触发问题的代码。但是我不知道如何修改它。他们是:

one = keras.backend.ones_like(z)
h_output = keras.layers.add([keras.layers.multiply([keras.layers.subtract([one, z]), h]), keras.layers.multiply([z, n])]) # h = (1 - z) * h + z * n
# h, z and n are all keras tensors

我想在这里实现的是 h =(1 -z) * h + z * n

有人可以给我建议吗?提前致谢。

顺便说一句,KERAS版本为2.3.1,TensorFlow版本为1.14.0。

I'm implementing a ConvRNN in keras, and the implementation follows this which is originally implemented in Pytorch.

When the class ConvRNN is going to return a keras Model(inputs, outputs), then an error occurs:

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

Anyway, I re-checked my code and finally located the code which triggers the problem.But I don't know how to modify it. They are:

one = keras.backend.ones_like(z)
h_output = keras.layers.add([keras.layers.multiply([keras.layers.subtract([one, z]), h]), keras.layers.multiply([z, n])]) # h = (1 - z) * h + z * n
# h, z and n are all keras tensors

What I want to implement here is h = (1 - z) * h + z * n.

Can anyone please give me advice? Thanks in advance.

BTW, the keras version is 2.3.1 and the tensorflow version is 1.14.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉2025-01-31 14:21:38

哇..我终于弄清楚了。永远记住要确保应作为keras.layers进行张量的每个操作!

转换:

one = keras.backend.ones_like(z)

到:

one = keras.layers.Lambda(lambda x: keras.backend.ones_like(x))(z)

然后错误消失了!

Whoo.. I finally figured it out. Always remember to make sure EVERY operation on tensors should be done as keras.layers!

Convert:

one = keras.backend.ones_like(z)

To:

one = keras.layers.Lambda(lambda x: keras.backend.ones_like(x))(z)

Then the error is gone!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文