I am trying to create a Keras model with multiple inputs.
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 defined the inputs as
inputs = ([X_train.reshape(10000,728), input_1.reshape(10000,), input_2.reshape(10000,)])
and trained as follow
history = cnn.fit(inputs, labels, validation_split = 0.2, epochs=30, batch_size=100, validation_data=(validation, labels_test))
Whenever I run this, I get the following error
ValueError: Error when checking target: expected activation_12 to have shape (3,) but got array with shape (1,)
How do I pass the inputs as shape (3,) if they have different dimensions?
[]
being itself inside a tuple()
, try to remove either the()
or the[]
likeinputs = (X_train.reshape(10000,728), input_1.reshape(10000,), input_2.reshape(10000,))
– Ben.TAttributeError: 'tuple' object has no attribute 'ndim'
– kdfndim
is an attribute of numpy arrays so probably the parameterinputs
should be anarray
and not atuple
nor alist
. Once again, I never used it, but you could tryinputs = np.array([X_train.reshape(10000,728), input_1.reshape(10000,), input_2.reshape(10000,)])
at least it would be an array of shape (3,) – Ben.TValueError: could not broadcast input array from shape (10000,728) into shape (10000)
when attempting to transform the list into numpy arrays. – kdf