def build_simple_nn_for_training(input_shape, create_cnn, optimizer='Adam', lr=0.001, momentum=None, clipnorm=0.0, loss='emd', reducer='average', merge_layer='dot-product', weight_decay=None, weight_file=None):
    assert (len(input_shape) == 5)
    (D, N, W, H, C) = input_shape
    x1_in = Input(shape=input_shape)
    x2_in = Input(shape=input_shape)
    x1 = TotalReshape(((- 1), W, H, C))(x1_in)
    x2 = TotalReshape(((- 1), W, H, C))(x2_in)
    cnn = create_cnn(input_shape=(W, H, C), kernel_regularizer=weight_decay)
    x1 = Flatten()(cnn(x1))
    x2 = Flatten()(cnn(x2))
    x = Dot(axes=(- 1), normalize=(merge_layer == 'cosine-similarity'))([x1, x2])
    x = TotalReshape(((- 1), D, N))(x)
    x = reducer_factory(reducer)(x)
    y = Activation('softmax')(x)
    model = Model(inputs=[x1_in, x2_in], outputs=y)
    model.compile(optimizer=optimizer_factory(optimizer, lr=lr, momentum=momentum, clipnorm=clipnorm), loss=loss_factory(loss), metrics=['accuracy', mae, mde])
    if weight_file:
        model.load_weights(weight_file, by_name=True)
    return model
def build_simple_nn_for_training(input_shape, create_cnn, optimizer='Adam', lr=0.001, momentum=None, clipnorm=0.0, loss='emd', reducer='average', merge_layer='dot-product', weight_decay=None, weight_file=None):
    assert (len(input_shape) == 5)
    (D, N, W, H, C) = input_shape
    x1_in = Input(shape=input_shape)
    x2_in = Input(shape=input_shape)
    x1 = TotalReshape(((- 1), W, H, C))(x1_in)
    x2 = TotalReshape(((- 1), W, H, C))(x2_in)
    cnn = create_cnn(input_shape=(W, H, C), kernel_regularizer=weight_decay)
    x1 = Flatten()(cnn(x1))
    x2 = Flatten()(cnn(x2))
    x = Dot(axes=(- 1), normalize=(merge_layer == 'cosine-similarity'))([x1, x2])
    x = TotalReshape(((- 1), D, N))(x)
    x = reducer_factory(reducer)(x)
    y = Activation('softmax')(x)
    model = Model(inputs=[x1_in, x2_in], outputs=y)
    model.compile(optimizer=optimizer_factory(optimizer, lr=lr, momentum=momentum, clipnorm=clipnorm), loss=loss_factory(loss), metrics=['accuracy', mae, mde])
    if weight_file:
        model.load_weights(weight_file, by_name=True)
    return model