tensorflow / model-optimization

A toolkit to optimize ML models for deployment for Keras and TensorFlow, including quantization and pruning.
https://www.tensorflow.org/model_optimization
Apache License 2.0
1.49k stars 319 forks source link

Unsupported operations when applying tfmot #941

Open Rahn80643 opened 2 years ago

Rahn80643 commented 2 years ago

Hi, I'm trying to apply tfmot for an implementation of BiSeNetV2, when executing tfmot.quantization.keras.quantize_model, I meet errors with the following operations:

tf.reduce_mean: Layer tf.math.reduce_mean:<class 'tensorflow.python.keras.layers.core.TFOpLambda'> is not supported. You can quantize this layer by passing a tfmot.quantization.keras.QuantizeConfig instance to the quantize_annotate_layer API. tf.nn.sigmoid: Exception has occurred: RuntimeError Layer tf.math.sigmoid_1:<class 'tensorflow.python.keras.layers.core.TFOpLambda'> is not supported. You can quantize this layer by passing a tfmot.quantization.keras.QuantizeConfig instance to the quantize_annotate_layer API.

tf.image.resize: Exception has occurred: ValueError 'images' must have either 3 or 4 dimensions.

  1. For layer tf.reduce_mean and tf.nn.sigmoid, the class is tensorflow.python.keras.layers.core.TFOpLambda, and they are failed to be executed with tfmot.quantization.keras.QuantizeConfig. How to apply these layers to tfmot?
  2. How to effectively apply tf.image.resize to tfmot model?

The followings are the settings of TensorFlow: TensorFlow-gpu 2.4.0 tensorflow-model-optimization 0.7.1

Best Regards, Rahn

thaink commented 2 years ago

@Xhark Could you take a look.