'Load a model from a legacy configuration.
# Arguments
config: dictionary with configuration.
layer_cache: cache to draw pre-existing layer.
# Returns
The loaded Model.'

@classmethod
def legacy_from_config(cls, config, layer_cache=None):

    if (not layer_cache):
        layer_cache = {}
    def normalize_legacy_config(conf):
        if ('class_name' not in conf):
            class_name = conf['name']
            name = conf.get('custom_name')
            conf['name'] = name
            return {'class_name': class_name, 'config': conf}
        return conf
    model = cls()
    def get_or_create_layer(layer_data):
        name = layer_data['config'].get('name')
        if (name in layer_cache):
            return layer_cache[name]
        layer = layer_module.deserialize(layer_data)
        layer_cache[name] = layer
        return layer
    first_layer = config[0]
    first_layer = normalize_legacy_config(first_layer)
    if (first_layer['class_name'] == 'Merge'):
        merge_inputs = []
        first_layer_config = first_layer['config']
        for merge_input_config in first_layer_config.pop('layers'):
            merge_input = layer_module.deserialize(merge_input_config)
            merge_inputs.append(merge_input)
        first_layer_config['layers'] = merge_inputs
        merge = legacy_layers.Merge.from_config(first_layer_config)
        model.add(merge)
    else:
        layer = get_or_create_layer(first_layer)
        model.add(layer)
    for conf in config[1:]:
        conf = normalize_legacy_config(conf)
        layer = get_or_create_layer(conf)
        model.add(layer)
    return model
