0
0
Computer Visionml~10 mins

Raspberry Pi deployment in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Acompile
Brun
Callocate_tensors
Dload_model
Attempts:
3 left
💡 Hint
Common Mistakes
Using load_model() which is not a method of the interpreter.
Trying to run inference before allocating tensors.
2fill in blank
medium

Complete 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'
Aset_tensor
Binput_tensor
Cset_input_tensor
Dfeed_tensor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method set_input_tensor().
Confusing input_tensor as a method instead of a key.
3fill in blank
hard

Fix 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'
Arun_inference
Binvoke
Cexecute
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using run_inference() which does not exist.
Using execute() or predict() which are not TensorFlow Lite methods.
4fill in blank
hard

Fill 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'
A(224, 224)
B0
C1
D(128, 128)
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong image size like (128, 128).
Expanding dims on axis 1 instead of 0.
5fill in blank
hard

Fill 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'
Aoutput_details[0]['index']
B0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong tensor index or batch index.
Mixing up batch indices 0 and 1.