Custom estimators

Premade and custom estimators share a common architecture: both aim to build a tf.estimator.EstimatorSpec object that fully defines the model to be run by tf.estimator.Estimator; the return value of any model_fn is, therefore, the Estimator specification.

The model_fn function follows this signature:

model_fn(    features,    labels,    mode = None,    params = None,    config = None)

The function parameters are:

  • features is the first item returned from input_fn
  • labels is the second item returned from input_fn
  • mode is the tf.estimator.ModeKeys object that specifies the status of the model, if it is in the training, evaluation, or prediction phase
  • params is a dictionary of hyperparameters that can be used to tune the model easily
  • config ...

Get Hands-On Neural Networks with TensorFlow 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.