Introduction to the Keras Tuner

View on TensorFlow.org Run in Google Colab View source on GitHub Download notebook

Overview

The Keras Tuner is a library that helps you pick the optimal set of hyperparameters for your TensorFlow program. The process of selecting the right set of hyperparameters for your machine learning (ML) application is called hyperparameter tuning or hypertuning.

Hyperparameters are the variables that govern the training process and the topology of an ML model. These variables remain constant over the training process and directly impact the performance of your ML program. Hyperparameters are of two types:

  1. Model hyperparameters which influence model selection such as the number and width of hidden layers
  2. Algorithm hyperparameters which influence the speed and quality of the learning algorithm such as the learning rate for Stochastic Gradient Descent (SGD) and the number of nearest neighbors for a k Nearest Neighbors (KNN) classifier

In this tutorial, you will use the Keras Tuner to perform hypertuning for an image classification application.

Setup

import tensorflow as tf
from tensorflow import keras

Install and import the Keras Tuner.

pip install -q -U keras-tuner
import keras_tuner as kt

Download and prepare the dataset

In this tutorial, you will use the Keras Tuner to find the best hyperparameters for a machine learning model that classifies images of clothing from the Fashion MNIST dataset.

Load the data.

(img_train, label_train), (img_test, label_test) = keras.datasets.fashion_mnist.load_data()
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
32768/29515 [=================================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz
8192/5148 [===============================================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz
4423680/4422102 [==============================] - 0s 0us/step
# Normalize pixel values between 0 and 1
img_train = img_train.astype('float32') / 255.0
img_test = img_test.astype('float32') / 255.0

Define the model

When you build a model for hypertuning, you also define the hyperparameter search space in addition to the model architecture. The model you set up for hypertuning is called a hypermodel.

You can define a hypermodel through two approaches:

  • By using a model builder function
  • By subclassing the HyperModel class of the Keras Tuner API

You can also use two pre-defined HyperModel classes - HyperXception and HyperResNet for computer vision applications.

In this tutorial, you use a model builder function to define the image classification model. The model builder function returns a compiled model and uses hyperparameters you define inline to hypertune the model.

def model_builder(hp):
  model = keras.Sequential()
  model.add(keras.layers.Flatten(input_shape=(28, 28)))

  # Tune the number of units in the first Dense layer
  # Choose an optimal value between 32-512
  hp_units = hp.Int('units', min_value=32, max_value=512, step=32)
  model.add(keras.layers.Dense(units=hp_units, activation='relu'))
  model.add(keras.layers.Dense(10))

  # Tune the learning rate for the optimizer
  # Choose an optimal value from 0.01, 0.001, or 0.0001
  hp_learning_rate = hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])

  model.compile(optimizer=keras.optimizers.Adam(learning_rate=hp_learning_rate),
                loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
                metrics=['accuracy'])

  return model

Instantiate the tuner and perform hypertuning

Instantiate the tuner to perform the hypertuning. The Keras Tuner has four tuners available - RandomSearch, Hyperband, BayesianOptimization, and Sklearn. In this tutorial, you use the Hyperband tuner.

To instantiate the Hyperband tuner, you must specify the hypermodel, the objective to optimize and the maximum number of epochs to train (max_epochs).

tuner = kt.Hyperband(model_builder,
                     objective='val_accuracy',
                     max_epochs=10,
                     factor=3,
                     directory='my_dir',
                     project_name='intro_to_kt')

The Hyperband tuning algorithm uses adaptive resource allocation and early-stopping to quickly converge on a high-performing model. This is done using a sports championship style bracket. The algorithm trains a large number of models for a few epochs and carries forward only the top-performing half of models to the next round. Hyperband determines the number of models to train in a bracket by computing 1 + logfactor(max_epochs) and rounding it up to the nearest integer.

Create a callback to stop training early after reaching a certain value for the validation loss.

stop_early = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=5)

Run the hyperparameter search. The arguments for the search method are the same as those used for tf.keras.model.fit in addition to the callback above.

tuner.search(img_train, label_train, epochs=50, validation_split=0.2, callbacks=[stop_early])

# Get the optimal hyperparameters
best_hps=tuner.get_best_hyperparameters(num_trials=1)[0]

print(f"""
The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is {best_hps.get('units')} and the optimal learning rate for the optimizer
is {best_hps.get('learning_rate')}.
""")
Trial 30 Complete [00h 00m 27s]
val_accuracy: 0.8523333072662354

Best val_accuracy So Far: 0.8889999985694885
Total elapsed time: 00h 05m 35s
INFO:tensorflow:Oracle triggered exit

The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is 384 and the optimal learning rate for the optimizer
is 0.001.

Train the model

Find the optimal number of epochs to train the model with the hyperparameters obtained from the search.

# Build the model with the optimal hyperparameters and train it on the data for 50 epochs
model = tuner.hypermodel.build(best_hps)
history = model.fit(img_train, label_train, epochs=50, validation_split=0.2)

val_acc_per_epoch = history.history['val_accuracy']
best_epoch = val_acc_per_epoch.index(max(val_acc_per_epoch)) + 1
print('Best epoch: %d' % (best_epoch,))
Epoch 1/50
1500/1500 [==============================] - 3s 2ms/step - loss: 0.4977 - accuracy: 0.8242 - val_loss: 0.4863 - val_accuracy: 0.8190
Epoch 2/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.3720 - accuracy: 0.8651 - val_loss: 0.3629 - val_accuracy: 0.8681
Epoch 3/50
1500/1500 [==============================] - 3s 2ms/step - loss: 0.3329 - accuracy: 0.8783 - val_loss: 0.3530 - val_accuracy: 0.8718
Epoch 4/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.3087 - accuracy: 0.8857 - val_loss: 0.3588 - val_accuracy: 0.8673
Epoch 5/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2900 - accuracy: 0.8903 - val_loss: 0.3117 - val_accuracy: 0.8876
Epoch 6/50
1500/1500 [==============================] - 3s 2ms/step - loss: 0.2742 - accuracy: 0.8971 - val_loss: 0.3571 - val_accuracy: 0.8754
Epoch 7/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2591 - accuracy: 0.9045 - val_loss: 0.3187 - val_accuracy: 0.8873
Epoch 8/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2470 - accuracy: 0.9074 - val_loss: 0.3161 - val_accuracy: 0.8888
Epoch 9/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2368 - accuracy: 0.9112 - val_loss: 0.3652 - val_accuracy: 0.8741
Epoch 10/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2273 - accuracy: 0.9150 - val_loss: 0.3198 - val_accuracy: 0.8898
Epoch 11/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2168 - accuracy: 0.9183 - val_loss: 0.3274 - val_accuracy: 0.8837
Epoch 12/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2073 - accuracy: 0.9225 - val_loss: 0.3253 - val_accuracy: 0.8887
Epoch 13/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2018 - accuracy: 0.9236 - val_loss: 0.3616 - val_accuracy: 0.8821
Epoch 14/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1924 - accuracy: 0.9268 - val_loss: 0.3484 - val_accuracy: 0.8904
Epoch 15/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1854 - accuracy: 0.9298 - val_loss: 0.3100 - val_accuracy: 0.8960
Epoch 16/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1767 - accuracy: 0.9337 - val_loss: 0.3314 - val_accuracy: 0.8928
Epoch 17/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1737 - accuracy: 0.9336 - val_loss: 0.3347 - val_accuracy: 0.8932
Epoch 18/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1665 - accuracy: 0.9373 - val_loss: 0.3376 - val_accuracy: 0.8933
Epoch 19/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1611 - accuracy: 0.9395 - val_loss: 0.3484 - val_accuracy: 0.8938
Epoch 20/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1569 - accuracy: 0.9420 - val_loss: 0.3904 - val_accuracy: 0.8802
Epoch 21/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1517 - accuracy: 0.9429 - val_loss: 0.3665 - val_accuracy: 0.8904
Epoch 22/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1466 - accuracy: 0.9452 - val_loss: 0.3482 - val_accuracy: 0.8959
Epoch 23/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1418 - accuracy: 0.9460 - val_loss: 0.3569 - val_accuracy: 0.8950
Epoch 24/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1390 - accuracy: 0.9481 - val_loss: 0.4292 - val_accuracy: 0.8806
Epoch 25/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1329 - accuracy: 0.9496 - val_loss: 0.3706 - val_accuracy: 0.8957
Epoch 26/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1302 - accuracy: 0.9509 - val_loss: 0.3662 - val_accuracy: 0.8929
Epoch 27/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1243 - accuracy: 0.9535 - val_loss: 0.3984 - val_accuracy: 0.8907
Epoch 28/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1244 - accuracy: 0.9537 - val_loss: 0.3822 - val_accuracy: 0.8964
Epoch 29/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1198 - accuracy: 0.9551 - val_loss: 0.4285 - val_accuracy: 0.8872
Epoch 30/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1166 - accuracy: 0.9563 - val_loss: 0.4269 - val_accuracy: 0.8918
Epoch 31/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1120 - accuracy: 0.9585 - val_loss: 0.4127 - val_accuracy: 0.8922
Epoch 32/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1118 - accuracy: 0.9575 - val_loss: 0.4294 - val_accuracy: 0.8931
Epoch 33/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1093 - accuracy: 0.9592 - val_loss: 0.4230 - val_accuracy: 0.8928
Epoch 34/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1043 - accuracy: 0.9602 - val_loss: 0.4282 - val_accuracy: 0.8947
Epoch 35/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1031 - accuracy: 0.9612 - val_loss: 0.4217 - val_accuracy: 0.8868
Epoch 36/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1029 - accuracy: 0.9609 - val_loss: 0.4487 - val_accuracy: 0.8957
Epoch 37/50
1500/1500 [==============================] - 3s 2ms/step - loss: 0.1010 - accuracy: 0.9623 - val_loss: 0.4623 - val_accuracy: 0.8908
Epoch 38/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0945 - accuracy: 0.9649 - val_loss: 0.4769 - val_accuracy: 0.8885
Epoch 39/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0932 - accuracy: 0.9654 - val_loss: 0.4907 - val_accuracy: 0.8908
Epoch 40/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0932 - accuracy: 0.9653 - val_loss: 0.4886 - val_accuracy: 0.8931
Epoch 41/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0890 - accuracy: 0.9666 - val_loss: 0.4780 - val_accuracy: 0.8917
Epoch 42/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0879 - accuracy: 0.9661 - val_loss: 0.4549 - val_accuracy: 0.8943
Epoch 43/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0876 - accuracy: 0.9669 - val_loss: 0.4959 - val_accuracy: 0.8936
Epoch 44/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0844 - accuracy: 0.9678 - val_loss: 0.4789 - val_accuracy: 0.8944
Epoch 45/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0803 - accuracy: 0.9705 - val_loss: 0.5110 - val_accuracy: 0.8939
Epoch 46/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0825 - accuracy: 0.9696 - val_loss: 0.4860 - val_accuracy: 0.8971
Epoch 47/50
1500/1500 [==============================] - 3s 2ms/step - loss: 0.0771 - accuracy: 0.9709 - val_loss: 0.5046 - val_accuracy: 0.8950
Epoch 48/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0775 - accuracy: 0.9709 - val_loss: 0.5245 - val_accuracy: 0.8918
Epoch 49/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0757 - accuracy: 0.9711 - val_loss: 0.5160 - val_accuracy: 0.8931
Epoch 50/50
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0775 - accuracy: 0.9716 - val_loss: 0.5132 - val_accuracy: 0.8959
Best epoch: 46

Re-instantiate the hypermodel and train it with the optimal number of epochs from above.

hypermodel = tuner.hypermodel.build(best_hps)

# Retrain the model
hypermodel.fit(img_train, label_train, epochs=best_epoch, validation_split=0.2)
Epoch 1/46
1500/1500 [==============================] - 3s 2ms/step - loss: 0.4972 - accuracy: 0.8242 - val_loss: 0.4372 - val_accuracy: 0.8413
Epoch 2/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.3681 - accuracy: 0.8646 - val_loss: 0.3778 - val_accuracy: 0.8640
Epoch 3/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.3322 - accuracy: 0.8771 - val_loss: 0.3637 - val_accuracy: 0.8618
Epoch 4/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.3065 - accuracy: 0.8869 - val_loss: 0.3397 - val_accuracy: 0.8799
Epoch 5/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2858 - accuracy: 0.8943 - val_loss: 0.3257 - val_accuracy: 0.8848
Epoch 6/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2724 - accuracy: 0.8983 - val_loss: 0.3138 - val_accuracy: 0.8856
Epoch 7/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2582 - accuracy: 0.9035 - val_loss: 0.3203 - val_accuracy: 0.8846
Epoch 8/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2466 - accuracy: 0.9074 - val_loss: 0.3291 - val_accuracy: 0.8896
Epoch 9/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2356 - accuracy: 0.9109 - val_loss: 0.3321 - val_accuracy: 0.8847
Epoch 10/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2256 - accuracy: 0.9157 - val_loss: 0.3395 - val_accuracy: 0.8873
Epoch 11/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2167 - accuracy: 0.9191 - val_loss: 0.3407 - val_accuracy: 0.8842
Epoch 12/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2096 - accuracy: 0.9208 - val_loss: 0.3269 - val_accuracy: 0.8913
Epoch 13/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.2012 - accuracy: 0.9237 - val_loss: 0.3243 - val_accuracy: 0.8948
Epoch 14/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1930 - accuracy: 0.9271 - val_loss: 0.3260 - val_accuracy: 0.8916
Epoch 15/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1862 - accuracy: 0.9305 - val_loss: 0.3384 - val_accuracy: 0.8828
Epoch 16/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1811 - accuracy: 0.9313 - val_loss: 0.3279 - val_accuracy: 0.8940
Epoch 17/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1737 - accuracy: 0.9345 - val_loss: 0.3451 - val_accuracy: 0.8914
Epoch 18/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1685 - accuracy: 0.9353 - val_loss: 0.3380 - val_accuracy: 0.8924
Epoch 19/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1639 - accuracy: 0.9374 - val_loss: 0.3551 - val_accuracy: 0.8927
Epoch 20/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1593 - accuracy: 0.9404 - val_loss: 0.3579 - val_accuracy: 0.8957
Epoch 21/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1527 - accuracy: 0.9423 - val_loss: 0.3822 - val_accuracy: 0.8841
Epoch 22/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1487 - accuracy: 0.9443 - val_loss: 0.3670 - val_accuracy: 0.8936
Epoch 23/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1460 - accuracy: 0.9455 - val_loss: 0.3735 - val_accuracy: 0.8911
Epoch 24/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1413 - accuracy: 0.9469 - val_loss: 0.3616 - val_accuracy: 0.8947
Epoch 25/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1359 - accuracy: 0.9482 - val_loss: 0.3641 - val_accuracy: 0.8956
Epoch 26/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1319 - accuracy: 0.9500 - val_loss: 0.3693 - val_accuracy: 0.8928
Epoch 27/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1288 - accuracy: 0.9508 - val_loss: 0.3755 - val_accuracy: 0.8937
Epoch 28/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1249 - accuracy: 0.9530 - val_loss: 0.3808 - val_accuracy: 0.8959
Epoch 29/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1218 - accuracy: 0.9546 - val_loss: 0.4050 - val_accuracy: 0.8923
Epoch 30/46
1500/1500 [==============================] - 3s 2ms/step - loss: 0.1192 - accuracy: 0.9547 - val_loss: 0.3844 - val_accuracy: 0.8967
Epoch 31/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1164 - accuracy: 0.9562 - val_loss: 0.4062 - val_accuracy: 0.8927
Epoch 32/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1126 - accuracy: 0.9565 - val_loss: 0.4070 - val_accuracy: 0.8974
Epoch 33/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1121 - accuracy: 0.9571 - val_loss: 0.4297 - val_accuracy: 0.8895
Epoch 34/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1056 - accuracy: 0.9600 - val_loss: 0.4263 - val_accuracy: 0.8962
Epoch 35/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1062 - accuracy: 0.9593 - val_loss: 0.4547 - val_accuracy: 0.8888
Epoch 36/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.1033 - accuracy: 0.9610 - val_loss: 0.4341 - val_accuracy: 0.8891
Epoch 37/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0987 - accuracy: 0.9629 - val_loss: 0.4396 - val_accuracy: 0.8894
Epoch 38/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0961 - accuracy: 0.9631 - val_loss: 0.4545 - val_accuracy: 0.8939
Epoch 39/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0935 - accuracy: 0.9638 - val_loss: 0.4612 - val_accuracy: 0.8915
Epoch 40/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0932 - accuracy: 0.9646 - val_loss: 0.4712 - val_accuracy: 0.8882
Epoch 41/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0904 - accuracy: 0.9653 - val_loss: 0.4784 - val_accuracy: 0.8941
Epoch 42/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0896 - accuracy: 0.9664 - val_loss: 0.4697 - val_accuracy: 0.8952
Epoch 43/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0851 - accuracy: 0.9674 - val_loss: 0.4728 - val_accuracy: 0.8913
Epoch 44/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0855 - accuracy: 0.9675 - val_loss: 0.4633 - val_accuracy: 0.8964
Epoch 45/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0834 - accuracy: 0.9693 - val_loss: 0.5373 - val_accuracy: 0.8875
Epoch 46/46
1500/1500 [==============================] - 2s 2ms/step - loss: 0.0826 - accuracy: 0.9696 - val_loss: 0.4981 - val_accuracy: 0.8917
<tensorflow.python.keras.callbacks.History at 0x7f5d0832be10>

To finish this tutorial, evaluate the hypermodel on the test data.

eval_result = hypermodel.evaluate(img_test, label_test)
print("[test loss, test accuracy]:", eval_result)
313/313 [==============================] - 1s 2ms/step - loss: 0.5843 - accuracy: 0.8865
[test loss, test accuracy]: [0.5842637419700623, 0.8865000009536743]

The my_dir/intro_to_kt directory contains detailed logs and checkpoints for every trial (model configuration) run during the hyperparameter search. If you re-run the hyperparameter search, the Keras Tuner uses the existing state from these logs to resume the search. To disable this behavior, pass an additional overwrite=True argument while instantiating the tuner.

Summary

In this tutorial, you learned how to use the Keras Tuner to tune hyperparameters for a model. To learn more about the Keras Tuner, check out these additional resources:

Also check out the HParams Dashboard in TensorBoard to interactively tune your model hyperparameters.