Merge pull request #21297 from rogday:div_fix

pull/21313/head
Alexander Alekhin 3 years ago
commit 947d610309
  1. 11
      modules/dnn/src/onnx/onnx_importer.cpp
  2. 5
      modules/dnn/test/test_onnx_importer.cpp

@ -1472,7 +1472,16 @@ void ONNXImporter::parseMul(LayerParams& layerParams, const opencv_onnx::NodePro
blob = blob.reshape(1, 1);
if (blob.total() == 1) {
float blob_value = blob.ptr<float>()[0];
float coeff = isDiv ? 1.0 / blob_value : blob_value;
float coeff = blob_value;
if (isDiv)
{
coeff = 1.f / blob_value;
if (constId == 0)
{
// Power layer calculates (x*scale + shift)^power, so const/x -> (x * (1/const) + 0)^(-1)
layerParams.set("power", -1.f);
}
}
layerParams.set("scale", coeff);
layerParams.type = "Power";
}

@ -1056,6 +1056,11 @@ TEST_P(Test_ONNX_layers, SubFromConst)
testONNXModels("sub_from_const_broadcast");
}
TEST_P(Test_ONNX_layers, DivConst)
{
testONNXModels("div_const");
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
class Test_ONNX_nets : public Test_ONNX_layers

Loading…
Cancel
Save