Both of these functions allow to save the model using the SavedModel format Using the SavedModel format | TensorFlow Core but only keras allows to disable or enable tracing, the tf.saved_model does not. Why is that? Can I save a model using tf.saved_model without tracing? I noticed keras is storing some metadata. Is this related to it? Also, keras allows passing custom objects, but tf.saved_model does not. Why is that?
TFX serving says it supports models stored in SavedModel format Serving a TensorFlow Model | TFX but it works only when model is stored using tf.saved_model, but not tf.keras.models.save_model.
What are the differences?
And more importantly, can I somehow save a model using tf.keras.models.save_model so it would work with TFX serving? If so, with which parameters it works and with which parameters it does not work?
1 Like
tf.saved_model
always traces model execution to create a concrete graph for compatibility. You can use the Keras API’s tf.keras.models.save_model()
with save_format='tf'
option to save without tracing and preserving original structure for later flexibility.
model.save('path/to/saved_model', save_format='tf')
Please refer to the tf.keras.saving.save_model for more detailed understand in this API. Thank you.
1 Like