【问题标题】:What is the difference between tf.estimator.Estimator and tf.contrib.learn.Estimator in TensorFlowTensorFlow 中的 tf.estimator.Estimator 和 tf.contrib.learn.Estimator 有什么区别
【发布时间】:2017-05-26 15:11:03
【问题描述】:

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

但是TensorFlow API中有两个Estimators:

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

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

不幸的是,我在 TensorFlow 文档或何时使用两者中的哪一个指南中找不到任何差异。实际上,学习 TensorFlow 教程会产生很多警告,因为某些接口显然已经更改(而不是 xy 参数、input_fn 参数等等)。

【问题讨论】:

    标签: machine-learning tensorflow


    【解决方案1】:

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

    似乎tf.estimator.Estimator 和一个返回tf.estimator.EstimatorSpec 的模型函数是最新示例中使用的最新示例,也是新代码中使用的示例。

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

    【讨论】:

      【解决方案2】:

      现在文档中有这样的明确声明:

      Note: TensorFlow also includes a deprecated Estimator class at tf.contrib.learn.Estimator, which you should not use.

      https://www.tensorflow.org/programmers_guide/estimators

      由于某种原因,它没有在代码中标记为已弃用。

      【讨论】:

        【解决方案3】:

        补充克里斯托夫的答案。

        Tensorflow Dev Summit 2017 by Martin Wicke 已经特别提到了这些包之间的区别@:

        core和contrib的区别其实就在core的东西上 不要改变。在 2.0 版之前,一切都是向后兼容的,目前没有人考虑这个问题。

        如果你有核心的东西,它是稳定的,你应该使用它。如果你在 contrib 中有一些东西,API 可能会根据你的需要而改变 你可能想用也可能不想用。

        因此您可以将tf.contrib 包视为“实验性”或“早期预览”。对于已经在tf.estimatortf.contrib 中的类,您绝对应该使用tf.estimator 版本,因为tf.contrib 类会自动弃用(即使文档中没有明确说明)并且可以在下一个中删除释放。

        从 tensorflow 1.4 开始,“毕业”课程列表包括:Estimator DNNClassifierDNNRegressorLinearClassifierLinearRegressorDNNLinearCombinedClassifierDNNLinearCombinedRegressor。这些应该移植到tf.estimator

        【讨论】:

          【解决方案4】:

          我也有同样的问题要问。

          我猜 tf.estimator.Estimator 是高级接口并推荐使用,而 tf.contrib.learn.Estimator 据说不是高级接口(但确实如此)。

          正如 Christoph 提到的,tf.contrib 不稳定,因此 tf.contrib.learn.Estimator 容易受到变化的影响。它从0.x版本更改为1.1版本,并在2016.12再次更改。问题是,它们的用法似乎不同。您可以使用 tf.contrib.learn.SKCompat 来包装 tf.contrib.learn.Estimator,而对于 tf.estimator.Estimator,您不能做同样的事情。如果您检查错误消息,model_fn 要求/参数会有所不同。

          结论是这两个 Estimator 是不同的东西!

          无论如何,我认为 tf doc 在这个主题上做得非常糟糕,因为 tf.estimator 在他们的教程页面中,这意味着他们对此非常认真......

          【讨论】:

            猜你喜欢
            • 2020-03-16
            • 1970-01-01
            • 2016-11-15
            • 2017-10-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-11-10
            • 1970-01-01
            相关资源
            最近更新 更多