1

I have to inputs that I want to merge into one network, so it should be something like:

input1    input2  
   |        | 
   |        |
 hidden    hidden
     Merged

I tried this code:

b1_part = Sequential()
b1_part.add(Dense(units=b1_X_train.shape[1],activation='tanh', activity_regularizer=regularizers.l2(1e-2)))
b1_part.add(Dropout(0.5))
b1_part.add(Dense(units=b1_X_train.shape[1]/4,activation='tanh', activity_regularizer=regularizers.l2(1e-2)))


b2_part = Sequential()
b2_part.add(Dense(units=b2_X_train.shape[1],activation='tanh', activity_regularizer=regularizers.l2(1e-2)))
b2_part.add(Dropout(0.5))
b2_part.add(Dense(units=b2_X_train.shape[1]/4,activation='tanh', activity_regularizer=regularizers.l2(1e-2)))

result = Concatenate(axis=1)([b1_part, b2_part])

optimizer = Adagrad()
result.compile(optimizer=optimzier, loss=BinaryFocalLoss(gamma=2),
               metrics=['accuracy'])

But got:

ValueError: Layer concatenate_10 was called with an input that isn't a symbolic tensor. Received type: <class 'tensorflow.python.keras.engine.sequential.Sequential'>. Full input: [<tensorflow.python.keras.engine.sequential.Sequential object at 0x7fb1cbf97048>, <tensorflow.python.keras.engine.sequential.Sequential object at 0x7fb1cbeb5358>]. All inputs to the layer should be tensors.

Any idea why?

OverLordGoldDragon
  • 1
  • 9
  • 53
  • 101
Cranjis
  • 1,590
  • 8
  • 31
  • 64

1 Answers1

1

first of all, remember to specify the input shape of your sequential model.

Then you can combine your sequential model and define a full model in this way:

b1_part = Sequential()
b1_part.add(Dense(units=100,activation='tanh', input_shape=(100,)))
b1_part.add(Dropout(0.5))
b1_part.add(Dense(units=25,activation='tanh'))

b2_part = Sequential()
b2_part.add(Dense(units=200,activation='tanh', input_shape=(200,)))
b2_part.add(Dropout(0.5))
b2_part.add(Dense(units=50,activation='tanh'))

result = Concatenate(axis=1)([b1_part.output, b2_part.output])
result = Dense(1, activation='sigmoid')(result)

model = Model([b1_part.input, b2_part.input], result)
model.compile('adam', 'binary_crossentropy', metrics='accuracy')
Marco Cerliani
  • 21,233
  • 3
  • 49
  • 54