Layer was called with an input that isn't a symbolic tensor. [Keras]

Viewed 9806

I'm getting the error in following code

flatten = Flatten()(drop_5)
aux_rand = Input(shape=(1,))
concat = Concatenate([flatten, aux_input])

fc1 = Dense(512, kernel_regularizer=regularizers.l2(weight_decay))(concat)

ValueError: Layer dense_1 was called with an input that isn't a symbolic tensor. Received type: . Full input: []. All inputs to the layer should be tensors.

(x_train, y_train), (x_test, y_test) = cifar10.load_data()
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')

aux_rand = np.random.rand(y_train.shape[0])
model_inst = cifar10vgg()
x_train_input = Input(shape=(32,32,3))
aux_input = Input(shape=(1,))
model = Model(inputs=[x_train_input, aux_input], output=model_inst.build_model())
model.fit(x=[x_train, aux_rand], y=y_train, batch_size=batch_size, steps_per_epoch=x_train.shape[0] // batch_size,
                epochs=maxepoches, validation_data=(x_test, y_test),
                callbacks=[reduce_lr, tensorboard], verbose=2)

model_inst.build_model() returns output from model's last layer (Activation('softmax')(fc2))

1 Answers

The error happens because concat is not a tensor. The layer keras.layers.Concatenate should be called as follows:

concat = Concatenate()([flatten, aux_input])
Related