使用 tf2 训练的模型将在硬件上运行,如果模型量化为“per-tensor”,该硬件将具有性能优势。但是
TFLiteConverter
没有任何选项可以使其成为 tf2 的“每个张量”。我猜 tf2 只能进行“每轴”量化。
我确定模型是“按轴”转换的,因为
interpreter.get_tensor_details()
显示了 conv2 张量的以下内容。
{'scales': array([0.00020375, 0.00016656, 0.00019717, 0.00022204, 0.00015516,
0.00018166, 0.00017471, 0.00016947, 0.00020444, 0.00017661,
...], dtype=float32),
'zero_points': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...], dtype=int32),
'quantized_dimension': 0}
如果“每张量”
scales
和zero_points
本来是标量。模型和训练代码是为 tf2 构建的,将所有东西转换为 tf1 将是一场噩梦。
scales
和 zero_points
取意思。谢谢!
设置转换器._experimental_disable_per_channel = True