def build_hartmann_network(input_shape, create_cnn=create_hartmann_cnn, optimizer='SGD', lr=0.001, momentum=None, clipnorm=0.0, loss=None, reducer=None, merge_layer=None, weight_decay=None, weight_file=None):
    assert (len(input_shape) == 3)
    (H, W, C) = input_shape
    cnn = create_hartmann_cnn(input_shape=(None, None, C))
    sim = Sequential([Conv2D(filters=2048, kernel_size=5, input_shape=K.int_shape(cnn.output)[1:]), Activation('relu'), Conv2D(filters=2048, kernel_size=1), Activation('relu'), Conv2D(filters=2, kernel_size=1), Activation('softmax')])
    x_in = [Input(shape=input_shape) for i in range(5)]
    x = [cnn(xi) for xi in x_in]
    x = KerasAverage()(x)
    y = sim(x)
    model = Model(inputs=x_in, outputs=y)
    model.compile(optimizer=optimizer_factory(optimizer, lr=lr, momentum=momentum, clipnorm=clipnorm), loss='categorical_crossentropy', metrics=['accuracy'])
    cnn.compile('sgd', 'mse')
    sim.compile('sgd', 'mse')
    model.cnn = cnn
    model.sim = sim
    if weight_file:
        model.load_weights(weight_file, by_name=True)
    return model
def build_hartmann_network(input_shape, create_cnn=create_hartmann_cnn, optimizer='SGD', lr=0.001, momentum=None, clipnorm=0.0, loss=None, reducer=None, merge_layer=None, weight_decay=None, weight_file=None):
    assert (len(input_shape) == 3)
    (H, W, C) = input_shape
    cnn = create_hartmann_cnn(input_shape=(None, None, C))
    sim = Sequential([Conv2D(filters=2048, kernel_size=5, input_shape=K.int_shape(cnn.output)[1:]), Activation('relu'), Conv2D(filters=2048, kernel_size=1), Activation('relu'), Conv2D(filters=2, kernel_size=1), Activation('softmax')])
    x_in = [Input(shape=input_shape) for i in range(5)]
    x = [cnn(xi) for xi in x_in]
    x = KerasAverage()(x)
    y = sim(x)
    model = Model(inputs=x_in, outputs=y)
    model.compile(optimizer=optimizer_factory(optimizer, lr=lr, momentum=momentum, clipnorm=clipnorm), loss='categorical_crossentropy', metrics=['accuracy'])
    cnn.compile('sgd', 'mse')
    sim.compile('sgd', 'mse')
    model.cnn = cnn
    model.sim = sim
    if weight_file:
        model.load_weights(weight_file, by_name=True)
    return model