Which of the following best describes the main components inside a TensorFlow SavedModel directory?
Think about what files TensorFlow saves when you use model.save('path') with the default format.
The SavedModel format saves the model as a directory containing a saved_model.pb file which holds the model architecture and computation graph, plus a variables folder that contains the trained weights.
What will be the output of the following code snippet?
import tensorflow as tf
model = tf.keras.Sequential([tf.keras.layers.Dense(1)])
model.save('my_model')
loaded_model = tf.keras.models.load_model('my_model')
print(type(loaded_model))Consider what type of object load_model returns when loading a Keras model saved in SavedModel format.
The load_model function returns a Keras Sequential object, which is of type tensorflow.keras.models.Sequential.
You have a trained TensorFlow Keras model and want to save it in the SavedModel format for later use in TensorFlow Serving. Which method should you use?
Think about the recommended way to save a full Keras model including architecture and weights in SavedModel format.
Using model.save('path', save_format='tf') saves the entire model in SavedModel format, including architecture, weights, and optimizer state. The tf.saved_model.save function is lower level and requires a concrete function. Saving weights only does not save the architecture. Saving with save_format='h5' saves in HDF5 format, not SavedModel.
When saving a TensorFlow model using tf.saved_model.save, what is the effect of specifying the signatures argument?
Think about why TensorFlow Serving needs information about inputs and outputs.
The signatures argument specifies the input and output formats (signatures) of the model functions. This helps TensorFlow Serving or other tools know how to call the model correctly.
You saved a TensorFlow model using model.save('my_model'). Later, when you try to load it with tf.keras.models.load_model('my_model'), you get the error:
ValueError: No model found in config.
What is the most likely cause of this error?
Consider what happens if the model has custom components that TensorFlow does not know about by default.
If the model has custom layers or functions, you must provide them via the custom_objects argument when loading. Otherwise, TensorFlow cannot reconstruct the model architecture and raises this error.