Skip to main content

KerasTuner

codecov PyPI version

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 objective to specify the objective to select the best models, and we use max_trials to specify the number of different models to try.

tuner = keras_tuner.RandomSearch(
    build_model,
    objective='val_loss',
    max_trials=5)

Start the search and get the best model:

tuner.search(x_train, y_train, epochs=5, validation_data=(x_val, y_val))
best_model = tuner.get_best_models()[0]

To learn more about KerasTuner, check out this starter guide.

Contributing Guide

Please refer to the CONTRIBUTING.md for the contributing guide.

Thank all the contributors!

The contributors

Community

Ask your questions on our GitHub Discussions.

Citing KerasTuner

If KerasTuner helps your research, we appreciate your citations. Here is the BibTeX entry:

@misc{omalley2019kerastuner,
	title        = {KerasTuner},
	author       = {O'Malley, Tom and Bursztein, Elie and Long, James and Chollet, Fran\c{c}ois and Jin, Haifeng and Invernizzi, Luca and others},
	year         = 2019,
	howpublished = {\url{https://github.com/keras-team/keras-tuner}}
}

Release files for keras-tuner 1.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keras-tuner 1.4.4
File Size Uploaded
keras-tuner-1.4.4.tar.gz 79.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keras-tuner 1.4.4
File Interpreter ABI Platform
keras_tuner-1.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 207.0 kB

Release files / keras-tuner-1.4.4.tar.gz

Download URL keras-tuner-1.4.4.tar.gz
Size 79.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f2b53bed90a24c4f0e761d9bf5acc1a71b879f7b043f5aad5c3c054586ee828c
BLAKE2b-256 checksum
How to use checksums
5c4ca561ceab08eee85a79d43327ee64bfb13e251e9b8532bb10d229728dce58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / keras_tuner-1.4.4-py3-none-any.whl

Download URL keras_tuner-1.4.4-py3-none-any.whl
Size 128.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d38c07ee50ec6fb321baa0dabc6f73a10c3a9d9f5b5b8d7c002d6e52b98b2f2e
BLAKE2b-256 checksum
How to use checksums
b3fb35dab32ffc45faefcb6762088a1c105e421fbd253eb3e86002b70916e6f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page