【问题标题】:Float 16 quantized Tflite model not working for custom models?Float 16 量化 Tflite 模型不适用于自定义模型?
【发布时间】:2021-04-18 22:46:39
【问题描述】:

我有一个自定义 tensorflow 模型,我使用 here 中提到的 Float16 量化将其转换为 tflite。
但是使用 tflite 解释器的 tflite 模型的输入细节是

[{'name': 'input_1',
  'index': 0,
  'shape': array([  1, 256, 256,   3], dtype=int32),
  'shape_signature': array([ -1, 256, 256,   3], dtype=int32),
  'dtype': numpy.float32,
  'quantization': (0.0, 0),
  'quantization_parameters': {'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32),
   'quantized_dimension': 0},
  'sparsity_parameters': {}}]

而输出细节是

[{'name': 'Identity',
  'index': 636,
  'shape': array([  7,   1, 256, 256,   1], dtype=int32),
  'shape_signature': array([  7,  -1, 256, 256,   1], dtype=int32),
  'dtype': numpy.float32,
  'quantization': (0.0, 0),
  'quantization_parameters': {'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32),
   'quantized_dimension': 0},
  'sparsity_parameters': {}}]

转换有问题吗?

我在将 tf 模型转换为 tflite 时也收到此警告

WARNING:absl:Found untraced functions such as _defun_call, _defun_call, _defun_call, _defun_call, _defun_call while saving (showing 5 of 63). These functions will not be directly callable after loading.
WARNING:absl:Found untraced functions such as _defun_call, _defun_call, _defun_call, _defun_call, _defun_call while saving (showing 5 of 63). These functions will not be directly callable after loading.

P.S我也尝试过进行this 量化,但收到了与该 tflite 模型相同的输入/输出细节。

【问题讨论】:

    标签: python tensorflow tensorflow-lite


    【解决方案1】:

    Float16 和训练后量化不会修改输入/输出张量,而只会修改中间权重张量。上述行为看起来像预期的行为。如果您想完全量化您的模型,请尝试完全整数量化。您可以在here找到详细信息。

    【讨论】:

    • 但 GPU 委托不支持这种类型的整数量化。我希望我的模型支持 GPU 委托
    • 在这种情况下,您可以坚持使用 float16 模式。但是,float16 模式不会改变输入/输出张量类型,但它会在 GPU 委托执行期间使用 float16 权重。
    • 转换过程中的警告是怎么回事,是否意味着某些层不支持?
    • 我认为你可以忽略它们。
    猜你喜欢
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多