Created
September 17, 2018 05:53
-
-
Save yuhanz/a5d783af813f66c566bd31387f719120 to your computer and use it in GitHub Desktop.
Convert a trained keras model .h5 file into tensorflow saved model
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
| from keras.models import load_model | |
| import numpy as np | |
| model = load_model('trained_keras_model.h5') | |
| from keras import backend as K | |
| import tensorflow as tf | |
| signature = tf.saved_model.signature_def_utils.predict_signature_def( | |
| inputs={'image': model.input}, outputs={'scores': model.output}) | |
| builder = tf.saved_model.builder.SavedModelBuilder('/tmp/my_saved_model') | |
| builder.add_meta_graph_and_variables( | |
| sess=K.get_session(), | |
| tags=[tf.saved_model.tag_constants.SERVING], | |
| signature_def_map={ | |
| tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: | |
| signature | |
| }) | |
| builder.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TensorFlow 2.x