From d392b11dfb3a16f919af75ed419a64905eb7de55 Mon Sep 17 00:00:00 2001
From: Liubov Batanina <piccione-mail@yandex.ru>
Date: Mon, 24 Aug 2020 10:46:53 +0300
Subject: [PATCH] Supported ONNX Pow op

---
 modules/dnn/src/onnx/onnx_importer.cpp  | 13 +++++++++++++
 modules/dnn/test/test_onnx_importer.cpp |  5 +++++
 2 files changed, 18 insertions(+)

diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp
index 7d37b065ab..ccef2f6936 100644
--- a/modules/dnn/src/onnx/onnx_importer.cpp
+++ b/modules/dnn/src/onnx/onnx_importer.cpp
@@ -712,6 +712,19 @@ void ONNXImporter::populateNet(Net dstNet)
                 layerParams.set("bias_term", true);
             }
         }
+        else if (layer_type == "Pow")
+        {
+            if (layer_id.find(node_proto.input(1)) != layer_id.end())
+                CV_Error(Error::StsNotImplemented, "Unsupported Pow op with variable power");
+
+            Mat blob = getBlob(node_proto, constBlobs, 1);
+            if (blob.total() != 1)
+                CV_Error(Error::StsNotImplemented, "Pow op supports only scalar power");
+
+            blob.convertTo(blob, CV_32F);
+            layerParams.type = "Power";
+            layerParams.set("power", blob.at<float>(0));
+        }
         else if (layer_type == "Max")
         {
             layerParams.type = "Eltwise";
diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp
index 25efcbb3ca..c68215ee30 100644
--- a/modules/dnn/test/test_onnx_importer.cpp
+++ b/modules/dnn/test/test_onnx_importer.cpp
@@ -283,6 +283,11 @@ TEST_P(Test_ONNX_layers, Cast)
     testONNXModels("cast");
 }
 
+TEST_P(Test_ONNX_layers, Power)
+{
+    testONNXModels("pow2", npy, 0, 0, false, false);
+}
+
 TEST_P(Test_ONNX_layers, Concatenation)
 {
     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)