Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!