Last active
February 8, 2021 05:30
-
-
Save zh3389/5d0bf3b5b8e9f72c2d79379872ce9674 to your computer and use it in GitHub Desktop.
tensorflow sample_save 保存模型示例
This file contains 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
import tensorflow as tf | |
# The export path contains the name and the version of the model | |
tf.keras.backend.set_learning_phase(0) # Ignore dropout at inference | |
model = tf.keras.models.load_model('./inception.h5') # 需要加载的模型路径 | |
export_path = '../my_image_classifier/1' # 将要导出模型的路径 | |
# Fetch the Keras session and save the model | |
# The signature definition is defined by the input and output tensors | |
# And stored with the default serving key | |
with tf.keras.backend.get_session() as sess: | |
tf.saved_model.simple_save( | |
sess, | |
export_path, | |
inputs={'input': model.input}, | |
outputs={t.name: t for t in model.outputs}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment