Skip to content

Commit a122a53

Browse files
committed
Merge pull request opencv#19330 from l-bat:lb/onnx_mish_subgraph
2 parents 235e648 + af9597f commit a122a53

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

modules/dnn/src/onnx/onnx_graph_simplifier.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ class ExpandSubgraph : public Subgraph
314314
}
315315
};
316316

317+
class MishSubgraph : public Subgraph
318+
{
319+
public:
320+
MishSubgraph()
321+
{
322+
int input = addNodeToMatch("");
323+
int softplus = addNodeToMatch("Softplus", input);
324+
int tanh = addNodeToMatch("Tanh", softplus);
325+
addNodeToMatch("Mul", input, tanh);
326+
setFusedNode("Mish", input);
327+
}
328+
};
329+
317330
class MulCastSubgraph : public Subgraph
318331
{
319332
public:
@@ -512,6 +525,7 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net)
512525
subgraphs.push_back(makePtr<BatchNormalizationSubgraph1>());
513526
subgraphs.push_back(makePtr<BatchNormalizationSubgraph2>());
514527
subgraphs.push_back(makePtr<ExpandSubgraph>());
528+
subgraphs.push_back(makePtr<MishSubgraph>());
515529

516530
simplifySubgraphs(Ptr<ImportGraphWrapper>(new ONNXGraphWrapper(net)), subgraphs);
517531
}

modules/dnn/test/test_onnx_importer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ TEST_P(Test_ONNX_layers, ResizeOpset11_Torch1_6)
660660
testONNXModels("resize_opset11_torch1.6");
661661
}
662662

663+
TEST_P(Test_ONNX_layers, Mish)
664+
{
665+
testONNXModels("mish");
666+
}
667+
663668
TEST_P(Test_ONNX_layers, Conv1d)
664669
{
665670
testONNXModels("conv1d");

0 commit comments

Comments
 (0)