Complete the code to import the TensorFlow monitoring module.
import tensorflow as tf from tensorflow import [1]
The monitoring module in TensorFlow is used to track metrics and monitor deployed models.
Complete the code to create a counter metric for monitoring prediction requests.
prediction_counter = tf.monitoring.Counter('[1]', 'Counts prediction requests')
The metric name should be descriptive and follow naming conventions like prediction_requests_total to count prediction requests.
Fix the error in the code to correctly increment the prediction counter.
def on_prediction(): [1].add(1)
increment() method which does not exist.The Counter object uses the add() method to increment. Calling add(1) on the counter variable is correct.
Fill both blanks to create a gauge metric and set its value.
latency_gauge = tf.monitoring.[1]('prediction_latency_seconds', 'Tracks prediction latency in seconds') latency_gauge.[2](0.25)
Counter instead of Gauge for latency.add() method on a gauge which expects set().A Gauge metric tracks values that can go up or down, like latency. Use set() to assign the current latency value.
Fill both blanks to create a dictionary comprehension that filters metrics with values greater than zero.
filtered_metrics = {k:v for k, v in metrics.items() if v [1] 0 and isinstance(v, [2])}The dictionary comprehension uses : to separate keys and values, filters values greater than zero with >, and checks if values are integers with int.
