Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a TensorFlow Lite model on Raspberry Pi.
Computer Vision
import tflite_runtime.interpreter as tflite interpreter = tflite.Interpreter(model_path='model.tflite') interpreter.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using load_model() which is not a method of the interpreter.
Trying to run inference before allocating tensors.
✗ Incorrect
The method allocate_tensors() prepares the model's tensors for inference on Raspberry Pi.
2fill in blank
mediumComplete the code to set the input tensor for the model on Raspberry Pi.
Computer Vision
input_details = interpreter.get_input_details() input_data = ... # preprocessed input image interpreter.[1](input_details[0]['index'], input_data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method set_input_tensor().
Confusing input_tensor as a method instead of a key.
✗ Incorrect
The method set_tensor() sets the input tensor data for the interpreter.
3fill in blank
hardFix the error in the code to run inference on Raspberry Pi.
Computer Vision
interpreter.[1]() output_details = interpreter.get_output_details() output_data = interpreter.get_tensor(output_details[0]['index'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using run_inference() which does not exist.
Using execute() or predict() which are not TensorFlow Lite methods.
✗ Incorrect
The correct method to run inference is invoke() in TensorFlow Lite interpreter.
4fill in blank
hardFill both blanks to preprocess an image for Raspberry Pi model input.
Computer Vision
from PIL import Image import numpy as np image = Image.open('input.jpg').resize([1]) input_data = np.expand_dims(np.array(image), axis=[2]).astype(np.float32)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong image size like (128, 128).
Expanding dims on axis 1 instead of 0.
✗ Incorrect
The image is resized to (224, 224) and expanded along axis 0 to add batch dimension.
5fill in blank
hardFill all three blanks to postprocess the model output on Raspberry Pi.
Computer Vision
output_details = interpreter.get_output_details() output_data = interpreter.get_tensor([1]) predicted_label = np.argmax(output_data[[2]]) confidence = output_data[[3]][predicted_label]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong tensor index or batch index.
Mixing up batch indices 0 and 1.
✗ Incorrect
We get the output tensor index, then use batch 0 to find predicted label and confidence.