Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperparameter tune for Tensorflow

I am searching for a hyperparameter tune package for code written directly in Tensorflow (not Keras or Tflearn). Could you make some suggestion?

like image 610
Mark Avatar asked May 25 '17 13:05

Mark


People also ask

Which is the best for hyperparameter tuning?

Hyperopt uses Bayesian optimization algorithms for hyperparameter tuning, to choose the best parameters for a given model. It can optimize a large-scale model with hundreds of hyperparameters.

How do I tune CNN hyperparameters?

The hyperparameters to tune are the number of neurons, activation function, optimizer, learning rate, batch size, and epochs. The second step is to tune the number of layers. This is what other conventional algorithms do not have. Different layers can affect the accuracy.

How do you tune a hyperparameter with a TensorBoard?

Start TensorBoard and click on "HParams" at the top. The left pane of the dashboard provides filtering capabilities that are active across all the views in the HParams dashboard: Filter which hyperparameters/metrics are shown in the dashboard. Filter which hyperparameter/metrics values are shown in the dashboard.


1 Answers

You can try out Ray Tune, a simple library for scaling hyperparameter search. I mainly use it for Tensorflow model training, but it's agnostic to the framework - works seamlessly with PyTorch, Keras, etc. Here's the docs page - ray.readthedocs.io/en/latest/tune.html

You can use it to run distributed versions of state-of-the-art algorithms such as HyperBand or Bayesian Optimization in about 10 lines of code.

As an example to run 4 parallel evaluations at a time:

import ray
import ray.tune as tune
from ray.tune.hyperband import HyperBandScheduler


def train_model(config, reporter):  # add the reporter parameter
    model = build_tf_model(config["alpha"], config["beta"])
    loss = some_loss_function(model)
    optimizer = tf.AdamOptimizer(loss)

    for i in range(20):
        optimizer.step()
        stats = get_statistics()
        reporter(timesteps_total=i, 
                 mean_accuracy=stats["accuracy"])

ray.init(num_cpus=4)
tune.run(train_model,
    name="my_experiment",
    stop={"mean_accuracy": 100}, 
    config={ 
        "alpha": tune.grid_search([0.2, 0.4, 0.6]), 
        "beta": tune.grid_search([1, 2]) 
    },
    scheduler=HyperBandScheduler(reward_attr="mean_accuracy"))

You also don't need to change your code if you want to run this script on a cluster.

Disclaimer: I work on this project - let me know if you have any feedback!

like image 107
richliaw Avatar answered Sep 30 '22 03:09

richliaw