Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
seo young Joung
opencv
Commits
245b2fec
Commit
245b2fec
authored
5 years ago
by
Alexander Alekhin
Browse files
Options
Download
Plain Diff
Merge pull request #16925 from dkurt:dnn_ssd.pytorch
parents
49a75079
d3f9ad11
4.x
3.4
5.x
master
next
4.5.5
4.5.4
4.5.3
4.5.3-openvino
4.5.3-openvino-2021.4.2
4.5.3-openvino-2021.4.1
4.5.2
4.5.2-openvino
4.5.1
4.5.1-openvino
4.5.0
4.5.0-openvino
4.4.0
4.4.0-openvino
3.4.17
3.4.16
3.4.15
3.4.14
3.4.13
3.4.12
3.4.11
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
modules/dnn/src/onnx/onnx_graph_simplifier.cpp
+39
-13
modules/dnn/src/onnx/onnx_graph_simplifier.cpp
modules/dnn/src/onnx/onnx_importer.cpp
+19
-0
modules/dnn/src/onnx/onnx_importer.cpp
modules/dnn/test/test_onnx_importer.cpp
+1
-0
modules/dnn/test/test_onnx_importer.cpp
with
59 additions
and
13 deletions
+59
-13
modules/dnn/src/onnx/onnx_graph_simplifier.cpp
View file @
245b2fec
...
...
@@ -154,16 +154,10 @@ private:
int
axis
;
};
class
NormalizeSubgraph
1
:
public
Subgraph
class
NormalizeSubgraph
Base
:
public
Subgraph
{
public:
NormalizeSubgraph1
()
:
axis
(
1
)
{
input
=
addNodeToMatch
(
""
);
norm
=
addNodeToMatch
(
"ReduceL2"
,
input
);
addNodeToMatch
(
"Div"
,
input
,
norm
);
setFusedNode
(
"Normalize"
,
input
);
}
NormalizeSubgraphBase
(
int
_normNodeOrder
=
0
)
:
axis
(
1
),
normNodeOrder
(
_normNodeOrder
)
{}
virtual
bool
match
(
const
Ptr
<
ImportGraphWrapper
>&
net
,
int
nodeId
,
std
::
vector
<
int
>&
matchedNodesIds
,
...
...
@@ -171,7 +165,7 @@ public:
{
if
(
Subgraph
::
match
(
net
,
nodeId
,
matchedNodesIds
,
targetNodesIds
))
{
Ptr
<
ImportNodeWrapper
>
norm
=
net
->
getNode
(
matchedNodesIds
[
0
]);
Ptr
<
ImportNodeWrapper
>
norm
=
net
->
getNode
(
matchedNodesIds
[
normNodeOrder
]);
opencv_onnx
::
NodeProto
*
node
=
norm
.
dynamicCast
<
ONNXNodeWrapper
>
()
->
node
;
for
(
int
i
=
0
;
i
<
node
->
attribute_size
();
i
++
)
...
...
@@ -204,20 +198,51 @@ public:
}
protected:
int
input
,
norm
;
int
axis
;
int
axis
,
normNodeOrder
;
};
class
NormalizeSubgraph1
:
public
NormalizeSubgraphBase
{
public:
NormalizeSubgraph1
()
{
int
input
=
addNodeToMatch
(
""
);
int
norm
=
addNodeToMatch
(
"ReduceL2"
,
input
);
addNodeToMatch
(
"Div"
,
input
,
norm
);
setFusedNode
(
"Normalize"
,
input
);
}
};
class
NormalizeSubgraph2
:
public
NormalizeSubgraph
1
class
NormalizeSubgraph2
:
public
NormalizeSubgraph
Base
{
public:
NormalizeSubgraph2
()
:
NormalizeSubgraph1
()
NormalizeSubgraph2
()
{
int
input
=
addNodeToMatch
(
""
);
int
norm
=
addNodeToMatch
(
"ReduceL2"
,
input
);
int
clip
=
addNodeToMatch
(
"Clip"
,
norm
);
int
shape
=
addNodeToMatch
(
"Shape"
,
input
);
int
expand
=
addNodeToMatch
(
"Expand"
,
clip
,
shape
);
addNodeToMatch
(
"Div"
,
input
,
expand
);
setFusedNode
(
"Normalize"
,
input
);
}
};
class
NormalizeSubgraph3
:
public
NormalizeSubgraphBase
{
public:
NormalizeSubgraph3
()
:
NormalizeSubgraphBase
(
1
)
{
int
input
=
addNodeToMatch
(
""
);
int
power
=
addNodeToMatch
(
"Constant"
);
int
squared
=
addNodeToMatch
(
"Pow"
,
input
,
power
);
int
sum
=
addNodeToMatch
(
"ReduceSum"
,
squared
);
int
sqrtNode
=
addNodeToMatch
(
"Sqrt"
,
sum
);
int
eps
=
addNodeToMatch
(
"Constant"
);
int
add
=
addNodeToMatch
(
"Add"
,
sqrtNode
,
eps
);
addNodeToMatch
(
"Div"
,
input
,
add
);
setFusedNode
(
"Normalize"
,
input
);
}
};
...
...
@@ -368,6 +393,7 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net)
subgraphs
.
push_back
(
makePtr
<
SoftMaxSubgraph
>
());
subgraphs
.
push_back
(
makePtr
<
NormalizeSubgraph1
>
());
subgraphs
.
push_back
(
makePtr
<
NormalizeSubgraph2
>
());
subgraphs
.
push_back
(
makePtr
<
NormalizeSubgraph3
>
());
simplifySubgraphs
(
Ptr
<
ImportGraphWrapper
>
(
new
ONNXGraphWrapper
(
net
)),
subgraphs
);
}
...
...
This diff is collapsed.
Click to expand it.
modules/dnn/src/onnx/onnx_importer.cpp
View file @
245b2fec
...
...
@@ -1457,6 +1457,25 @@ void ONNXImporter::populateNet(Net dstNet)
layerParams
.
type
=
"Softmax"
;
layerParams
.
set
(
"log_softmax"
,
layer_type
==
"LogSoftmax"
);
}
else
if
(
layer_type
==
"DetectionOutput"
)
{
CV_CheckEQ
(
node_proto
.
input_size
(),
3
,
""
);
if
(
constBlobs
.
find
(
node_proto
.
input
(
2
))
!=
constBlobs
.
end
())
{
Mat
priors
=
getBlob
(
node_proto
,
constBlobs
,
2
);
LayerParams
constParams
;
constParams
.
name
=
layerParams
.
name
+
"/priors"
;
constParams
.
type
=
"Const"
;
constParams
.
blobs
.
push_back
(
priors
);
opencv_onnx
::
NodeProto
priorsProto
;
priorsProto
.
add_output
(
constParams
.
name
);
addLayer
(
dstNet
,
constParams
,
priorsProto
,
layer_id
,
outShapes
);
node_proto
.
set_input
(
2
,
constParams
.
name
);
}
}
else
{
for
(
int
j
=
0
;
j
<
node_proto
.
input_size
();
j
++
)
{
...
...
This diff is collapsed.
Click to expand it.
modules/dnn/test/test_onnx_importer.cpp
View file @
245b2fec
...
...
@@ -440,6 +440,7 @@ TEST_P(Test_ONNX_layers, ReduceL2)
{
testONNXModels
(
"reduceL2"
);
testONNXModels
(
"reduceL2_subgraph"
);
testONNXModels
(
"reduceL2_subgraph_2"
);
}
TEST_P
(
Test_ONNX_layers
,
Split
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help