0cfe82c6beb9a28a5ff7da81b86fa0e93c388f14,tasks/save_reload_model.py,,,#,10

Before Change


        dropout_rate=0.5,  // with dropout here.
        kernel_size=6,
        dilations=[1, 2, 4])(x)
x = Dropout(0.5)(x)  // and dropout here.
x = Dense(1, activation="sigmoid")(x)

model = Model(inputs=[i], outputs=[x])

if os.path.exists("tcn.npz"):
    // Load checkpoint if file exists.
    w = np.load("tcn.npz", allow_pickle=True)["w"]
    print("Model reloaded.")
    model.set_weights(w.tolist())
else:
    // Save the checkpoint.
    w = np.array(model.get_weights())
    np.savez_compressed(file="tcn.npz", w=w, allow_pickle=True)
    print("First time.")

// Make inference.

After Change



// load model from file
loaded_json = open(r"model.json", "r").read()
reloaded_model = model_from_json(loaded_json, custom_objects={"TCN": TCN})

// restore weights
reloaded_model.load_weights(r"weights.h5")
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: philipperemy/keras-tcn
Commit Name: 0cfe82c6beb9a28a5ff7da81b86fa0e93c388f14
Time: 2019-11-20
Author: premy@cogent.co.jp
File Name: tasks/save_reload_model.py
Class Name:
Method Name:


Project Name: allenai/allennlp
Commit Name: 700abc65fd2172a2c6809dd9b72cf50fc2407772
Time: 2020-02-03
Author: mattg@allenai.org
File Name: allennlp/models/srl_bert.py
Class Name: SrlBert
Method Name: __init__


Project Name: keras-team/keras
Commit Name: bf4dab3501c62836f94ea17d2f0e198348f5293d
Time: 2016-03-31
Author: francois.chollet@gmail.com
File Name: tests/keras/layers/test_core.py
Class Name:
Method Name: test_dropout