diff --git a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp index 0f9670e8a4..a7845b2b5a 100644 --- a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp +++ b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp @@ -950,6 +950,7 @@ void sortByExecutionOrder(tensorflow::GraphDef& net) for (int i = 0; i < net.node_size(); ++i) { const tensorflow::NodeDef& node = net.node(i); + int numInputsInGraph = 0; for (int j = 0; j < node.input_size(); ++j) { std::string inpName = node.input(j); @@ -957,22 +958,25 @@ void sortByExecutionOrder(tensorflow::GraphDef& net) inpName = inpName.substr(inpName.find('^') + 1); nodesMapIt = nodesMap.find(inpName); - CV_Assert(nodesMapIt != nodesMap.end()); - edges[nodesMapIt->second].push_back(i); + if (nodesMapIt != nodesMap.end()) + { + edges[nodesMapIt->second].push_back(i); + numInputsInGraph += 1; + } } - if (node.input_size() == 0) + if (numInputsInGraph == 0) nodesToAdd.push_back(i); else { if (node.op() == "Merge" || node.op() == "RefMerge") { int numControlEdges = 0; - for (int j = 0; j < node.input_size(); ++j) + for (int j = 0; j < numInputsInGraph; ++j) numControlEdges += node.input(j)[0] == '^'; numRefsToAdd[i] = numControlEdges + 1; } else - numRefsToAdd[i] = node.input_size(); + numRefsToAdd[i] = numInputsInGraph; } } diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index 192b94e3bb..2775934faf 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -715,6 +715,10 @@ void TFImporter::populateNet(Net dstNet) simplifySubgraphs(netBin); sortByExecutionOrder(netBin); } + else + { + sortByExecutionOrder(netTxt); + } std::set layers_to_ignore;