Skip to content

Commit

Permalink
Fix erroneous quantization operations in TFLite model (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Dec 21, 2024
1 parent cdbf64e commit ac6502b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions microwakeword/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ def representative_dataset_gen():
converter = tf.lite.TFLiteConverter.from_saved_model(path_to_model)
converter.optimizations = {tf.lite.Optimize.DEFAULT}

# Without this flag, the Streaming layer `state` variables are left as float32,
# resulting in Quantize and Dequantize operations before and after every `ReadVariable`
# and `AssignVariable` operation.
converter._experimental_variable_quantization = True

if quantize:
converter.target_spec.supported_ops = {tf.lite.OpsSet.TFLITE_BUILTINS_INT8}
converter.inference_input_type = tf.int8
Expand Down

0 comments on commit ac6502b

Please sign in to comment.