本文介绍了TensorFlow 中的 tf.estimator.Estimator 和 tf.contrib.learn.Estimator 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前,我使用了 TensorFlow 的 tf.contrib.learn.DNNRegressor API,我发现它使用起来非常方便.最近几个月我没有跟上 TensorFlow 的发展.现在我有一个项目,我想再次使用回归器,但可以更好地控制 DNNRegressor 提供的实际模型.据我所知,这是由 Estimator API 使用 model_fn 参数支持的.

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.

但是在 TensorFlow API 中有两个 Estimator:

But there are two Estimators in the TensorFlow API:

  • tf.contrib.learn.Estimator
  • tf.estimator.Estimator

两者都提供类似的 API,但在用法上略有不同.为什么有两种不同的实现方式,是否有理由偏爱其中一种?

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?

不幸的是,我在 TensorFlow 文档或指南中找不到任何区别,何时使用两者中的哪一个.实际上,在 TensorFlow 教程中工作会产生很多警告,因为一些接口显然已经改变(而不是 x,y 参数,input_fn 参数等).

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

推荐答案

我也有同样的疑问,无法给出明确的答案,但是我有一些有根据的猜测可能会对您有所帮助:

I wondered the same and cannot give a definitive answer, but I have a few educated guesses that might help you:

似乎 tf.estimator.Estimator 与返回 tf.estimator.EstimatorSpec 的模型函数一起是最新示例中使用的最新函数,并且要在新代码中使用的那个.

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.

我现在猜测 tf.contrib.learn.Estimator 是一个早期的原型,被 tf.estimator.Estimator 取代.根据文档,tf.contrib 中的所有内容都是不稳定的 API,可能随时更改,看起来 tf.estimator 模块是从进化"而来的稳定 APItf.contrib.learn 模块.我认为作者只是忘记将 tf.contrib.learn.Estimator 标记为已弃用,并且尚未删除,因此现有代码不会中断.

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.

这篇关于TensorFlow 中的 tf.estimator.Estimator 和 tf.contrib.learn.Estimator 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:22