KerasTuner is a hyperparameter optimization library for Keras, making it easy to find the best hyperparameters for your machine learning models. It supports various tuning algorithms like RandomSearch, Hyperband, and BayesianOptimization. The library is actively maintained and frequently updated, with recent versions adding support for Keras 3 (multi-backend) and improving distributed execution.
pip install keras-tunerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use KerasTuner with a `HyperModel` to search for optimal hyperparameters for a simple Keras model on the Fashion MNIST dataset. It defines a model with tunable dense layer units and learning rate, then uses `RandomSearch` to find the best configuration.
Update any imports of internal components from `keras_tuner.some_private_api` to `keras_tuner.src.some_private_api`. Public APIs remain at the top level (e.g., `keras_tuner.tuners.RandomSearch`).
If using Keras 3, ensure you have `keras` installed and potentially set `KERAS_BACKEND` environment variable. If using Keras 2, ensure you have `tensorflow<2.16` and `keras<3.0`.
Upgrade to KerasTuner v1.4.7 or newer to benefit from fixes to distributed execution stability. Carefully manage the lifecycle of parallel tuning processes.
Ensure you have compatible versions of `grpcio` and `protobuf` installed. A clean `pip install keras-tuner` will pull the correct versions. If conflicts arise, consider using a virtual environment.