How to change the signatures of my SavedModel without retraining the model?

I just finished training my model to find out that I exported a model for a service that had signature problems. How to update them?

(One of the common problems is installing the wrong form for CloudML Engine).

+1
source share
1 answer

Do not worry - you do not need to retrain your model. However, little work remains to be done. You are about to create a new (adjusted) service schedule, load breakpoints into this graph, and then export this schedule.

, , placeholder, , (, CloudML). :

x = tf.placeholder(tf.float32)
y = foo(x)
...

:

# Create the *correct* graph
with tf.Graph().as_default() as new_graph:
  x = tf.placeholder(tf.float32, shape=[None])
  y = foo(x)
  saver = tf.train.Saver()

# (Re-)define the inputs and the outputs.
inputs = {"x": tf.saved_model.utils.build_tensor_info(x)}
outputs = {"y": tf.saved_model.utils.build_tensor_info(y)}
signature = tf.saved_model.signature_def_utils.build_signature_def(
    inputs=inputs,
    outputs=outputs,
    method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME
)

with tf.Session(graph=new_graph) as session:
  # Restore the variables
  vars_path = os.path.join(old_export_dir, 'variables', 'variables')
  saver.restore(session, vars_path)

  # Save out the corrected model
  b = builder.SavedModelBuilder(new_export_dir)
  b.add_meta_graph_and_variables(session, ['serving_default'], signature)
  b.save()
+1

Source: https://habr.com/ru/post/1672179/


All Articles