60c52ea766b8049c4396ad76c6f4242039c5e974,keras/models.py,,load_model,#Any#Any#Any#,170

Before Change


    if model_config is None:
        raise ValueError("No model found in config file.")
    model_config = json.loads(model_config.decode("utf-8"))
    model = model_from_config(model_config, custom_objects=custom_objects)

    // set weights
    topology.load_weights_from_hdf5_group(f["model_weights"], model.layers)

    // Early return if compilation is not required.
    if not compile:
        f.close()
        return model

    // instantiate optimizer
    training_config = f.attrs.get("training_config")
    if training_config is None:
        warnings.warn("No training configuration found in save file: "
                      "the model was *not* compiled. Compile it manually.")
        f.close()
        return model
    training_config = json.loads(training_config.decode("utf-8"))
    optimizer_config = training_config["optimizer_config"]
    optimizer = optimizers.deserialize(optimizer_config,
                                       custom_objects=custom_objects)

    // Recover loss functions and metrics.
    loss = convert_custom_objects(training_config["loss"])
    metrics = convert_custom_objects(training_config["metrics"])
    sample_weight_mode = training_config["sample_weight_mode"]
    loss_weights = training_config["loss_weights"]

    // Compile model.
    model.compile(optimizer=optimizer,
                  loss=loss,
                  metrics=metrics,
                  loss_weights=loss_weights,
                  sample_weight_mode=sample_weight_mode)

    // Set optimizer weights.
    if "optimizer_weights" in f:
        // Build train function (to get weight updates).

After Change


        if obj in custom_objects:
            return custom_objects[obj]
        return obj
    with h5py.File(filepath, mode="r") as f:
        // instantiate model
        model_config = f.attrs.get("model_config")
        if model_config is None:
            raise ValueError("No model found in config file.")
        model_config = json.loads(model_config.decode("utf-8"))
        model = model_from_config(model_config, custom_objects=custom_objects)

        // set weights
        topology.load_weights_from_hdf5_group(f["model_weights"], model.layers)

        // Early return if compilation is not required.
        if not compile:
            return model

        // instantiate optimizer
        training_config = f.attrs.get("training_config")
        if training_config is None:
            warnings.warn("No training configuration found in save file: "
                          "the model was *not* compiled. Compile it manually.")
            return model
        training_config = json.loads(training_config.decode("utf-8"))
        optimizer_config = training_config["optimizer_config"]
        optimizer = optimizers.deserialize(optimizer_config,
                                           custom_objects=custom_objects)

        // Recover loss functions and metrics.
        loss = convert_custom_objects(training_config["loss"])
        metrics = convert_custom_objects(training_config["metrics"])
        sample_weight_mode = training_config["sample_weight_mode"]
        loss_weights = training_config["loss_weights"]

        // Compile model.
        model.compile(optimizer=optimizer,
                      loss=loss,
                      metrics=metrics,
                      loss_weights=loss_weights,
                      sample_weight_mode=sample_weight_mode)

        // Set optimizer weights.
        if "optimizer_weights" in f:
            // Build train function (to get weight updates).
            if isinstance(model, Sequential):
                model.model._make_train_function()
            else:
                model._make_train_function()
            optimizer_weights_group = f["optimizer_weights"]
            optimizer_weight_names = [n.decode("utf8") for n in
                                      optimizer_weights_group.attrs["weight_names"]]
            optimizer_weight_values = [optimizer_weights_group[n] for n in
                                       optimizer_weight_names]
            model.optimizer.set_weights(optimizer_weight_values)
    return model


def model_from_config(config, custom_objects=None):
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 7

Non-data size: 7

Instances


Project Name: keras-team/keras
Commit Name: 60c52ea766b8049c4396ad76c6f4242039c5e974
Time: 2017-05-26
Author: anis.khlif01@gmail.com
File Name: keras/models.py
Class Name:
Method Name: load_model


Project Name: tensorflow/models
Commit Name: 82b56ca707a6cd08ddc65c6f33ade2acfaca5ca3
Time: 2019-01-03
Author: shiningsun@google.com
File Name: official/resnet/keras/keras_imagenet_main.py
Class Name:
Method Name: run


Project Name: cmu-db/ottertune
Commit Name: c76c8e7bfb2ade8fc5496b60339d77424dfa29b8
Time: 2019-12-17
Author: bohanzhang95@gmail.com
File Name: server/analysis/nn_tf.py
Class Name: NeuralNet
Method Name: __init__


Project Name: tensorflow/models
Commit Name: 1255d5b94dec8f1927e3d500db15ef2078196ecb
Time: 2019-04-08
Author: seemuch@users.noreply.github.com
File Name: official/recommendation/ncf_keras_main.py
Class Name:
Method Name: run_ncf


Project Name: tensorflow/models
Commit Name: 82b56ca707a6cd08ddc65c6f33ade2acfaca5ca3
Time: 2019-01-03
Author: shiningsun@google.com
File Name: official/resnet/keras/keras_cifar_main.py
Class Name:
Method Name: run


Project Name: tensorflow/tpu
Commit Name: 286f897139d03390497a7a896e541f40497d73bd
Time: 2019-08-06
Author: rxsang@google.com
File Name: models/experimental/resnet50_keras/resnet50_tf2.py
Class Name:
Method Name: main


Project Name: keras-team/keras
Commit Name: 8d77bc5f267a49ed890222039f9ee058cca7f22f
Time: 2021-03-01
Author: scottzhu@google.com
File Name: keras/saving/save_test.py
Class Name: TestWholeModelSaving
Method Name: test_multi_output_metrics_name_stay_same