SavedModel conversion to integer (quantized) TFLite reports error because of fused ops #36
Labels
enhancement
New feature or request
model support
Add support for certain models that don't work with the current version
Hello,
Firstly, thank you for publishing and maintaining this lib.
Package versions used in my setup are tfjs-graph-converter 1.5.0 and tensorflow 2.8.0.
I have been experimenting the lib with MediaPipe Blazeface TFJS model from TensorFlow Hub:
https://tfhub.dev/tensorflow/tfjs-model/blazeface/1/default/1?tfjs-format=compressed
TFJS model archive
blazeface_1_default_1.tar.gz
is extracted to:Conversion to SavedModel is then operated using lib CLI:
Resulting saved_model can be converted to float32 TFLite model with:
Conversion to float32 TFLite succeeds with notice:
TFLite interpreter needs to link Flex delegate in order to run the model since it contains the following Select TFop(s): Flex ops: Flex_FusedConv2D
Conversion to integer (quantized) version is done replacing converter
supported_ops
as below:This time conversion fails because _FusedConv2D operator does not exist in TFLITE INT8 operation set:
With this model, 2 fused operators cause issue for quantization and need to be split before conversion:
Conv2D + BiasAdd
Conv2D + BiasAdd + Relu
There is no fused MatMul op in this model, but I presume it would have needed to be split too.
Lib implementation currently supports multiple case of fused op split, for instance:
_FusedConv2D( BiasAdd, Prelu) -> Conv2D + BiasAdd + Prelu
Therefore, with a local hack of
is_fused_conv2d()' and
_split_fused_op()' functions, I unconditonally split the faulty ops:_FusedConv2D( BiasAdd, Relu) -> Conv2D + BiasAdd + Relu
_FusedConv2D( BiasAdd) -> Conv2D + BiasAdd
It enabled conversion of the saved_model to a functional quantized TFLite model.
Would you consider adding a 'TFLite' compatibility mode to the lib, that would consistently split all fused operators present in the saved_model?
Such mode could be every useful for 2 use cases of TFLite conversions:
corresponds to:
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]
corresponds to:
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
Thank you for your support
The text was updated successfully, but these errors were encountered: