tensorflow - 本地超参数调优——Tensorflow Google Cloud ML Engine
问题描述
是否可以使用 ML Engine 调整超参数以在本地训练模型?文档只提到了在云中进行超参数调整的训练(提交作业),并没有提到在本地这样做。
否则,是否有另一种常用的超参数调整,如人口普查估计器教程中那样将命令参数传递给 task.py?
https://github.com/GoogleCloudPlatform/cloudml-samples/tree/master/census
解决方案
正如 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)
推荐阅读
- flutter - 在 pubspec 中声明自定义字体时,weight 和 style 属性有什么用?
- c - CMake错误找不到openmp_c不合适的Mac版本
- c - 为什么局部变量 i 初始化为 0?
- javascript - 我在将我的 API 格式化为我将使用的 npm 包的功能版本时遇到问题
- c++ - 谁能让我知道如何使用 pqxx 库在 c++ 中调用 postgres db 函数和过程?
- c# - 为什么 PageModel 和 ControllerBase 使用不属于它们的 ActionResult?
- android - R8 缺少 android.view 类警告
- reactjs - Typescript 属性“X”在“AxiosResponse”类型中缺失,但在“Pick”类型中是必需的
' - html - CSS 问题。试图将 .switch-dot(控制板内的点)类元素定位在 700px 和 800px 的屏幕宽度上,在 .switch 元素内
- java - 获取两个字符串的所有匹配索引的最快方法是什么