Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多个不同scale的输入,量化影响了结果 #152

Closed
zhouyang1989 opened this issue Jul 26, 2022 · 8 comments
Closed

多个不同scale的输入,量化影响了结果 #152

zhouyang1989 opened this issue Jul 26, 2022 · 8 comments
Labels

Comments

@zhouyang1989
Copy link

zhouyang1989 commented Jul 26, 2022

任务的模型有两个输入,一个是image,经过backbone后得到image features,另一个是输入其他detection模型检测得到的bbox 坐标,坐标经过了归一化,是0~1之间的float值。坐标经过线性层以及卷积层的上采样,结果与image features做concat。使用MQBench量化后,发现INT8的推理结果,对于head1精度很高,但是head2有明显的精度损失。
网络定义如下:

image

想问下这种结构的网络一般怎么处理?

@Tracin
Copy link
Contributor

Tracin commented Jul 26, 2022

我们应该先解决MQBench模拟结果与SNPE实测结果相差较大的问题
网络中包含哪些算子?

@zhouyang1989
Copy link
Author

1、Backbone用的是Mobilenet v2;
2、head1那一路,都是conv2d + sigmoid;
3、上采样部分用的gemm + conv2d;
4、两路合并用的concat;
5、head2那一路,用的bottleneck结构,主要是conv2d + relu6。

@zhouyang1989
Copy link
Author

此外,我还做了一组实验,如果把bbox那个输入和上采样去掉,直接由image features产生head2。虽然head2的结果会差一点,但是MQBench量化的结果和SNPE执行的结果,是能匹配上的。所以也怀疑是bbox那个输入头构造的方式的问题。坐标输入是4个0~1之间的float值,经过gemm上采样+conv,参数量剧增,这种由窄到宽的结构,不知道量化的时候,放大误差的影响?

@Tracin
Copy link
Contributor

Tracin commented Jul 27, 2022

可否尝试替换relu6

@zhouyang1989
Copy link
Author

尝试替换了从bbox坐标输入头到head2输出头这一路的relu6,都换成relu。结果还是一样的。
此外我发现bbox坐标输入后,我原来先做了一下view,这样在mqbench生成的json文件里,就不会生成对bbox输入的encoding,如果去掉view,就可以生成encoding。

@Tracin
Copy link
Contributor

Tracin commented Jul 29, 2022

两个输入都有encoding时,MQBench与SNPE能对齐吗

@zhouyang1989
Copy link
Author

zhouyang1989 commented Jul 29, 2022

仍旧不能对齐。
现在我有这么几个怀疑点:
1、这两个输入的encoding分别是:
"input_x_bboxs": [
{
"bitwidth": 8,
"min": 0.0,
"max": 0.4640962779521942
}
],
"input_img1": [
{
"bitwidth": 8,
"min": -2.033802032470703,
"max": 2.39884352684021
}
]
bbox那个输入,我只有正值没有负值,那么我的encoding的offset是设置成0还是127?或者这种输入有问题?

2、我使用的SNPE的指令如下:

snpe-onnx-to-dlc --input_network mqbench_qmodel_deploy_model.onnx --output_path tmp.dlc --quantization_overrides
mqbench_qmodel_clip_ranges.json --input_type "input_img1" image --input_type "input_x_bboxs" default --input_layout "input_img1" NCHW --input_layout "input_x_bboxs" NFC (因为img的维度是N1112112, 而我的 bbox输入的维度是 N2*4, 像bbox这种不规则的维度会不会有问题)

snpe-dlc-quantize --input_dlc tmp.dlc --input_list file_list.txt --output_dlc model.dlc --override_params --bias_bitwidth 32

3、我的各个输出头,都是CONV2D + view 的形式,我发现json文件中,对输出头给出的encoding,都是CONV2D那一层输出的encoding。

@github-actions
Copy link

This issue has not received any updates in 120 days. Please reply to this issue if this still unresolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants