question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exporting LTR Model in SavedModel Format

See original GitHub issue

Could we please get an example of how to save the produced model in https://github.com/tensorflow/ranking/blob/master/tensorflow_ranking/examples/tf_ranking_libsvm.ipynb in SavedModel format (ref: https://www.tensorflow.org/guide/saved_model). I’ve tried a bunch of variations of exporting from the TensorFlow API docs and GitHub examples with no luck.

feature_columns = example_feature_columns()
feature_spec = tf.feature_column.make_parse_example_spec(feature_columns)
export_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
ranker.export_savedmodel("savedmodel", export_fn)

With the example above I get KeyError: NumericColumn(key='1', shape=(1,), default_value=(0.0,), dtype=tf.float32, normalizer_fn=None)

Some guidance on this problem would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kunalkishorecommented, Aug 13, 2020

@hodeld This might help you:

def make_serving_input_fn():
    """Returns serving input fn."""
    context_feature_spec = tf.feature_column.make_parse_example_spec(
      context_feature_columns().values())
    example_feature_spec = tf.feature_column.make_parse_example_spec(
      example_feature_columns().values())
    return tfr.data.build_ranking_serving_input_receiver_fn(
        data_format="example_list_with_context",
        context_feature_spec=context_feature_spec,
        example_feature_spec=example_feature_spec)

estimator_path = ranker.export_saved_model("path/to/export", make_serving_input_fn())
1reaction
working-estimatecommented, Jul 22, 2019

can you share an example of how this works with build_raw_serving_input_receiver_fn? The purpose here is to interface with requests that feed features directly instead of through a tf.Example.

def serving_fn():
    features={str(k):tf.placeholder(shape=(1,),dtype=tf.float32) for k in range(_NUM_FEATURES+1)}
    return tf.estimator.export.build_raw_serving_input_receiver_fn(features)()
ranker.export_saved_model(export_dir, serving_fn)

gives the error: ValueError: slice index 1 of dimension 0 out of bounds. for 'groupwise_dnn_v2/infer_sizes/strided_slice_1' (op: 'StridedSlice') with input shapes: [1], [1], [1], [1] and with computed input tensors: input[1] = <1>, input[2] = <2>, input[3] = <1>.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the SavedModel format | TensorFlow Core
For a quick introduction, this section exports a pre-trained Keras model and serves image classification requests with it. The rest of the guide...
Read more >
Using Saved Model Format from Tensorflow Lite Model Maker ...
Following this tutorial I created an simple model for image classification with Tensorflow Model Maker. I changed export format from tflite ...
Read more >
Export TensorFlow models in the SavedModel format
This topic describes how to export TensorFlow models in the SavedModel format. SavedModel format. Before you use the built-in official processor ...
Read more >
Exporting a SavedModel for prediction | AI Platform Prediction
To deploy your trained models to AI Platform Prediction and use them to serve predictions, you must first export them in the TensorFlow...
Read more >
Save, Load and Export Models with Keras - Coursera
We can also export the models to TensorFlow's Saved Mode format which is very useful when serving a model in production, and we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found