Home > Back-end >  tf.keras.Concatenate Graph Disconnected when concatenating two input layers
tf.keras.Concatenate Graph Disconnected when concatenating two input layers

Time:11-02

Hey I have a problem that seems common but I am sure what I'm doing should work because it is so simple.

It's got to do with the Keras Concatenate layer:

Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 128, 256, 192, 1), dtype=tf.float32, name='input_1'), name='input_1', description="created by layer 'input_1'") at layer "tf.concat". The following previous layers were accessed without issue: []

I am essentially trying to concatenate 2 inputs like so:

in_layer1 = Input((sizes1[1], sizes1[2], sizes1[3], 1))  # (slices, x, y, channel=1)
in_layer2 = Input((sizes2[1], sizes2[2], sizes2[3], 1))  # (slices, x, y, channel=1)
in_layer = Concatenate(axis=1)([in_layer1, in_layer2][:])  # combine the two inputs

problem happens when I instantiate the model :

Model(inputs=[in_layer], outputs=[out_layer])

it seems it was a problem before tf2.2 and I am using 2.4 so not sure why it's happening: https://github.com/tensorflow/tensorflow/issues/32023

Any help or resources would be really appreciated. I checked the documentation and I don't think I'm doing it wrong but clearly there is a problem.

CodePudding user response:

As @Dr.Snoopy mentioned, in_layer isnt actually an input layer. Instead it should be Model(inputs=[in_layer1, in_layer2], outputs=[out_layer])

  • Related