What is the difference between tf.estimator.Estimator and tf.contrib.learn.Estimator in TensorFlow

Viewed 3494

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 Estimators 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).

4 Answers

To add to Christoph's answer.

The distinction between these packages has been specifically mentioned at Tensorflow Dev Summit 2017 by Martin Wicke:

The distinction between core and contrib is really in core things don't change. Things are backward compatible until release 2.0, and nobody's thinking about that right now.

If you have something in core, it's stable, you should use it. If you have something in contrib, the API may change and depending on your needs you may or may not want to use it.

So you can think of tf.contrib package as "experimental" or "early preview". For classes that are already in both tf.estimator and tf.contrib, you should definitely use tf.estimator version, because tf.contrib class gets deprecated automatically (even if it's not stated explicitly in the documentation) and can be dropped in the next release.

As of tensorflow 1.4 the list of "graduated" classes includes: Estimator DNNClassifier, DNNRegressor, LinearClassifier, LinearRegressor, DNNLinearCombinedClassifier, DNNLinearCombinedRegressor. These should be ported to tf.estimator.

Related