Kullanabilirsiniz tf.keras.callbacks.ModelCheckpoint
için Keras tuner
kontrol noktalarını kaydetmek için diğer modelde kullanılanla aynı şekilde.
Modeli, bu modele göre aramadan elde edilen hiper parametrelerle eğittikten sonra, model kontrol noktalarını tanımlayabilir ve aşağıdaki gibi kaydedebilirsiniz:
hypermodel = tuner.hypermodel.build(best_hps)
# Retrain the model
hypermodel.fit(img_train, label_train, epochs=best_epoch, validation_split=0.2)
import os
checkpoint_path = "training_1/cp.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)
# Create a callback that saves the model's weights
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
save_weights_only=True,
verbose=1)
history = hypermodel.fit(img_train, label_train, epochs=5, validation_split=0.2, callbacks=[cp_callback])
os.listdir(checkpoint_dir)
# Re-evaluate the model
loss, acc = hypermodel.evaluate(img_test, label_test, verbose=2)
print("Restored model, accuracy: {:5.2f}%".format(100 * acc))
# Loads the weights
hypermodel.load_weights(checkpoint_path)
# Re-evaluate the model
loss, acc = hypermodel.evaluate(img_test, label_test, verbose=2)
print("Restored model, accuracy: {:5.2f}%".format(100 * acc))
Lütfen bakın bu bağlantı için daha inofrmation tasarruf ve yük modeli kontrol noktaları.