0
0
Computer Visionml~10 mins

Mobile deployment (TFLite, Core ML) 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 convert a TensorFlow model to TensorFlow Lite format.

Computer Vision
import tensorflow as tf

model = tf.keras.models.load_model('model.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.[1]()
Drag options to blanks, or click blank then click option'
Acompile
Bconvert
Csave
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'compile()' instead of 'convert()' which is for preparing the model for training.
Using 'save()' which saves the model but does not convert it.
Using 'fit()' which trains the model.
2fill in blank
medium

Complete the code to load a Core ML model in Swift for iOS deployment.

Computer Vision
import CoreML

guard let model = try? [1](configuration: MLModelConfiguration()) else {
    fatalError("Failed to load model")
}
Drag options to blanks, or click blank then click option'
AMyModel
BMLModel
CVNCoreMLModel
DMLModelConfiguration
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'MLModel' directly instead of the generated model class.
Confusing 'VNCoreMLModel' which is for Vision framework.
Using 'MLModelConfiguration' as a model instance.
3fill in blank
hard

Fix the error in the TensorFlow Lite interpreter initialization code.

Computer Vision
import tensorflow as tf

interpreter = tf.lite.Interpreter(model_path='model.tflite')
interpreter.[1]()
Drag options to blanks, or click blank then click option'
Aprepare
Bload_tensors
Cinitialize
Dallocate_tensors
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load_tensors()' which does not exist.
Using 'initialize()' or 'prepare()' which are not valid methods.
4fill in blank
hard

Fill both blanks to create a dictionary mapping input names to input data for TFLite inference.

Computer Vision
input_details = interpreter.get_input_details()
input_data = [1]
inputs = {input_details[0]['name']: [2]
Drag options to blanks, or click blank then click option'
Anp.array([1.0, 2.0, 3.0], dtype=np.float32)
Binput_data
Cnp.array([0.0, 0.0, 0.0], dtype=np.float32)
Dinput_details
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'input_details' as input data.
Using a zero array instead of actual input values.
Not matching the input name to the data variable.
5fill in blank
hard

Fill all three blanks to run inference and get the output tensor from a TFLite interpreter.

Computer Vision
interpreter.set_tensor(input_details[0]['index'], [1])
interpreter.[2]()
output_data = interpreter.get_tensor(output_details[0]['[3]'])
Drag options to blanks, or click blank then click option'
Ainput_data
Binvoke
Cindex
Doutput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'output' instead of 'index' to get tensor.
Calling a wrong method instead of 'invoke()'.
Passing wrong variable to set_tensor.