Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The method 'convert()' converts the Keras model to TensorFlow Lite format.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
You instantiate your specific Core ML model class (e.g., 'MyModel') to load it.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load_tensors()' which does not exist.
Using 'initialize()' or 'prepare()' which are not valid methods.
✗ Incorrect
You must call 'allocate_tensors()' to prepare the interpreter before inference.
4fill in blank
hardFill 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'
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.
✗ Incorrect
First, input_data is created as a numpy array, then the dictionary maps the input name to input_data.
5fill in blank
hardFill 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'
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.
✗ Incorrect
You set the input tensor with input_data, call 'invoke()' to run inference, then get the output tensor by 'index'.