使用tflite并获得解释器的属性,如:
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)是什么意思?
发布于 2019-02-27 09:43:31
它是指量化参数值:输入张量的标度和zero_point。
这对于使用公式将量化的uint8数字q转换为浮点数f是必要的:
f = (q - zero_point) * scale发布于 2021-04-15 20:15:36
不幸的是,get_input_details没有解释:
返回:输入详细信息列表。
但是,如果您查看源代码get_input_details,它会调用_get_tensor_details (来源),并且这个函数确实记录了它:
"""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) + zf = (q - z) * s注:Aleksandr Kondratyev的方程f = (q - zero_point) * scale实际上是去量化的,因为它取q(量化值),并给你f(浮点)。当然,你可以反转这个方程得到另一个。
https://stackoverflow.com/questions/54830126
复制相似问题