0
0
TensorFlowml~20 mins

Loading and inference in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Loading and Inference Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of model prediction after loading
Given the following TensorFlow code that loads a saved model and runs inference on a sample input, what will be the printed output?
TensorFlow
import tensorflow as tf
import numpy as np

model = tf.keras.models.load_model('my_model')
sample_input = np.array([[1.0, 2.0, 3.0]])
prediction = model.predict(sample_input)
print(prediction)
A[[0.3 0.4 0.3]]
BRaises a FileNotFoundError
C[[0.1 0.7 0.2]]
DA numpy array with shape (1, 3) containing probabilities
Attempts:
2 left
💡 Hint
The output shape and type depend on the model's last layer and input shape.
Model Choice
intermediate
1:30remaining
Choosing the correct method to load a TensorFlow model
Which TensorFlow method correctly loads a saved Keras model for inference?
Atf.keras.load('path_to_model')
Btf.saved_model.load('path_to_model')
Ctf.keras.models.load_model('path_to_model')
Dtf.load_model('path_to_model')
Attempts:
2 left
💡 Hint
Keras models have a specific loading function.
Hyperparameter
advanced
2:00remaining
Effect of batch size on inference speed
When performing inference with a loaded TensorFlow model, how does increasing the batch size generally affect inference speed and memory usage?
AInference speed per sample increases and memory usage increases
BInference speed per sample decreases and memory usage increases
CInference speed per sample decreases and memory usage decreases
DInference speed per sample increases and memory usage decreases
Attempts:
2 left
💡 Hint
Think about processing multiple inputs at once.
Metrics
advanced
1:30remaining
Interpreting inference output probabilities
A loaded TensorFlow classification model outputs the following prediction for a single input: [[0.05, 0.9, 0.05]]. What does this output represent?
AThe model predicts class 2 with 90% confidence
BThe model predicts class 1 with 90% confidence
CThe model predicts class 0 with 90% confidence
DThe model output is invalid because probabilities do not sum to 1
Attempts:
2 left
💡 Hint
Look at the highest probability and its index.
🔧 Debug
expert
2:30remaining
Identifying the cause of an error during model loading
You run the following code to load a TensorFlow model saved in 'model_dir', but get the error: "OSError: SavedModel file does not exist at: model_dir". What is the most likely cause?
TensorFlow
import tensorflow as tf
model = tf.keras.models.load_model('model_dir')
AThe path 'model_dir' is incorrect or the directory does not contain a saved model
BThe model was saved using tf.saved_model.save instead of tf.keras.models.save_model
CThe model file is corrupted and cannot be loaded
DTensorFlow version is incompatible with the saved model format
Attempts:
2 left
💡 Hint
Check the file path and directory contents.