DNN: let Quant and Dequant of ONNX_importer support the Constant input.#22666
DNN: let Quant and Dequant of ONNX_importer support the Constant input.#22666alalek merged 2 commits intoopencv:4.xfrom
Conversation
|
|
||
| template <typename T> | ||
| static T getScaleFromMat(Mat m) | ||
| static T getScalarFromMat(Mat m) |
There was a problem hiding this comment.
The old name has an error. Scale => Scalar.
473c9d0 to
c966332
Compare
rogday
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
| if(zpMat.total() > 1) scalarParams = false; | ||
| } | ||
|
|
||
| if (constBlobs.find(node_proto.input(0)) == constBlobs.end()) // Variable input. |
There was a problem hiding this comment.
if (scalar)
{
layerParams.set(scales, zeropoint, depth)
if (const) { runLayer() }
else { addLayer() }
return
}
assert(const)
axis = ...;
calculate()so that we don't repeat getting scalar zeropoint and scales 3 times.
306b6e7 to
b55ac6d
Compare
| float scale; | ||
| int zeropoint; | ||
| bool is1D; | ||
| std::vector<float> scales; | ||
| std::vector<int> zeropoints; |
There was a problem hiding this comment.
Replace scale with scales, so that we can support the scales of 1-D tensor. And this change affects the ABI compatibility.
There was a problem hiding this comment.
more details can be found in the un-passed ci.
|
For me, this PR is done. |
Where do you get the axis for per axis quantization? |
Hi, @rogday. My mistake. For now, I just implement the default axis. I will re-think this implementation. |
b55ac6d to
cf48b28
Compare
cf48b28 to
1a66ed8
Compare
|
The |
DNN: let Quant and Dequant of ONNX_importer support the Constant input. * let Quant and Dequant support the Constant input. * fix negative value of axis.
Merge with extra: opencv_extra/#1014
For zeropoint and scale can be 1-D tensor, only exists in
Quant,Deauntand weight ofQLinearConv. We have supported 1-D tensor case inQLinearConv. ForQuantandDeaunt, we can support the constant input case, which is very common situation in per-channel QDQ quantized format. Model examples can be found at PR of extra.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.