-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Stop relying on the producer's naming of quantized layers to fetch its parameters #22442
Copy link
Copy link
Closed
Labels
Description
This function shouldn't use the names of the layers:
opencv/modules/dnn/src/onnx/onnx_importer.cpp
Lines 756 to 799 in 2619099
| void ONNXImporter::handleQuantizedNode(LayerParams& layerParams, | |
| const opencv_onnx::NodeProto& node_proto) | |
| { | |
| // Quantized nodes have output names ending with 'quantized' | |
| std::string outName = node_proto.output(0); | |
| int len = outName.length(); | |
| if (len <= 9) | |
| return; | |
| if (outName.substr(len - 9) == "quantized") | |
| { | |
| outName = outName.substr(0, len - 9); | |
| Mat scale, zeropoint; | |
| if (constBlobs.find(outName + "scale") != constBlobs.end() && | |
| constBlobs.find(outName + "zero_point") != constBlobs.end()) | |
| { | |
| scale = getBlob(outName + "scale"); | |
| zeropoint = getBlob(outName + "zero_point"); | |
| } | |
| else | |
| { | |
| std::string inpName = node_proto.input(0); | |
| inpName = inpName.substr(0, inpName.length() - 9); | |
| scale = getBlob(inpName + "scale"); | |
| zeropoint = getBlob(inpName + "zero_point"); | |
| for (int i = 0; i < node_proto.output_size(); i++) | |
| { | |
| std::string out = node_proto.output(i); | |
| out = out.substr(0, out.length() - 9); | |
| addConstant(out + "scale", scale); | |
| addConstant(out + "zero_point", zeropoint); | |
| } | |
| } | |
| if (scale.total() != 1 || zeropoint.total() != 1) | |
| CV_Error(Error::StsNotImplemented, "Per-channel scales/zeropoints are not supported"); | |
| layerParams.set("depth", CV_8S); | |
| layerParams.set("scales", DictValue::arrayReal(scale.ptr<float>(), 1)); | |
| layerParams.set("zeropoints", DictValue::arrayInt(zeropoint.ptr<int8_t>(), 1)); | |
| } | |
| } |
Reactions are currently unavailable