I am trying to connect the last layer of two UNet model using functional API and I am having the issue. I think error happens somewhere linking between input layer and each models but I have no clue where to fix.
data_input = keras.Input(shape=(512,512,3))
model_a = sm.Unet(BACKBONE1, input_shape=(512,512,3), encoder_weights='imagenet', classes=n_classes, activation=activation)
model_a(data_input)
model_a_output = model_a.get_layer('decoder_stage4b_relu').output
model_b = sm.Unet(BACKBONE2, input_shape=(512,512,3), encoder_weights='imagenet', classes=n_classes, activation=activation)
model_b(data_input)
model_b_output = model_b.get_layer('decoder_stage4b_relu').output
concat = tf.keras.layers.concatenate([model_a_output,model_b_output], axis=3)
data_output = layers.Conv2D(3, 2, padding="same", activation = "sigmoid")(concat)
ensemble_model= keras.Model(inputs=data_input, outputs=data_output, name="ensemble_model")
ensemble_model.summary()
The issue I'm geeting is
ValueError Traceback (most recent call last) in () 14 data_output = layers.Conv2D(3, 2, padding="same", activation = "sigmoid")(concat) 15 ---> 16 ensemble_model= keras.Model(inputs=data_input, outputs=data_output, name="ensemble_model") 17 18 ensemble_model.summary()
4 frames /usr/local/lib/python3.7/dist-packages/keras/engine/functional.py in _map_graph_network(inputs, outputs) 1035 if id(x) not in computable_tensors: 1036 raise ValueError( -> 1037 f'Graph disconnected: cannot obtain value for tensor {x} ' 1038 f'at layer "{layer.name}". The following previous layers ' 1039 f'were accessed without issue: {layers_with_complete_input}')
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 512, 512, 3), dtype=tf.float32, name='data'), name='data', description="created by layer 'data'") at layer "bn_data". The following previous layers were accessed without issue: []