Both Tensorflow Keras models and Tensorflow Estimators are able to train neural network models and use them to predict new data. They are both high-level APIs that sits on top of the low-level core TensorFlow API. So when should I use one over the other?
相关问题
- batch_dot with variable batch size in Keras
- How to use Reshape keras layer with two None dimen
- CV2 Image Error: error: (-215:Assertion failed) !s
- Why keras use “call” instead of __call__?
- How to conditionally scale values in Keras Lambda
相关文章
- tensorflow 神经网络 训练集准确度远高于验证集和测试集准确度?
- Tensorflow: device CUDA:0 not supported by XLA ser
- Numpy array to TFrecord
- conditional graph in tensorflow and for loop that
- How to downgrade to cuda 10.0 in arch linux?
- Apply TensorFlow Transform to transform/scale feat
- Change loss function dynamically during training i
- How to force tensorflow tensors to be symmetric?
Background
The Estimators API was added to Tensorflow in Release 1.1, and provides a high-level abstraction over lower-level Tensorflow core operations. It works with an Estimator instance, which is TensorFlow's high-level representation of a complete model.
Keras is similar to the Estimators API in that it abstracts deep learning model components such as layers, activation functions and optimizers, to make it easier for developers. It is a model-level library, and does not handle low-level operations, which is the job of tensor manipulation libraries, or backends. Keras supports three backends - Tensorflow, Theano and CNTK.
Keras was not part of Tensorflow until Release 1.4.0 (2 Nov 2017). Now, when you use
tf.keras
(or talk about 'Tensorflow Keras'), you are simply using the Keras interface with the Tensorflow backend to build and train your model.So both the Estimator API and Keras API provides a high-level API over low-level core Tensorflow API, and you can use either to train your model. But in most cases, if you are working with Tensorflow, you'd want to use the Estimators API for the reasons listed below.
Distribution
You can conduct distributed training across multiple servers with the Estimators API, but not with Keras API.
From the Tensorflow Keras Guide, it says that:
And from the Tensorflow Estimators Guide, it says that:
Pre-made Estimator
Whilst Keras provides abstractions that makes building your models easier, you still have to write code to build your model. With Estimators, Tensorflow provides Pre-made Estimators, which are models which you can use straight away, simply by plugging in the hyperparameters.
Pre-made Estimators are similar to how you'd work with
scikit-learn
. For example, thetf.estimator.LinearRegressor
from Tensorflow is similar to thesklearn.linear_model.LinearRegression
fromscikit-learn
.Integration with Other Tensorflow Tools
Tensorflow provides a vistualzation tool called TensorBoard that helps you visualize your graph and statistics. By using an Estimator, you can easily save summaries to be visualized with Tensorboard.
Converting Keras Model to Estimator
To migrate a Keras model to an Estimator, use the
tf.keras.estimator.model_to_estimator
method.In my understanding, estimator is for training data on large scale and serving on production purpose, because cloud ML engine can only accept estimator.
The description below from one of tensorflow doc mentioned this:
" The Estimators API is used for training models for distributed environments. This targets industry use cases such as distributed training on large datasets that can export a model for production. "