Not that this is a definitive answer, as I am not sure of the differences here, but it is based on the official docs and a tutorial. From the keras-tuner "Getting started" and from the PyImageSearch tutorial on keras-tuner, both use option A.
For example, on the official keras-tuner tutorial search for parameters on a subset of the data and train the final model as following:
# Get the top 2 hyperparameters.
best_hps = tuner.get_best_hyperparameters(2)
# Build the model with the best hp.
model = build_model(best_hps[0])
# Fit with the entire dataset.
x_all = np.concatenate((x_train, x_val))
y_all = np.concatenate((y_train, y_val))
model.fit(x=x_all, y=y_all, epochs=1)
On the PyImageSearch tutorial they do the following:
# build the best model and train it
model = tuner.hypermodel.build(bestHP)
H = model.fit(x=trainX, y=trainY,
validation_data=(testX, testY), batch_size=config.BS,
epochs=config.EPOCHS, callbacks=[es], verbose=1)
# evaluate the network
predictions = model.predict(x=testX, batch_size=32)
...
Interestingly, on the later, they use tuner.hypermodel.build
directly from the tuner class, which is only shown in the API documentation.
The confusing thing is whether the best found is trained or untrained. Model is untrained, as per keras-tuner documentation, it shows the following example for the get_best_hyperparameters
method:
Returns the best hyperparameters, as determined by the objective.
This method can be used to reinstantiate the (untrained) best model
found during the search process.
Example
best_hp = tuner.get_best_hyperparameters()[0]
model = tuner.hypermodel.build(best_hp)
However, on the get_best_models
documentation says it returns "List of trained model instances sorted from the best to the worst", but
For best performance, it is recommended to retrain your Model on the
full dataset using the best hyperparameters found during search, which
can be obtained using tuner.get_best_hyperparameters(). The models are
loaded with the weights corresponding to their best checkpoint (at the
end of the best epoch of best trial).