Tensorflow: Pass grid search params to TensorFlowEstimator custom model

Created on 20 Apr 2016  ·  3Comments  ·  Source: tensorflow/tensorflow

GridSearchCV is a great way to test and optimize hyper-parameters automatically. I use it with TensorFlowEstimator to optimize learning_rate, batch_size, ...etc. It would be a great addition if I can also use it to customize other parameters in my custom model.

For example, say I have a custom model with a convnet and I want to optimize the stride value. This pseudo code explains what I'm trying to achieve.

I used a custom "params" input to the model function just as an example, not to imply that this is necessarily the right way to implement this feature.

# 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

Most helpful comment

@ilblackdragon Any update on this?

All 3 comments

It's on our TODO list. Just trying to figure out how to do it nicely to have a general way to pass hyper-parameters into the models.

@ilblackdragon Any update on this?

Model function has params argument. TensorFlowEstimator is deprecated, please use Estimator that takes params argument. This should work now, please re-open if this doesn't.

Was this page helpful?
0 / 5 - 0 ratings