'Keras concatenate Sequential and Dense models

I have the following models:

Dense Model:

def dense_model(num_features):
  inputs = Input(shape=(num_features,), dtype=tf.float32)
  layers = Dense(32, activation='relu')(inputs)
  model = Model(inputs=inputs, outputs=layers)
  
  return model

enter image description here

LSTM Model:

def lstm_model(num_features):

    inputs = Input(shape=[None, num_features], dtype=tf.float32, ragged=True)
    layers = LSTM(16, activation='tanh')(
        inputs.to_tensor(), mask=tf.sequence_mask(inputs.row_lengths()))

    layers = BatchNormalization()(layers)
    layers = Dense(16,activation='relu')(layers)
    layers = Dense(1, activation='sigmoid')(layers)
    
    model = Model(inputs=inputs, outputs=layers)
    model.compile(loss='mse', optimizer='adam', metrics=['mse'])
        
    return model

enter image description here


I'm trying to concatenate the two networks like so:

def concatenate_model(num_features):
    model_1 = dense_model(10)
    inputs = Input(shape=[None, num_features], dtype=tf.float32, ragged=True)
    layers = LSTM(16, activation='tanh')(
        inputs.to_tensor(), mask=tf.sequence_mask(inputs.row_lengths()))

    layers = BatchNormalization()(layers)
    layers = Dense(16,activation='relu')(concatenate([layers,model_1]))
    layers = Dense(1, activation='sigmoid')(layers)
    
    model = Model(inputs=inputs, outputs=layers)
    model.compile(loss='mse', optimizer='adam', metrics=['mse'])
        
    return model

to get the following result: enter image description here

But I get an error:

ValueError: as_list() is not defined on an unknown TensorShape.

Here is a Colab that demonstrate my issue. What am I missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source