AttributeError: 'NoneType' object has no attribute '_inbound_nodes' when implement an operation between a constant tensor and a keras tensor

Viewed 598

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.

1 Answers

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!

Related