Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a TensorFlow Lite model from a file.
TensorFlow
interpreter = tf.lite.Interpreter(model_path=[1])Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the file name.
Trying to call a function instead of passing a string.
✗ Incorrect
The model_path argument requires a string with the file name, so it must be in quotes.
2fill in blank
mediumComplete the code to allocate tensors for the TensorFlow Lite interpreter.
TensorFlow
interpreter.[1]()Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like load_tensors or init_tensors.
Confusing this step with loading the model.
✗ Incorrect
The correct method to prepare the interpreter for use is allocate_tensors().
3fill in blank
hardFix the error in the code to get the input details from the interpreter.
TensorFlow
input_details = interpreter.[1]()Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like get_input or input_details.
Trying to access input details as a property instead of a method.
✗ Incorrect
The correct method to get input tensor details is get_input_details().
4fill in blank
hardFill both blanks to set the input tensor data correctly.
TensorFlow
interpreter.set_tensor([1], [2])
Attempts:
3 left
💡 Hint
Common Mistakes
Using the shape instead of the index for the first argument.
Passing the wrong variable as input data.
✗ Incorrect
The first argument is the input tensor index, and the second is the input data array.
5fill in blank
hardFill all three blanks to run the interpreter and get the output data.
TensorFlow
interpreter.[1]() output_details = interpreter.[2]() output_data = interpreter.get_tensor([3])
Attempts:
3 left
💡 Hint
Common Mistakes
Calling allocate_tensors() again instead of invoke().
Using wrong method names for output details.
Passing shape instead of index to get_tensor().
✗ Incorrect
invoke() runs the model, get_output_details() gets output info, and get_tensor() fetches output data by index.
