Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
How to export Estimator model with export_savedmodel function

are there any tutorials available about export_savedmodel ?

I have gone through this article on tensorflow.org and unittest code on github.com, and still have no idea about how to construct the parameter serving_input_fn of function export_savedmodel

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Do it like this:

your_feature_spec = {
    "some_feature": tf.FixedLenFeature([], dtype=tf.string, default_value=""),
    "some_feature": tf.VarLenFeature(dtype=tf.string),
}

def _serving_input_receiver_fn():
    serialized_tf_example = tf.placeholder(dtype=tf.string, shape=None, 
                                           name='input_example_tensor')
    # key (e.g. 'examples') should be same with the inputKey when you 
    # buid the request for prediction
    receiver_tensors = {'examples': serialized_tf_example}
    features = tf.parse_example(serialized_tf_example, your_feature_spec)
    return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

estimator.export_savedmodel(export_dir, _serving_input_receiver_fn)

Then you can request the served model with "predict" signature name by batch.

Source: https://www.tensorflow.org/guide/saved_model#prepare_serving_inputs

over 4 years ago · Santiago Trujillo Relatório

0

if you are using tensorflow straight from the master branch there's a module tensorflow.python.estimator.export that provides a function for that:

from tensorflow.python.estimator.export import export
feature_spec = {'MY_FEATURE': tf.constant(2.0, shape=[1, 1])}
serving_input_fn = export.build_raw_serving_input_receiver_fn(feature_spec)

Unfortunately at least for me it will not go further than that but I'm not sure if my model is really correct so maybe you have more luck than I do.

Alternatively, there are the following functions for the current version installed from pypi:

serving_input_fn = tf.contrib.learn.utils.build_parsing_serving_input_fn(feature_spec)
serving_input_fn = tf.contrib.learn.utils.build_default_serving_input_fn(feature_spec)

But I couldn't get them to work, too.

Probably, I'm not understanding this correctly so I hope you'll have more luck.

chris

over 4 years ago · Santiago Trujillo Relatório

0

You have 2 options:

Export your model to work with JSON dictionaries

In my mlengine-boilerplate repository, I use this to export estimator models to Cloud ML Engine to easily use this with online predictions (sample code for the predictions). Essential part:

def serving_input_fn():
    feature_placeholders = {
        'id': tf.placeholder(tf.string, [None], name="id_placeholder"),
        'feat': tf.placeholder(tf.float32, [None, FEAT_LEN], name="feat_placeholder"),
        #label is not required since serving is only used for inference
    }
    return input_fn_utils.InputFnOps(
        feature_placeholders,
        None,
        feature_placeholders)

Export your model to work with Tensorflow Examples

This tutorial shows how you can use export_savedmodel to serve the Wide & Deep Model implemented with estimators and how to feed Tensorflow examples into the exported model. The essential part:

from tensorflow.contrib.learn.python.learn.utils import input_fn_utils      
serving_input_fn = input_fn_utils.build_parsing_serving_input_fn(feature_spec)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda