quantize_model

quantize_model(model, keras_model=None, output=None, weights=None, build=False, update_archive=None, tflite_converter_override=None, post_process=False)[source]

Generate a quantized .tflite model file

This uses the Tensorflow TfliteConverter internally. This will also add any metadata to the generated .tflite model file.

Parameters:
  • model (Union[YZLiteModel, str]) – yzlite.core.YZLiteModel instance, name of YZLITE model, path to model archive (.yzlite.zip) or specification script (.py)

  • keras_model (Optional[Model]) –

    Optional, keras_model previously built from given yzlite_model

    • If none, then load keras model from YZLITE model archive’s .h5 file

    • If none and build=True, then build keras model rather that loading archive’s .h5

  • output (Optional[str]) –

    Optional, directory path or file path to generated .tflite file.

    • If none then generate in model log directory and update the model’s archive.

    • If output=’tflite_model’, then return the yzlite.core.TfliteModel object instead of .tflite file path

    NOTE: The model archive is NOT updated if this argument is supplied

  • weights (Optional[str]) – Optional, path to model weights file. This is only used if no keras_model argument is given.

  • build (bool) – If true and keras_model is None, then first build the keras model by training for 1 epoch.. This is useful for visualizing the .tflite without fully training the model first NOTE: The model archive is NOT updated if this argument is supplied

  • update_archive (Optional[bool]) – Update the model archive .yzlite.zip with the generated .tflite file,. If None (default), then determine automatically if the model archive should be updated

  • tflite_converter_override (Optional[dict]) – Dictionary of zero or more yzlite.core.TrainMixin.tflite_converter settings used to override the yzlite.core.TrainMixin.tflite_converter in the model specification NOTE: The model archive is NOT updated if this argument is supplied

  • post_process (bool) – This allows for post-processing the quantization results (e.g. uploading to a cloud) if supported by the given YZLiteModel

Return type:

Union[str, TfliteModel]

Returns:

The file path to the generated .tflite OR TfliteModel object if output=’tflite_model’