0
0
TensorFlowml~20 mins

SavedModel format in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SavedModel Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the SavedModel directory structure

Which of the following best describes the main components inside a TensorFlow SavedModel directory?

AA Python script that recreates the model architecture and loads weights from a checkpoint.
BA single '.h5' file that stores the entire model including architecture and weights.
CA JSON file describing the model architecture and a separate binary file for weights.
DA directory containing a 'saved_model.pb' file and a 'variables' folder with model weights.
Attempts:
2 left
💡 Hint

Think about what files TensorFlow saves when you use model.save('path') with the default format.

Predict Output
intermediate
2:00remaining
Output of loading a SavedModel

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))
A<class 'tensorflow.keras.models.Sequential'>
B<class 'tensorflow.saved_model.LoadedModel'>
CAttributeError: module 'tensorflow.keras.models' has no attribute 'load_model'
D<class 'tensorflow.keras.models.Model'>
Attempts:
2 left
💡 Hint

Consider what type of object load_model returns when loading a Keras model saved in SavedModel format.

Model Choice
advanced
2:00remaining
Choosing the correct method to save a TensorFlow model in SavedModel format

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?

Atf.saved_model.save(model, 'path_to_dir')
Bmodel.save('path_to_dir', save_format='tf')
Cmodel.save_weights('path_to_dir')
Dtf.keras.models.save_model(model, 'path_to_dir', save_format='h5')
Attempts:
2 left
💡 Hint

Think about the recommended way to save a full Keras model including architecture and weights in SavedModel format.

Hyperparameter
advanced
2:00remaining
Effect of including signatures when saving a SavedModel

When saving a TensorFlow model using tf.saved_model.save, what is the effect of specifying the signatures argument?

AIt automatically tunes hyperparameters during saving for better performance.
BIt compresses the SavedModel files to reduce disk space usage.
CIt defines the input and output signatures for serving, enabling TensorFlow Serving to know how to call the model.
DIt encrypts the SavedModel to protect the model weights.
Attempts:
2 left
💡 Hint

Think about why TensorFlow Serving needs information about inputs and outputs.

🔧 Debug
expert
3:00remaining
Diagnosing a loading error with a SavedModel

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?

AThe model contains custom layers or objects but they were not provided during loading.
BThe model was saved in HDF5 format but loaded as SavedModel format.
CThe TensorFlow version used to load is older than the version used to save.
DThe SavedModel directory is missing the 'variables' folder.
Attempts:
2 left
💡 Hint

Consider what happens if the model has custom components that TensorFlow does not know about by default.