mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
fix const/x in Div
This commit is contained in:
parent
a079acc0d9
commit
0a178a687a
@ -1472,7 +1472,16 @@ void ONNXImporter::parseMul(LayerParams& layerParams, const opencv_onnx::NodePro
|
|||||||
blob = blob.reshape(1, 1);
|
blob = blob.reshape(1, 1);
|
||||||
if (blob.total() == 1) {
|
if (blob.total() == 1) {
|
||||||
float blob_value = blob.ptr<float>()[0];
|
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.set("scale", coeff);
|
||||||
layerParams.type = "Power";
|
layerParams.type = "Power";
|
||||||
}
|
}
|
||||||
|
@ -1056,6 +1056,11 @@ TEST_P(Test_ONNX_layers, SubFromConst)
|
|||||||
testONNXModels("sub_from_const_broadcast");
|
testONNXModels("sub_from_const_broadcast");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_P(Test_ONNX_layers, DivConst)
|
||||||
|
{
|
||||||
|
testONNXModels("div_const");
|
||||||
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
|
||||||
|
|
||||||
class Test_ONNX_nets : public Test_ONNX_layers
|
class Test_ONNX_nets : public Test_ONNX_layers
|
||||||
|
Loading…
Reference in New Issue
Block a user