几个月前,我使用了tf.contrib.learn.DNNRegressor
来自 TensorFlow 的 API,我发现它使用起来非常方便。最近几个月我没有跟上TensorFlow的发展。现在我有一个项目,我想再次使用回归器,但可以更好地控制 DNNRegressor
提供的实际模型。 。据我所知,Estimator
支持这一点。 API 使用model_fn
参数。
但是有两个Estimator
TensorFlow API 中的:
-
tf.contrib.learn.Estimator
-
tf.estimator.Estimator
两者都提供类似的 API,但用法略有不同。为什么有两种不同的实现?有理由选择其中一种吗?
不幸的是,我在 TensorFlow 文档或何时使用两者的指南中找不到任何差异。实际上,学习 TensorFlow 教程会产生很多警告,因为某些接口(interface)显然已更改(而不是 x
、 y
参数、input_fn
参数等)。
最佳答案
我也有同样的疑问,但无法给出明确的答案,但是我有一些有根据的猜测可能会对您有所帮助:
似乎 tf.estimator.Estimator 以及返回 tf.estimator.EstimatorSpec 的模型函数是较新示例中使用的最新函数,并且将在新代码中使用的代码。
我现在的猜测是,tf.contrib.learn.Estimator
是一个早期原型(prototype),已被 tf.estimator.Estimator
取代。根据文档,tf.contrib
中的所有内容都是不稳定的 API,可能随时更改,并且看起来 tf.estimator
模块是从“进化”而来的稳定 API tf.contrib.learn 模块。我认为作者只是忘记将 tf.contrib.learn.Estimator 标记为已弃用,并且尚未删除,因此现有代码不会中断。
关于machine-learning - TensorFlow 中 tf.estimator.Estimator 和 tf.contrib.learn.Estimator 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44204897/