Python keras.models 模块,model_from_config() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用keras.models.model_from_config()

项目:pydl    作者:rafaeltg    | 项目源码 | 文件源码
def load_model(config=None):
    assert config is not None, 'Missing input configuration'

    configs = config
    if isinstance(config, str):
        configs = load_json(config)

    assert len(configs) > 0, 'No configuration specified!'
    assert 'model' in configs, 'Missing model definition!'

    m = model_from_config(configs['model'])
    if m is None:
        raise Exception('Invalid model!')

    if 'weights' in configs:
        m.load_model(configs['weights'])

    return m
项目:vinci    作者:Phylliade    | 项目源码 | 文件源码
def clone_model(model, custom_objects={}):
    # Requires Keras 1.0.7 since get_config has breaking changes.
    config = {
        'class_name': model.__class__.__name__,
        'config': model.get_config(),
    }
    clone = model_from_config(config, custom_objects=custom_objects)
    clone.set_weights(model.get_weights())
    return clone
项目:pydl    作者:rafaeltg    | 项目源码 | 文件源码
def model_from_config(config):
    assert 'class_name' in config, 'Missing model class!'

    # fetch all members of module 'pydl.models'
    classes = dict(inspect.getmembers(sys.modules['pydl.models'], inspect.isclass))
    return k_models.model_from_config(config, classes)
项目:keras-rl    作者:matthiasplappert    | 项目源码 | 文件源码
def clone_model(model, custom_objects={}):
    # Requires Keras 1.0.7 since get_config has breaking changes.
    config = {
        'class_name': model.__class__.__name__,
        'config': model.get_config(),
    }
    clone = model_from_config(config, custom_objects=custom_objects)
    clone.set_weights(model.get_weights())
    return clone
项目:openai_lab    作者:kengz    | 项目源码 | 文件源码
def clone_model(model, custom_objects=None):
    from keras.models import model_from_config
    custom_objects = custom_objects or {}
    config = {
        'class_name': model.__class__.__name__,
        'config': model.get_config(),
    }
    clone = model_from_config(config, custom_objects=custom_objects)
    clone.set_weights(model.get_weights())
    return clone


# clone a keras optimizer without file I/O