本地超参数调整-Tensorflow Google Cloud ML Engine [英] Hyperparameter tuning locally -- Tensorflow Google Cloud ML Engine
问题描述
是否可以使用ML Engine调整超参数以在本地训练模型?该文档仅提及在云中进行超参数调整的培训(提交作业),而没有提及在本地进行.
Is it possible to tune hyperparameters using ML Engine to train the model locally? The documentation only mentions training with hyperparameter tuning in the cloud (submitting a job), and has no mention to doing so locally.
否则,是否还有另一种常用的超参数调整,如普查估计器教程中所述,将命令参数传递给task.py?
Otherwise, is there another commonly used hyperparameter tuning that passes in command arguments to task.py as in the census estimator tutorial?
https://github.com/GoogleCloudPlatform/cloudml-samples/tree/master/人口普查
推荐答案
正如Puneith所说,超参数调整不能在ML-Engine中本地运行.
As Puneith said, hyperparamater tuning cannot run locally in ML-Engine.
SciKit Optimize提供了一个易于使用的包装器,可与包括估计器在内的任何模型一起使用.只需将针对N个纪元进行训练的代码放到自己的函数中,该函数将返回评估1精度,1-auroc或损失度量以最小化.
SciKit Optimize provides an easy to use wrapper that works with any model including estimators. Just put the code that runs training for N epochs into its own function, which returns the evaluation 1-accuracy, 1-auroc or loss metric for minimizing.
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-优化/scikit优化/blob/master/examples/hyperparameter-optimization.ipynb
这篇关于本地超参数调整-Tensorflow Google Cloud ML Engine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!