How to get the number of epochs the best model was trained using Keras Tuner?

Viewed 271

I used Keras Tuner's RandomSearch class to search for the best model, and I used an EarlyStopping callback when I called fit() (see the code below).

Now I would like to know for how many epochs the best model was actually trained. The goal is to retrain the best model on the full training set (including the validation set) for that number of epochs. Since there won't be a validation set anymore, I cannot use it for early stopping.

tuner = kt.RandomSearch(
    build_model,
    objective="val_accuracy",
    max_trials=5,
    overwrite=True,
    directory="test_search",
    project_name="test_project"
)
tuner.search(
    X_train, y_train, epochs=100,
    validation_data=(X_valid, y_valid),
    callbacks=[tf.keras.callbacks.EarlyStopping(patience=10)]
)
best_trials = random_search_tuner.oracle.get_best_trials(num_trials=3)
0 Answers
Related