def build_simple_cnn(input_shape, create_cnn, optimizer='Adam', lr=0.001, momentum=None, clipnorm=0.0, loss='mse', reducer='average', merge_layer='dot-product', weight_decay=None, weight_file=None):
    assert (len(input_shape) == 5)
    (D, N, W, H, C) = input_shape
    model = create_cnn(input_shape=(None, None, C), kernel_regularizer=weight_decay)
    model.compile(optimizer=optimizer_factory(optimizer, lr=lr, momentum=momentum, clipnorm=clipnorm), loss=loss_factory(loss))
    if weight_file:
        try:
            f = h5py.File(weight_file, 'r')
            keys = [os.path.join(model.name, w.name) for l in model.layers for w in l.weights]
            weights = [f[os.path.join('model_weights', k)][:] for k in keys]
            model.set_weights(weights)
        except:
            model.load_weights(weight_file, by_name=True)
    return model
def build_simple_cnn(input_shape, create_cnn, optimizer='Adam', lr=0.001, momentum=None, clipnorm=0.0, loss='mse', reducer='average', merge_layer='dot-product', weight_decay=None, weight_file=None):
    assert (len(input_shape) == 5)
    (D, N, W, H, C) = input_shape
    model = create_cnn(input_shape=(None, None, C), kernel_regularizer=weight_decay)
    model.compile(optimizer=optimizer_factory(optimizer, lr=lr, momentum=momentum, clipnorm=clipnorm), loss=loss_factory(loss))
    if weight_file:
        try:
            f = h5py.File(weight_file, 'r')
            keys = [os.path.join(model.name, w.name) for l in model.layers for w in l.weights]
            weights = [f[os.path.join('model_weights', k)][:] for k in keys]
            model.set_weights(weights)
        except:
            model.load_weights(weight_file, by_name=True)
    return model