Confusion about the parameter in tf.estimator.Estimator

Viewed 174

So I am using

tf.estimator.Estimator(
    model_fn, model_dir=None, config=None, params=None, warm_start_from=None
)

and I am confused about the parameter params.

I know it's a dict and according to some example code, I assume that params is some like:

params = {"batch_size":128,
          "hidden_layer": 3
}

but according to the official page, params is dict of hyper parameters that will be passed into model_fn. Keys are names of parameters, values are basic python types (offical page). So the value should be python types like int64, float64?

Please give me a clear explanation. Thank you so much for your help

1 Answers

Further down the docs:

The params argument contains hyperparameters. It is passed to the model_fn, if the model_fn has a parameter named "params", and to the input functions in the same manner. Estimator only passes params along, it does not inspect it. The structure of params is therefore entirely up to the developer.

In other words, what's appropriate is what you decide is appropriate. If your model loads weights, it could be string path to the weights file: weights_path = "model.h5". Float for dropout rate, between 0. and 1.. Like so:

def model_fn(params):
    ...
    x = Dense(params['units'])(x)
    x = Dropout(params['dropout'])(x)
    ...
    model.load_weights(params['weights_path'])
    return model

TF checks if model_fn has params argument here, and passes it in accordingly. model_fn can have any other args as well.

Related