Skip to content

esp32s3 上部署量化模型,使用 m_model->test() 测试不通过 (AIS-2159) #265

@hushi55

Description

@hushi55

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

  1. 使用 esp-ppq 量化训练的模型使用 export_test_values=True 参数导出 espdl 文件部署,m_model->test() 应该要通过
  2. 模型量化后于 PC 端的识别效果相差太大. 性别识别完全不可用(但是我在 PC 端测试,准确率 95% +)

Actual behavior (suspected bug)

  1. m_model->test() 测试不通过

Error logs or terminal output

Steps to reproduce the behavior

  1. 我自己训练一个通过人脸识别 age、gender 特性的模型
  2. 我通过 esp-ppq 量化一个版本使用的量化参数如下
    quant_setting = QuantizationSettingFactory.espdl_setting()

quant_setting.dispatcher = 'conservative'

禁用可能导致问题的优化选项

quant_setting.fusion = False # 禁用算子融合
quant_setting.equalization = False # 禁用均衡化
quant_setting.layerwise_equalization = False # 禁用层间均衡

# 调整量化设置

quant_setting.lsq_optimization = False # 关闭LSQ优化
quant_setting.bias_correct = False # 关闭偏置校正

激进的量化校准和后处理

quant_setting.equalization = True # 激活均衡

quant_setting.layerwise_equalization = True # 层级均衡化

quant_setting.bias_correct = True # 偏置校正

quant_setting.channel_wise = True # 按通道量化
quant_setting.statistical_err_minimize = True # 统计误差最小化
quant_setting.tensorrt_scaling = True # TensorRT缩放策略
quant_setting.sensitivity_analysis = True # 敏感度分析

quant_setting.calib_algorithm = 'kl_divergence'

3.我的 onnx 文件和量化的 output 如下

199.zip

Project release version

latest

System architecture

ARM 64-bit (Apple M1/M2, Raspberry Pi 4/5)

Operating system

MacOS

Operating system version

macbook M4 15.6.1

Shell

Bash

Additional context

由于 m_model->test() 测试不通过,不知道现在模型效果不好的问题边界在哪里

  1. 到底是模型的量化后有问题
    2.还是我对 image 图片处理的输入有问题,由于 esp32s3 对 sub, mul 算子支持的不好,所以我将图片的数据的归一化放到了模型外,对图片的归一化处理算法如下

读取已经裁剪好的人脸图像

img = cv2.imread(self.image_paths[idx])
if img is not None:
# 调整大小(虽然已经是112x112,但为了保险起见)
img = cv2.resize(img, (112, 112))

# 后续处理保持不变
img = img[:, :, ::-1]  # BGR to RGB
img = img.transpose((2, 0, 1))  # HWC to CHW
img = img.astype(np.float32)

## esp-ppq 量化如果存在这个归一化,量化不了
img = (img - 127.5) * 0.0078125

我希望

  1. 先解决 m_model->test() 测试问题,确保和 量化 时加入的测试数据输入输出一致

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions