Challenge - 5 Problems
Loading and Inference Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
The output shape and type depend on the model's last layer and input shape.
✗ Incorrect
The model.predict returns a numpy array with shape matching the output layer. Since the model is loaded successfully, it returns a numpy array of probabilities or values, not a fixed hardcoded array.
❓ Model Choice
intermediate1:30remaining
Choosing the correct method to load a TensorFlow model
Which TensorFlow method correctly loads a saved Keras model for inference?
Attempts:
2 left
💡 Hint
Keras models have a specific loading function.
✗ Incorrect
The correct method to load a saved Keras model is tf.keras.models.load_model. The other options are either invalid or used for different purposes.
❓ Hyperparameter
advanced2: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?
Attempts:
2 left
💡 Hint
Think about processing multiple inputs at once.
✗ Incorrect
Increasing batch size allows the model to process more samples simultaneously, often improving throughput (speed per sample), but it also requires more memory to hold the batch data.
❓ Metrics
advanced1: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?
Attempts:
2 left
💡 Hint
Look at the highest probability and its index.
✗ Incorrect
The output is a probability distribution over classes. The highest value 0.9 is at index 1, so the model predicts class 1 with 90% confidence.
🔧 Debug
expert2: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')
Attempts:
2 left
💡 Hint
Check the file path and directory contents.
✗ Incorrect
The error indicates the specified path does not contain the expected saved model files. This usually means the path is wrong or the model was not saved there.