Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
f0f50b75
Commit
f0f50b75
authored
May 20, 2019
by
dianlujitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix LogSoftmax for ONNX
Fix wrong indentation as well while at it
parent
447116a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
25 deletions
+36
-25
onnx_importer.cpp
modules/dnn/src/onnx/onnx_importer.cpp
+30
-25
test_onnx_importer.cpp
modules/dnn/test/test_onnx_importer.cpp
+6
-0
No files found.
modules/dnn/src/onnx/onnx_importer.cpp
View file @
f0f50b75
...
...
@@ -786,37 +786,42 @@ void ONNXImporter::populateNet(Net dstNet)
}
replaceLayerParam
(
layerParams
,
"mode"
,
"interpolation"
);
}
else
if
(
layer_type
==
"LogSoftmax"
)
{
layerParams
.
type
=
"Softmax"
;
layerParams
.
set
(
"log_softmax"
,
true
);
}
else
{
for
(
int
j
=
0
;
j
<
node_proto
.
input_size
();
j
++
)
{
if
(
layer_id
.
find
(
node_proto
.
input
(
j
))
==
layer_id
.
end
())
layerParams
.
blobs
.
push_back
(
getBlob
(
node_proto
,
constBlobs
,
j
));
}
}
int
id
=
dstNet
.
addLayer
(
layerParams
.
name
,
layerParams
.
type
,
layerParams
);
layer_id
.
insert
(
std
::
make_pair
(
layerParams
.
name
,
LayerInfo
(
id
,
0
)));
std
::
vector
<
MatShape
>
layerInpShapes
,
layerOutShapes
,
layerInternalShapes
;
for
(
int
j
=
0
;
j
<
node_proto
.
input_size
();
j
++
)
{
layerId
=
layer_id
.
find
(
node_proto
.
input
(
j
));
if
(
layerId
!=
layer_id
.
end
())
{
dstNet
.
connect
(
layerId
->
second
.
layerId
,
layerId
->
second
.
outputId
,
id
,
j
);
// Collect input shapes.
shapeIt
=
outShapes
.
find
(
node_proto
.
input
(
j
));
CV_Assert
(
shapeIt
!=
outShapes
.
end
());
layerInpShapes
.
push_back
(
shapeIt
->
second
);
}
}
// Compute shape of output blob for this layer.
Ptr
<
Layer
>
layer
=
dstNet
.
getLayer
(
id
);
layer
->
getMemoryShapes
(
layerInpShapes
,
0
,
layerOutShapes
,
layerInternalShapes
);
CV_Assert
(
!
layerOutShapes
.
empty
());
outShapes
[
layerParams
.
name
]
=
layerOutShapes
[
0
];
}
}
}
int
id
=
dstNet
.
addLayer
(
layerParams
.
name
,
layerParams
.
type
,
layerParams
);
layer_id
.
insert
(
std
::
make_pair
(
layerParams
.
name
,
LayerInfo
(
id
,
0
)));
std
::
vector
<
MatShape
>
layerInpShapes
,
layerOutShapes
,
layerInternalShapes
;
for
(
int
j
=
0
;
j
<
node_proto
.
input_size
();
j
++
)
{
layerId
=
layer_id
.
find
(
node_proto
.
input
(
j
));
if
(
layerId
!=
layer_id
.
end
())
{
dstNet
.
connect
(
layerId
->
second
.
layerId
,
layerId
->
second
.
outputId
,
id
,
j
);
// Collect input shapes.
shapeIt
=
outShapes
.
find
(
node_proto
.
input
(
j
));
CV_Assert
(
shapeIt
!=
outShapes
.
end
());
layerInpShapes
.
push_back
(
shapeIt
->
second
);
}
}
// Compute shape of output blob for this layer.
Ptr
<
Layer
>
layer
=
dstNet
.
getLayer
(
id
);
layer
->
getMemoryShapes
(
layerInpShapes
,
0
,
layerOutShapes
,
layerInternalShapes
);
CV_Assert
(
!
layerOutShapes
.
empty
());
outShapes
[
layerParams
.
name
]
=
layerOutShapes
[
0
];
}
}
Net
readNetFromONNX
(
const
String
&
onnxFile
)
{
...
...
modules/dnn/test/test_onnx_importer.cpp
View file @
f0f50b75
...
...
@@ -245,6 +245,12 @@ TEST_P(Test_ONNX_layers, Reshape)
testONNXModels
(
"unsqueeze"
);
}
TEST_P
(
Test_ONNX_layers
,
Softmax
)
{
testONNXModels
(
"softmax"
);
testONNXModels
(
"log_softmax"
);
}
INSTANTIATE_TEST_CASE_P
(
/*nothing*/
,
Test_ONNX_layers
,
dnnBackendsAndTargets
());
class
Test_ONNX_nets
:
public
Test_ONNX_layers
{};
...
...
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