From 7a2b3ed471403a8a0e975363eac6427c59464aa3 Mon Sep 17 00:00:00 2001 From: Anastasia Murzova Date: Mon, 22 Mar 2021 22:37:49 +0300 Subject: [PATCH] Corrected DNN elementwise multiplication --- modules/dnn/src/tensorflow/tf_importer.cpp | 6 +++++- modules/dnn/test/test_tf_importer.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index 53d62fc9f7..bdab0663a7 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -12,6 +12,7 @@ Implementation of Tensorflow models parser #include "../precomp.hpp" #include +#include #undef CV_LOG_STRIP_LEVEL #define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG + 1 #include @@ -1825,6 +1826,7 @@ void TFImporter::parseNode(const tensorflow::NodeDef& layer_) { // Check if all the inputs have the same shape. bool equalInpShapes = true; + bool isShapeOnes = false; MatShape outShape0; for (int ii = 0; ii < num_inputs && !netInputShapes.empty(); ii++) { @@ -1845,12 +1847,14 @@ void TFImporter::parseNode(const tensorflow::NodeDef& layer_) else if (outShape != outShape0) { equalInpShapes = false; + isShapeOnes = isAllOnes(outShape, 2, outShape.size()) || + isAllOnes(outShape0, 2, outShape0.size()); break; } } int id; - if (equalInpShapes || netInputShapes.empty()) + if (equalInpShapes || netInputShapes.empty() || (!equalInpShapes && isShapeOnes)) { layerParams.set("operation", type == "RealDiv" ? "div" : "prod"); id = dstNet.addLayer(name, "Eltwise", layerParams); diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index 62a559a672..5e45a5c0f0 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -210,6 +210,12 @@ TEST_P(Test_TensorFlow_layers, eltwise_add_vec) runTensorFlowNet("eltwise_add_vec"); } +TEST_P(Test_TensorFlow_layers, eltwise_mul_vec) +{ + runTensorFlowNet("eltwise_mul_vec"); +} + + TEST_P(Test_TensorFlow_layers, channel_broadcast) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)