Skip to content

Commit

Permalink
fix the infinite loop in tf importer of 3.4 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
zihaomu committed Nov 15, 2022
1 parent 2991717 commit 5bf64e7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,19 @@ void RemoveIdentityOps(tensorflow::GraphDef& net)
IdentityOpsMap::iterator it = identity_ops.find(input_op_name);

if (it != identity_ops.end()) {
std::set<String> loopCheckSet;
// In case of Identity after Identity
while (true)
{
IdentityOpsMap::iterator nextIt = identity_ops.find(it->second);
if (nextIt != identity_ops.end())
{
// Loop check
if (loopCheckSet.find(it->second) != loopCheckSet.end())
CV_Error(Error::StsError, "Found a loop in your input Tensorflow model, which is illegal!");
loopCheckSet.insert(it->second);
it = nextIt;
}
else
break;
}
Expand Down

0 comments on commit 5bf64e7

Please sign in to comment.