tf2 的每张量训练后量化

问题描述 投票:0回答:1

使用 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 将是一场噩梦。

  1. 我可以以“每个张量”的方式量化 tf2 训练模型吗?
  2. 是否可以将 tflite“每轴”转换为“每张量”?看起来我只需要从
    scales
    zero_points
    取意思。
  3. 是否可以在“tf1 模式”下训练 tf2 模型而无需大的改变?

谢谢!

tensorflow2.0 tensorflow-lite
1个回答
0
投票

设置转换器._experimental_disable_per_channel = True

© www.soinside.com 2019 - 2024. All rights reserved.