Skip to content

Commit f5ba3f5

Browse files
committed
Merge pull request opencv#18181 from l-bat:onnx_pow
2 parents 8c1af09 + d392b11 commit f5ba3f5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

modules/dnn/src/onnx/onnx_importer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,19 @@ void ONNXImporter::populateNet(Net dstNet)
712712
layerParams.set("bias_term", true);
713713
}
714714
}
715+
else if (layer_type == "Pow")
716+
{
717+
if (layer_id.find(node_proto.input(1)) != layer_id.end())
718+
CV_Error(Error::StsNotImplemented, "Unsupported Pow op with variable power");
719+
720+
Mat blob = getBlob(node_proto, constBlobs, 1);
721+
if (blob.total() != 1)
722+
CV_Error(Error::StsNotImplemented, "Pow op supports only scalar power");
723+
724+
blob.convertTo(blob, CV_32F);
725+
layerParams.type = "Power";
726+
layerParams.set("power", blob.at<float>(0));
727+
}
715728
else if (layer_type == "Max")
716729
{
717730
layerParams.type = "Eltwise";

modules/dnn/test/test_onnx_importer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ TEST_P(Test_ONNX_layers, Cast)
283283
testONNXModels("cast");
284284
}
285285

286+
TEST_P(Test_ONNX_layers, Power)
287+
{
288+
testONNXModels("pow2", npy, 0, 0, false, false);
289+
}
290+
286291
TEST_P(Test_ONNX_layers, Concatenation)
287292
{
288293
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)

0 commit comments

Comments
 (0)