【发布时间】:2021-03-05 02:29:26
【问题描述】:
在我使用的之前的 TensorFlow 版本 (1.9) 中,我能够使用存储在 Conv2D 操作输入中的 UINT8 权重来量化我的网络。现在使用使用 Keras 模型的 TensorFlow 2.0,训练后量化为我提供了 INT8 权重,似乎没有无符号权重的选项。 TF 2.0不能控制Conv层权重的符号吗?
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
def representative_dataset_gen():
for _ in range(num_calibration_steps):
# Get sample input data as a numpy array in a method of your choosing.
yield [input]
converter.representative_dataset = representative_dataset_gen
# there is no such tf.lite.OpsSet.TFLITE_BUILTINS_UINT8
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8 # or tf.int8 ( note this has zero effect on the tensors produced for Conv2D operations -- all of which include signed int8 unless you were to output the model as float16/32 )
converter.inference_output_type = tf.uint8 # or tf.int8
tflite_quant_model = converter.convert()
【问题讨论】:
标签: python tensorflow tensorflow2.0 convolution quantization