tf.compat.v1.saved_model.signature_def_utils.MethodNameUpdater

Updates the method name(s) of the SavedModel stored in the given path.

The MethodNameUpdater class provides the functionality to update the method name field in the signature_defs of the given SavedModel. For example, it can be used to replace the predict method_name to regress.

Typical usages of the MethodNameUpdater

...
updater = tf.compat.v1.saved_model.signature_def_utils.MethodNameUpdater(
    export_dir)
# Update all signature_defs with key "foo" in all meta graph defs.
updater.replace_method_name(signature_key="foo", method_name="regress")
# Update a single signature_def with key "bar" in the meta graph def with
# tags ["serve"]
updater.replace_method_name(signature_key="bar", method_name="classify",
                            tags="serve")
updater.save(new_export_dir)
Note: This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.builder.MethodNameUpdater.
Args
export_dir Directory containing the SavedModel files.
Raises
IOError If the saved model file does not exist, or cannot be successfully parsed.

Methods

replace_method_name

View source

Replaces the method_name in the specified signature_def.

This will match and replace multiple sig defs iff tags is None (i.e when multiple MetaGraphs have a signature_def with the same key). If tags is not None, this will only replace a single signature_def in the MetaGraph with matching tags.

Args
signature_key Key of the signature_def to be updated.
method_name new method_name to replace the existing one.
tags A tag or sequence of tags identifying the MetaGraph to update. If None, all meta graphs will be updated.
Raises
ValueError if signature_key or method_name are not defined or if no metagraphs were found with the associated tags or if no meta graph has a signature_def that matches signature_key.

save

View source

Saves the updated SavedModel.

Args
new_export_dir Path where the updated SavedModel will be saved. If None, the input SavedModel will be overriden with the updates.
Raises
errors.OpError If there are errors during the file save operation.

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/compat/v1/saved_model/signature_def_utils/MethodNameUpdater