Tensorflow: 将网格搜索参数传递给 TensorFlowEstimator 自定义模型

创建于 2016-04-20  ·  3评论  ·  资料来源: tensorflow/tensorflow

GridSearchCV 是一种自动测试和优化超参数的好方法。 我将它与 TensorFlowEstimator 一起使用来优化 learning_rate、batch_size 等。 如果我还可以使用它来自定义自定义模型中的其他参数,那将是一个很好的补充。

例如,假设我有一个带有卷积网络的自定义模型,并且我想优化步幅值。 这个伪代码解释了我想要实现的目标。

我使用模型函数的自定义“参数”输入只是作为示例,并不是暗示这一定是实现此功能的正确方法。

# My custom model. 
# Feature request: New params dict with values filled by GridSearchCV
def cnn_model(X, Y, params):
  stride = params['stride']
  ... custom model definition here ...

# Create the Convnet classifier
cnn_classifier = learn.TensorFlowEstimator(model_fn=cnn_model)

# Grid search on different stride values.
parameters = {'stride': [1, 2, 3],}
grid_searcher = GridSearchCV(cnn_classifier, parameters)
grid_searcher.fit(X, Y)
feature

最有用的评论

@ilblackdragon对此有何更新?

所有3条评论

它在我们的 TODO 列表中。 只是想弄清楚如何很好地做到有一种通用的方法将超参数传递到模型中。

@ilblackdragon对此有何更新?

模型函数有params参数。 TensorFlowEstimator已弃用,请使用带有params参数的 $#$ Estimator $#$。 现在应该可以了,如果不行,请重新打开。

此页面是否有帮助?
0 / 5 - 0 等级