Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a saved TensorFlow model.
TensorFlow
import tensorflow as tf model = tf.keras.models.[1]('my_model')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using save_model instead of load_model
Trying to compile or fit the model during loading
✗ Incorrect
The function load_model loads a saved TensorFlow model from disk.
2fill in blank
mediumComplete the code to make predictions using the loaded model.
TensorFlow
predictions = model.[1](input_data) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit or train instead of predict
Using evaluate which returns loss and metrics
✗ Incorrect
The predict method is used to get the model's output for new input data.
3fill in blank
hardFix the error in the code to load a model from the file 'model.h5'.
TensorFlow
model = tf.keras.models.load_model([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the filename without quotes
Passing a variable name instead of a string
✗ Incorrect
The file path must be a string, so it needs quotes around it.
4fill in blank
hardFill both blanks to create a dictionary of predictions for each input sample.
TensorFlow
results = {i: model.[1](sample) for i, sample in enumerate([2])} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit or evaluate instead of predict
Using wrong variable name for input data
✗ Incorrect
Use predict to get predictions for each sample in input_data.
5fill in blank
hardFill all three blanks to load a model, make predictions, and print the results.
TensorFlow
model = tf.keras.models.[1]('saved_model') preds = model.[2](test_data) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict
Printing the wrong variable
Not using quotes for the model path
✗ Incorrect
Load the model with load_model, predict with predict, and print the predictions stored in preds.