Some months ago, I used the tf.contrib.learn.DNNRegressor
API from TensorFlow, which I found very convenient to use. I didn't keep up with the development of TensorFlow the last few months. Now I have a project where I want to use a Regressor again, but with more control over the actual model as provided by DNNRegressor
. As far as I can see, this is supported by the Estimator
API using the model_fn
parameter.
But there are two Estimator
s in the TensorFlow API:
tf.contrib.learn.Estimator
tf.estimator.Estimator
Both provide a similar API, but are nevertheless slightly different in their usage. Why are there two different implementations and are there reasons to prefer one?
Unfortunately, I can't find any differences in the TensorFlow documentation or a guide when to use which of both. Actually, working through the TensorFlow tutorials produced a lot of warnings as some of the interfaces apparently have changed (instead of the x
,y
parameter, the input_fn
parameter et cetera).
TF Lattice Custom Estimators. Graph-based Neural Structured Learning in TFX. The Estimator object wraps a model which is specified by a model_fn , which, given inputs and a number of other parameters, returns the ops necessary to perform training, evaluation, or predictions. All outputs (checkpoints, event files, etc.)
It is recommended using pre-made Estimators when just getting started. To write a TensorFlow program based on pre-made Estimators, you must perform the following tasks: Create one or more input functions. Define the model's feature columns.
The model_fn is a function that contains all the logic to support training, evaluation, and prediction. The basic skeleton for a model_fn looks like this: def model_fn(features, labels, mode, hyperparameters): # Logic to do the following: # 1. Configure the model via TensorFlow operations # 2.
I wondered the same and cannot give a definitive answer, but I have a few educated guesses that might help you:
It seems that tf.estimator.Estimator
together with a model function that returns tf.estimator.EstimatorSpec
is the most current one that is used in the newer examples and the one to be used in new code.
My guess now is that the tf.contrib.learn.Estimator
is an early prototype that got replaced by the tf.estimator.Estimator
. According to the docs everything in tf.contrib
is unstable API that may change at any time and it looks like the tf.estimator
module is the stable API that “evolved” from the tf.contrib.learn
module. I assume that the authors just forgot to mark tf.contrib.learn.Estimator
as deprecated and that it wasn't removed yet so existing code won't break.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With