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

使用 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)意思?


慕仙森
浏览 524回答 2
2回答

长风秋雁

这意味着量化参数值:输入张量的比例和零点。这是使用公式将量化的 uint8 数 q 转换为浮点数 f 所必需的:f&nbsp;=&nbsp;(q&nbsp;-&nbsp;zero_point)&nbsp;*&nbsp;scale

ITMISS

不幸的是,文档get_input_details没有解释:Returns: A list of input details.但是,如果您查看源代码get_input_details,它会调用_get_tensor_details( source ),并且此函数确实记录了它:&nbsp; &nbsp; """Gets tensor details.&nbsp; &nbsp; Args:&nbsp; &nbsp; &nbsp; tensor_index: Tensor index of tensor to query.&nbsp; &nbsp; Returns:&nbsp; &nbsp; &nbsp; A dictionary containing the following fields of the tensor:&nbsp; &nbsp; &nbsp; &nbsp; 'name': The tensor name.&nbsp; &nbsp; &nbsp; &nbsp; 'index': The tensor index in the interpreter.&nbsp; &nbsp; &nbsp; &nbsp; 'shape': The shape of the tensor.&nbsp; &nbsp; &nbsp; &nbsp; 'quantization': Deprecated, use 'quantization_parameters'. This field&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; only works for per-tensor quantization, whereas&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'quantization_parameters' works in all cases.&nbsp; &nbsp; &nbsp; &nbsp; 'quantization_parameters': The parameters used to quantize the tensor:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'scales': List of scales (one if per-tensor quantization)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'zero_points': List of zero_points (one if per-tensor quantization)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'quantized_dimension': Specifies the dimension of per-axis&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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)):量化:&nbsp;q = (f / s) + z去量化:&nbsp;f = (q - z) * s有关此量化方程的更多信息,请参阅量化规范。注意:&nbsp;Aleksandr Kondratyev的方程f = (q - zero_point) * scale实际上是反量化,因为它采用 q(量化值)并为您提供 f(浮点数)。当然,你可以颠倒等式来得到另一个。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python