【问题标题】:Hyperparameter tuning locally -- Tensorflow Google Cloud ML Engine本地超参数调优——Tensorflow Google Cloud ML Engine
【发布时间】:2019-05-01 23:44:26
【问题描述】:

是否可以使用 ML Engine 调整超参数以在本地训练模型?文档只提到了在云中进行超参数调整的训练(提交作业),并没有提到在本地这样做。

否则,是否有另一种常用的超参数调整,如人口普查估计器教程中那样将命令参数传递给 task.py?

https://github.com/GoogleCloudPlatform/cloudml-samples/tree/master/census

【问题讨论】:

    标签: tensorflow gcloud google-cloud-ml tensorflow-estimator hyperparameters


    【解决方案1】:

    正如 Puneith 所说,超参数调优无法在 ML-Engine 中本地运行。

    SciKit Optimize 提供了一个易于使用的包装器,适用于包括估算器在内的任何模型。只需将运行 N 个 epoch 的训练的代码放入它自己的函数中,该函数返回评估 1-accuracy、1-auroc 或用于最小化的损失度量。

    import numpy as np
    from skopt import gp_minimize
    
    def train(hyperparam_config):
        # set from passed in hyperparameters
        learning_rate = hyperparam_config[0]
        num_layers = hyperparam_config[2]
        # run training
        res = estimator.train_and_evaluate()...
        return res['loss']  # return metric to minimize
    
    hyperparam_config = [Real(0.0001, 0.01, name="learning_rate"),
                          Integer(3, 10, name="num_layers")]
    res = gp_minimize(train, hyperparam_config)
    with open('results.txt', 'w') as wf:
        wf.write(str(res))
    print(res)
    

    来源: https://github.com/scikit-optimize/scikit-optimize/blob/master/examples/hyperparameter-optimization.ipynb

    【讨论】:

      【解决方案2】:

      您无法在本地执行 HPTuning(Cloud ML Engine 支持的基于 Bayesian Optimization 的 HPTuning),因为它是 Cloud ML Engine 提供的托管服务。还有其他方法可以执行超参数调整,例如 Scikit-learn GridSearch,但它们在此任务中的效果要差得多。

      【讨论】:

        【解决方案3】:

        查看Sherpa,优秀的超参数优化库。

        上面写着:

        使研究人员能够快速进行实验、可视化和扩展的超参数优化

        市面上有很多超参数优化库,但使用 Sherpa 可以将结果可视化。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-03-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-09-05
          相关资源
          最近更新 更多