首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在interpreter.get_input_details()中“量子化”是什么意思?

在interpreter.get_input_details()中“量子化”是什么意思?
EN

Stack Overflow用户
提问于 2019-02-22 15:18:04
回答 2查看 1K关注 0票数 5

使用tflite并获得解释器的属性,如:

代码语言:javascript
复制
print(interpreter.get_input_details())

[{'name': 'input_1_1', 'index': 47, 'shape': array([  1, 128, 128,   3], dtype=int32), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.003921568859368563, 0)}]

'quantization': (0.003921568859368563, 0)是什么意思?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-27 09:43:31

它是指量化参数值:输入张量的标度和zero_point。

这对于使用公式将量化的uint8数字q转换为浮点数f是必要的:

代码语言:javascript
复制
f = (q - zero_point) * scale
票数 5
EN

Stack Overflow用户

发布于 2021-04-15 20:15:36

不幸的是,get_input_details没有解释:

返回:输入详细信息列表。

但是,如果您查看源代码get_input_details,它会调用_get_tensor_details (来源),并且这个函数确实记录了它:

代码语言:javascript
复制
    """Gets tensor details.
    Args:
      tensor_index: Tensor index of tensor to query.
    Returns:
      A dictionary containing the following fields of the tensor:
        'name': The tensor name.
        'index': The tensor index in the interpreter.
        'shape': The shape of the tensor.
        'quantization': Deprecated, use 'quantization_parameters'. This field
            only works for per-tensor quantization, whereas
            'quantization_parameters' works in all cases.
        'quantization_parameters': The parameters used to quantize the tensor:
          'scales': List of scales (one if per-tensor quantization)
          'zero_points': List of zero_points (one if per-tensor quantization)
          'quantized_dimension': Specifies the dimension of per-axis
              quantization, in the case of multiple scales/zero_points.

什么意思?

这些量化参数是用于量化的值(将数字的范围从一个范围转换到另一个更有限的范围,例如0-10到0-1)。在TensorFlow中,这是指当数据类型更改为支持较少数字的数据类型时:例如,float32到float16,float32到uint8,float16到int8。反量化是相反的(例如,当您希望从量化到uint8且量化输出在0-255之间的模型中获取概率时)。

数学非常简单,就像一种更一般的形式规范化(使某些内容从(0到1)不等):

  • 量化:q = (f / s) + z
  • 去量化:f = (q - z) * s
  • 有关这个量化方程的更多信息,请参见量化规范

注:Aleksandr Kondratyev的方程f = (q - zero_point) * scale实际上是去量化的,因为它取q(量化值),并给你f(浮点)。当然,你可以反转这个方程得到另一个。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54830126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档