A Hyperparameter Tuning Library for Keras
pip install keras-tunerKerasTuner
KerasTuner is an easy-to-use, scalable hyperparameter optimization framework that solves the pain points of hyperparameter search. Easily configure your search space with a define-by-run syntax, then leverage one of the available search algorithms to find the best hyperparameter values for your models. KerasTuner comes with Bayesian Optimization, Hyperband, and Random Search algorithms built-in, and is also designed to be easy for researchers to extend in order to experiment with new search algorithms.
Official Website: https://keras.io/keras_tuner/
Quick links
Installation
KerasTuner requires Python 3.8+ and TensorFlow 2.0+.
Install the latest release:
pip install keras-tuner
You can also check out other versions in our GitHub repository.
Quick introduction
Import KerasTuner and TensorFlow:
import keras_tuner
from tensorflow import keras
Write a function that creates and returns a Keras model.
Use the hp argument to define the hyperparameters during model creation.
def build_model(hp):
model = keras.Sequential()
model.add(keras.layers.Dense(
hp.Choice('units', [8, 16, 32]),
activation='relu'))
model.add(keras.layers.Dense(1, activation='relu'))
model.compile(loss='mse')
return model
Initialize a tuner (here, RandomSearch).
We use to specify the objective to select the best models,
and we use to specify the number of different models to try.