Created
December 5, 2017 17:53
-
-
Save gauravkaila/772e12a948bd868d8d6e48b5fae3ab57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _write_saved_model(saved_model_path, | |
trained_checkpoint_prefix, | |
inputs, | |
outputs): | |
"""Writes SavedModel to disk. | |
Args: | |
saved_model_path: Path to write SavedModel. | |
trained_checkpoint_prefix: path to trained_checkpoint_prefix. | |
inputs: The input image tensor to use for detection. | |
outputs: A tensor dictionary containing the outputs of a DetectionModel. | |
""" | |
saver = tf.train.Saver() | |
with session.Session() as sess: | |
saver.restore(sess, trained_checkpoint_prefix) | |
builder = tf.saved_model.builder.SavedModelBuilder(saved_model_path) | |
tensor_info_inputs = { | |
'inputs': tf.saved_model.utils.build_tensor_info(inputs)} | |
tensor_info_outputs = {} | |
for k, v in outputs.items(): | |
tensor_info_outputs[k] = tf.saved_model.utils.build_tensor_info(v) | |
detection_signature = ( | |
tf.saved_model.signature_def_utils.build_signature_def( | |
inputs=tensor_info_inputs, | |
outputs=tensor_info_outputs, | |
method_name=signature_constants.PREDICT_METHOD_NAME)) | |
builder.add_meta_graph_and_variables( | |
sess, [tf.saved_model.tag_constants.SERVING], | |
signature_def_map={ | |
'detection_signature': | |
detection_signature, | |
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: | |
detection_signature, | |
}, | |
) | |
builder.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment