Created
February 12, 2019 10:35
-
-
Save morenoh149/7156f8586482adbbcf478761c08dfcca to your computer and use it in GitHub Desktop.
Tensorflow serve on Sagemaker
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 export_h5_to_pb(path_to_h5, export_path): | |
# Set the learning phase to Test since the model is already trained. | |
K.set_learning_phase(0) | |
# Load the Keras model | |
keras_model = load_model(path_to_h5) | |
# Build the Protocol Buffer SavedModel at 'export_path' | |
builder = saved_model_builder.SavedModelBuilder(export_path) | |
# Create prediction signature to be used by TensorFlow Serving Predict API | |
signature = predict_signature_def(inputs={"images": keras_model.input}, | |
outputs={"scores": keras_model.output}) | |
with K.get_session() as sess: | |
# Save the meta graph and the variables | |
builder.add_meta_graph_and_variables(sess=sess, tags=[tag_constants.SERVING], | |
signature_def_map={"serving_default": signature}) | |
builder.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment