Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a tf.estimator to a keras model?

In package tf.estimator, there's a lot of defined estimators. I want to use them in Keras.

I checked TF docs, there's only one converting method that could convert keras. Model to tf. estimator, but no way to convert from estimator to Model.

For example, if we want to convert the following estimator:

tf.estimator.DNNLinearCombinedRegressor

How could it be converted into Keras Model?

like image 776
cramer Avatar asked Jul 22 '19 07:07

cramer


People also ask

Is TF keras the same as keras?

The difference between tf. keras and keras is the Tensorflow specific enhancement to the framework. keras is an API specification that describes how a Deep Learning framework should implement certain part, related to the model definition and training.

What is keras estimator?

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.

What does TF estimator do?

The Estimator object wraps a model which is specified by a model_fn , which, given inputs and a number of other parameters, returns the ops necessary to perform training, evaluation, or predictions. All outputs (checkpoints, event files, etc.)


1 Answers

You cannot because estimators can run arbitrary code in their model_fn functions and Keras models must be much more structured, whether sequential or functional they must consist of layers, basically.

A Keras model is a very specific type of object that can therefore be easily wrapped and plugged into other abstractions.

Estimators are based on arbitrary Python code with arbitrary control flow and so it's quite tricky to force any structure onto them.

Estimators support 3 modes - train, eval and predict. Each of these could in theory have completely independent flows, with different weights, architectures etc. This is almost unthinkable in Keras and would essentially amount to 3 separate models.

Keras, in contrast, supports 2 modes - train and test (which is necessary for things like Dropout and Regularisation).

like image 114
rudolfovic Avatar answered Sep 20 '22 09:09

rudolfovic