View source on GitHub |
Configuration for post-training quantization.
mediapipe_model_maker.quantization.QuantizationConfig(
optimizations: Optional[Union[tf.lite.Optimize, List[tf.lite.Optimize]]] = None,
representative_data: Optional[mediapipe_model_maker.model_util.dataset.Dataset
] = None,
quantization_steps: Optional[int] = None,
inference_input_type: Optional[tf.dtypes.DType] = None,
inference_output_type: Optional[tf.dtypes.DType] = None,
supported_ops: Optional[Union[tf.lite.OpsSet, List[tf.lite.OpsSet]]] = None,
supported_types: Optional[Union[tf.dtypes.DType, List[tf.dtypes.DType]]] = None,
experimental_new_quantizer: bool = False
)
Refer to https://www.tensorflow.org/lite/performance/post_training_quantization for different post-training quantization options.
Raises | |
---|---|
ValueError
|
if inference_input_type or inference_output_type are set but not in {tf.float32, tf.uint8, tf.int8}. |
Methods
for_dynamic
@classmethod
for_dynamic() -> 'QuantizationConfig'
Creates configuration for dynamic range quantization.
for_float16
@classmethod
for_float16() -> 'QuantizationConfig'
Creates configuration for float16 quantization.
for_int8
@classmethod
for_int8( representative_data:
mediapipe_model_maker.model_util.dataset.Dataset
, quantization_steps: int = DEFAULT_QUANTIZATION_STEPS, inference_input_type: tf.dtypes.DType = tf.uint8, inference_output_type: tf.dtypes.DType = tf.uint8, supported_ops: tf.lite.OpsSet = tf.lite.OpsSet.TFLITE_BUILTINS_INT8 ) -> 'QuantizationConfig'
Creates configuration for full integer quantization.
Args | |
---|---|
representative_data
|
Representative data used for post-training quantization. |
quantization_steps
|
Number of post-training quantization calibration steps to run. |
inference_input_type
|
Target data type of real-number input arrays. |
inference_output_type
|
Target data type of real-number output arrays. |
supported_ops
|
Set of tf.lite.OpsSet options, where each option
represents a set of operators supported by the target device.
|
Returns | |
---|---|
QuantizationConfig. |
set_converter_with_quantization
set_converter_with_quantization(
converter: tf.lite.TFLiteConverter, **kwargs
) -> tf.lite.TFLiteConverter
Sets input TFLite converter with quantization configurations.
Args | |
---|---|
converter
|
input tf.lite.TFLiteConverter. |
**kwargs
|
arguments used by ds.Dataset.gen_tf_dataset. |
Returns | |
---|---|
tf.lite.TFLiteConverter with quantization configurations. |