From 0245c0cd10387f2de7c7bd076585a285d977e53c Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Wed, 2 Aug 2023 14:39:11 +0300 Subject: [PATCH] Merge pull request #24072 from dkurt:openvino_cpu_tests Remove legacy nGraph logic #24072 ### Pull Request Readiness Checklist TODO: - [x] Test with OpenVINO 2021.4 (tested locally) See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- modules/dnn/src/ie_ngraph.cpp | 101 +----------------- modules/dnn/src/ie_ngraph.hpp | 8 -- modules/dnn/src/net_openvino.cpp | 1 - modules/dnn/test/test_darknet_importer.cpp | 2 +- modules/dnn/test/test_ie_models.cpp | 4 +- ...conformance_layer_filter__openvino.inl.hpp | 4 +- 6 files changed, 5 insertions(+), 115 deletions(-) diff --git a/modules/dnn/src/ie_ngraph.cpp b/modules/dnn/src/ie_ngraph.cpp index a49976de74..140d4b0d2f 100644 --- a/modules/dnn/src/ie_ngraph.cpp +++ b/modules/dnn/src/ie_ngraph.cpp @@ -446,66 +446,6 @@ void InfEngineNgraphNet::addOutput(const Ptr& node) requestedOutputs.insert({name, node.get()}); } -void InfEngineNgraphNet::setNodePtr(std::shared_ptr* ptr) { - all_nodes.emplace((*ptr)->get_friendly_name(), ptr); -} - - void InfEngineNgraphNet::release() - { - // FIXIT release should not be conditional, release ALL - for (auto& node : components.back()) { -#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) - if (!(ngraph::op::is_parameter(node) || ngraph::op::is_output(node) || ngraph::op::is_constant(node)) ) { -#else - if (!(node->is_parameter() || node->is_output() || node->is_constant()) ) { -#endif - auto it = all_nodes.find(node->get_friendly_name()); - if (it != all_nodes.end()) { - it->second->reset(); - all_nodes.erase(it); - } - } - } - } - -void InfEngineNgraphNet::dfs(std::shared_ptr& node, - std::vector>& comp, - std::unordered_map& used) { - used[node->get_friendly_name()] = true; - comp.push_back(node); - auto inputs = node->get_users(); - for (size_t i = 0; i < node->get_input_size(); ++i) { - inputs.push_back(node->input_value(i).get_node()->shared_from_this()); - } - - for (auto& to : inputs) { - if (!used[to->get_friendly_name()]) { - dfs(to, comp, used); - } - } -} - -int InfEngineNgraphNet::getNumComponents() -{ - if (!components.empty()) { - return components.size(); - } - std::unordered_map used; - auto inputs = ngraph_function->get_ordered_ops(); - for (auto& node : inputs) { - used.emplace(node->get_friendly_name(), false); - } - - for (auto& node : inputs) { - if (!used[node->get_friendly_name()]) { - std::vector> current_comp; - dfs(node, current_comp, used); - components.push_back(current_comp); - } - } - return components.size(); -} - void InfEngineNgraphNet::createNet(Target targetId) { if (!hasNetOwner) { @@ -524,46 +464,7 @@ void InfEngineNgraphNet::createNet(Target targetId) { } CV_Assert_N(!inputs_vec.empty(), !outs.empty()); ngraph_function = std::make_shared(outs, inputs_vec); - - int num_comp = getNumComponents(); - CV_LOG_DEBUG(NULL, "DNN/IE: number of subgraphs: " << num_comp); - if (num_comp > 1) { - for (int i = num_comp - 1; i >= 0; --i) { - ngraph::ResultVector outputs; - ngraph::ParameterVector inps; - for (auto& node : components.back()) { -#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) - if (ngraph::op::is_parameter(node)) { -#else - if (node->is_parameter()) { -#endif - CV_LOG_DEBUG(NULL, "DNN/IE: subgraph[" << i << "]: +input[" << inps.size() << "] = '" << node->get_friendly_name() << "'"); - auto parameter = std::dynamic_pointer_cast(node); - inps.push_back(parameter); - } -#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) - else if (ngraph::op::is_output(node)) { -#else - else if (node->is_output()) { -#endif - CV_LOG_DEBUG(NULL, "DNN/IE: subgraph[" << i << "]: +output[" << outputs.size() << "] = '" << node->get_friendly_name() << "'"); - auto result = std::dynamic_pointer_cast(node); - outputs.push_back(result); - } - } - CV_LOG_DEBUG(NULL, "DNN/IE: subgraph[" << i << ": nodes=" << components.back().size() << " inputs=" << inps.size() << " outputs=" << outputs.size()); - isInit = false; - CV_Assert_N(!inps.empty(), !outputs.empty()); - ngraph_function = std::make_shared(outputs, inps); - release(); - components.pop_back(); - init(targetId); - } - } else { - release(); - components.clear(); - init(targetId); - } + init(targetId); } } diff --git a/modules/dnn/src/ie_ngraph.hpp b/modules/dnn/src/ie_ngraph.hpp index 09afc7f117..7bb0ac09df 100644 --- a/modules/dnn/src/ie_ngraph.hpp +++ b/modules/dnn/src/ie_ngraph.hpp @@ -50,22 +50,14 @@ public: void addBlobs(const std::vector >& ptrs); void createNet(Target targetId); - void setNodePtr(std::shared_ptr* ptr); void reset(); //private: detail::NetImplBase& netImpl_; - void release(); - int getNumComponents(); - void dfs(std::shared_ptr& node, std::vector>& comp, - std::unordered_map& used); - ngraph::ParameterVector inputs_vec; std::shared_ptr ngraph_function; - std::vector>> components; - std::unordered_map* > all_nodes; InferenceEngine::ExecutableNetwork netExec; #if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2022_1) diff --git a/modules/dnn/src/net_openvino.cpp b/modules/dnn/src/net_openvino.cpp index 5704cb9b64..e147faa9f3 100644 --- a/modules/dnn/src/net_openvino.cpp +++ b/modules/dnn/src/net_openvino.cpp @@ -549,7 +549,6 @@ void NetImplOpenVINO::initBackend(const std::vector& blobsToKeep_) break; } } - ieNode->net->setNodePtr(&ieNode->node); net->addBlobs(ld.inputBlobsWrappers); net->addBlobs(ld.outputBlobsWrappers); diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index 2d61426769..fc4f02e1ad 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -1046,7 +1046,7 @@ TEST_P(Test_Darknet_layers, region) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); #endif -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2022010000) // accuracy on CPU, OpenCL // Expected: (normL1) <= (l1), actual: 0.000358148 vs 1e-05 // |ref| = 1.207319974899292 diff --git a/modules/dnn/test/test_ie_models.cpp b/modules/dnn/test/test_ie_models.cpp index 135caa9064..c6667c7ad2 100644 --- a/modules/dnn/test/test_ie_models.cpp +++ b/modules/dnn/test/test_ie_models.cpp @@ -465,8 +465,8 @@ TEST_P(DNNTestHighLevelAPI, predict) const std::string modelPath = getOpenVINOModel(modelName, isFP16); ASSERT_FALSE(modelPath.empty()) << modelName; - std::string xmlPath = findDataFile(modelPath + ".xml"); - std::string binPath = findDataFile(modelPath + ".bin"); + std::string xmlPath = findDataFile(modelPath + ".xml", false); + std::string binPath = findDataFile(modelPath + ".bin", false); Model model(xmlPath, binPath); Mat frame = imread(findDataFile("dnn/googlenet_1.png")); diff --git a/modules/dnn/test/test_onnx_conformance_layer_filter__openvino.inl.hpp b/modules/dnn/test/test_onnx_conformance_layer_filter__openvino.inl.hpp index e6a35dfab9..339746f5f2 100644 --- a/modules/dnn/test/test_onnx_conformance_layer_filter__openvino.inl.hpp +++ b/modules/dnn/test/test_onnx_conformance_layer_filter__openvino.inl.hpp @@ -579,9 +579,7 @@ CASE(test_dropout_default_mask_ratio) CASE(test_dropout_default_old) // no filter CASE(test_dropout_default_ratio) -#if SKIP_SET_1 - SKIP; -#endif + // no filter CASE(test_dropout_random_old) // no filter CASE(test_dynamicquantizelinear)