Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a TensorFlow Lite converter from a saved model.
TensorFlow
import tensorflow as tf converter = tf.lite.TFLiteConverter.from_[1]('saved_model_dir')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using from_keras_model() when the model is saved as a saved model directory.
Confusing from_concrete_function() with from_saved_model().
✗ Incorrect
The method from_saved_model() creates a converter from a saved TensorFlow model directory.
2fill in blank
mediumComplete the code to convert the TensorFlow model to TensorFlow Lite format.
TensorFlow
tflite_model = converter.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using save() which does not exist on the converter object.
Using compile() which is unrelated to conversion.
✗ Incorrect
The convert() method runs the conversion and returns the TensorFlow Lite model as bytes.
3fill in blank
hardFix the error in saving the TensorFlow Lite model to a file.
TensorFlow
with open('model.tflite', 'wb') as f: f.[1](tflite_model)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using writelines() which causes a TypeError with bytes.
Using save() which is not a file method.
✗ Incorrect
The write() method writes bytes to a file. writelines() expects an iterable of strings.
4fill in blank
hardFill both blanks to enable post-training quantization for the converter.
TensorFlow
converter.optimizations = [[1].DEFAULT] converter.target_spec.supported_types = [[2].int8]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using tf.lite.Quantize which does not exist.
Confusing Converter class with optimization enums.
✗ Incorrect
tf.lite.Optimize.DEFAULT enables default optimizations including quantization. tf.int8 specifies INT8 data type support.
5fill in blank
hardFill all three blanks to convert a Keras model to TensorFlow Lite and save it.
TensorFlow
import tensorflow as tf converter = tf.lite.TFLiteConverter.from_[1](keras_model) tflite_model = converter.[2]() with open('model.tflite', '[3]') as f: f.write(tflite_model)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using from_saved_model() for Keras model.
Opening file in text mode instead of binary mode.
Using save() instead of convert().
✗ Incorrect
Use from_keras_model() to create converter from Keras model, convert() to convert, and 'wb' mode to write binary file.