【问题标题】:TensorFlow 2.0 TFLite Quantized export with UINT8 weights具有 UINT8 权重的 TensorFlow 2.0 TFLite 量化导出
【发布时间】: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


    【解决方案1】:

    最新版本的 TensorFlow (2.5) 在卷积网络上使用了更强大的量化方案,其中每个滤波器深度映射到不同的量化级别。目前还没有办法利用之前的方法。

    【讨论】:

    • 嗨,我有类似的需要将我的模型量化为 UINT8 ,你能分享一下如何在 tensorflow 1.9 中做到这一点吗?非常感谢!
    • 这是否意味着 TF 2.x 不支持 UINT8 量化?
    • @ai2ys 据我所知,是的。签名的 int8 方法是前进的方向,如果有帮助的话,我可以报告它确实提高了当前实现的性能。
    • @Kalen 我特意要求支持 uint8,因为硬件只支持 uint8 操作。我希望将 TF 用于量化任务而不是供应商工具。
    • @ai2ys 据我所知,导出中涉及的 tf2x 脚本在将 uint8 作为参数时其功能为零。我尝试了当时可用的所有排列都无济于事。我建议使用早期版本。
    猜你喜欢
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多