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

Before Change


// simple TCN model.
max_len = 100
max_features = 50
i = Input(shape=(max_len,))
x = Embedding(max_features, 16)(i)
x = TCN(nb_filters=12,
        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.
// The value for [First time] and [Model reloaded] should be the same. Run the script twice!
inputs = np.ones(shape=(1, 100))

After Change


                           Dense(units=1, activation="sigmoid")])

// get model as json string and save to file
model_as_json = model.to_json()
with open(r"model.json", "w") as json_file:
    json_file.write(model_as_json)
// save weights to file (for this format, need h5py installed)
model.save_weights("weights.h5")

// Make inference.
inputs = np.ones(shape=(1, 100))
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 8

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: HyperGAN/HyperGAN
Commit Name: 5a69007e1ab2f4c0b4a549c0a2a8cd9701fd8929
Time: 2017-06-28
Author: mikkel@255bits.com
File Name: examples/colorizer.py
Class Name:
Method Name: search


Project Name: deepchem/deepchem
Commit Name: c7c06f56e918cabf565d4e4454daa344137d1f0f
Time: 2017-05-25
Author: Karl
File Name: contrib/rl/tictactoe.py
Class Name:
Method Name: main