RDK X5 转paddleocr rec模型的时候精度问题

首先在转bin的时候会报错:

[E:onnxruntime:, sequential_executor.cc:183 Execute] Non-zero status code returned while running Reshape node. Name:‘p2o.MatMul.0_reshape_input’ Status Message: /home/jenkins/agent/workspace/model_convert_hmct1_ut_cpu_1.1.0/onnxruntime/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:43 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, std::vector&) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{1,120,320}, requested shape:{1,120,1,40}

但是最终也转换成功了,精度损失也不大;

并且original_float_model,optimized_float_model 模型推理的结果也是正确的,但是从calibrated_model 模型开始,结果就不对了.

咨询这种问题怎么排查,怎么解决???

另外,转模型的时候将norm_type: ‘no_preprocess’ ,模型精度损失会比较大,相似度为0.8多点。

debug_result.zip

从敏感度看,没有敏感的节点,都是三个9以上,反而是累计误差会掉到0.8左右。-

如果是0.999以上还是结果不佳, 那大概率是前处理没有对齐,还有校准数据没有对其,全featuremap下,或者浮点onnx推理下,直接在送进onnx的前一刻用np.tofile保存下来作为校准数据。-

另外就是确认是否是全int16,如果全int16还是不行,那就只能指定算子为CPU算子,去查找哪些算子量化敏感

你好,有可能是前处理没有对齐,您可以将original_float_model,optimized_float_model 时刻的numpy数组数据dump下来进行校准。

模型转换工具链会基于您提供的校准样本对模型进行校准量化并保障模型高效的部署在地平线计算平台上。 而在模型转换的过程中,难免会因为浮点到定点的量化过程而引入精度损失,通常情况下造成精度损失的主要原因可能有以下几点:

1.模型中的一部分节点对量化比较敏感会引入较大误差,即敏感节点量化问题。

2.模型中各个节点的误差累积导致模型整体出现较大的校准误差,主要包含:权重量化导致的误差累积、激活量化导致的误差累积以及全量量化导致的误差累积。

针对该情况,地平线提供了精度debug工具用以协助您自主定位模型量化过程中产生的精度问题。 该工具能够协助您对校准模型进行节点粒度的量化误差分析,最终帮助您快速定位出现精度异常的节点。

我用 debug_mode:“dump_calibration_data” 保存下来的npy进行load推理, calibrated_model模型的结果也不对

我把采用精度debug工具测试的结果放上去了,这个结果有问题吗?

[E:onnxruntime:, sequential_executor.cc:183 Execute] Non-zero status code returned while running Reshape node. Name:‘p2o.MatMul.0_reshape_input’ Status Message: /home/jenkins/agent/workspace/model_convert_hmct1_ut_cpu_1.1.0/onnxruntime/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:43 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, std::vector&) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{1,120,320}, requested shape:{1,120,1,40} 转bin模型的时候,这个错误有影响吗

ONNXRuntime会尝试多batch前向传播来提高量化校准速度,带transformer的模型一般都会报这个Warming,注意ONNXRuntime是报错,但是对工具链来说是Warning,不会影响后续