1

I am building a Keras model that has multiple inputs with different shapes.

input_img = Input(shape=(728,))
input_1 = Input(shape=(1,))
input_2 = Input(shape=(1,))


x = (Dense(48,kernel_initializer='normal',activation="relu"))(input_img)
x = (Dropout(0.2))(x)
x = (Dense(24,activation="tanh"))(x)
x = (Dropout(0.3))(x)
x = (Dense(1))(x)
x = keras.layers.concatenate([x, input_1, input_2])
x = (Activation("sigmoid"))(x)
cnn = Model(inputs = [input_img, input_1, input_2], outputs = x)
cnn.compile(loss="binary_crossentropy", optimizer='adam')

I tried to define the input as

inputs =  (X_train.reshape(10000,728), input_1[0:10000], input_2[0:10000])

And when I try to train, I get the error

AttributeError: 'tuple' object has no attribute 'ndim'

I attempted to turn inputs into a numpy array, however, I get another error

ValueError: could not broadcast input array from shape (10000,728) into shape (10000)

How can I train this model with multiple inputs if they have different shapes? It seems like everything I tried has lead to some type of error.

kdf
  • 358
  • 4
  • 16
  • Please don't forget to upvote all working answers, and accept the one you like the most. Probably you know this, but this is to let the community know which answers were useful and to reward the people for their time and effort as well ;) See this meta.stackexchange.com/questions/5234/ and meta.stackexchange.com/questions/173399/ – alan.elkin Mar 07 '20 at 19:32

1 Answers1

0

I think you are having trouble concatenating tensors. You should use keras.concatenate to join different tensors. Take a look at this: How to concatenate two layers in keras?

alan.elkin
  • 954
  • 1
  • 10
  • 19