How to use K.function with two inputs and a concatenate layer? In Keras, I try to compute use the K.function between some layers. But I get an error when I use a Concatenate layer.

Here is a minimal code you can try yourself:

import numpy as np
from keras.layers import *
from keras.models import Model
def test_model(concat, conv2_dim=32, kernel=(3,3), dropout=0, 
                     optimizer='adam', extra_conv=False, padding='valid', 
                     width_dense=1024, batch_norm=False):
    img_shape = (64,64,1)

    image_input = Input(shape=img_shape)
    entropy_vector = Input(shape=(1,))

    conv = Conv2D(conv2_dim, kernel_size=kernel,
                     activation='relu', padding=padding,
                     input_shape=img_shape)(image_input)
    conv = MaxPooling2D(pool_size=(2, 2), padding=padding,)(conv)

    final_conv = Flatten()(conv)
    dense = Dense(width_dense, activation='relu')(final_conv)

    concat_layer = Concatenate()([dense, entropy_vector])

    if(concat): #Skipping
        flat = Dense(width_dense//4, activation='relu')(concat_layer)
    else:
        flat = Dense(width_dense//4, activation='relu')(dense)

    output = Dense(1, activation='sigmoid')(flat)

    model = Model(inputs=[image_input, entropy_vector], outputs=[output])
    model.compile(loss='binary_crossentropy',
                  optimizer=optimizer,
                  metrics=['accuracy'])
    return model

X = [np.ones((1,64,64,1)), np.ones(1,)]
m = test_model(concat=False) # you can try with False
fn = K.function(m.input, [m.output])

m.predict(X)
fn(X) 


But I get this error if concat=True in the test_model function:

InvalidArgumentError: ConcatOp : Ranks of all input tensors should match: shape[0] = [1,1024] vs. shape[1] = [1]
     [[{{node concatenate_18/concat}} = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](dense_112/Relu, _arg_input_44_0_1/_4327, concatenate_18/concat/axis)]]
     [[{{node dense_114/Sigmoid/_4329}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_68_dense_114/Sigmoid", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Use X = [np.ones((1,64,64,1)), np.ones((1, 1))].