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)
它在我们的 TODO 列表中。 只是想弄清楚如何很好地做到有一种通用的方法将超参数传递到模型中。
@ilblackdragon对此有何更新?
模型函数有params
参数。 TensorFlowEstimator
已弃用,请使用带有params
参数的 $#$ Estimator
$#$。 现在应该可以了,如果不行,请重新打开。
最有用的评论
@ilblackdragon对此有何更新?