Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
73dc666d
Commit
73dc666d
authored
Jun 08, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1212 from dkurt:torch_softmax_layer
parents
6c9d6d50
78ff9d93
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
0 deletions
+35
-0
all_layers.hpp
modules/dnn/include/opencv2/dnn/all_layers.hpp
+2
-0
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+1
-0
softmax_layer.cpp
modules/dnn/src/layers/softmax_layer.cpp
+9
-0
torch_importer.cpp
modules/dnn/src/torch/torch_importer.cpp
+11
-0
test_torch_importer.cpp
modules/dnn/test/test_torch_importer.cpp
+12
-0
No files found.
modules/dnn/include/opencv2/dnn/all_layers.hpp
View file @
73dc666d
...
...
@@ -251,6 +251,8 @@ namespace dnn
class
CV_EXPORTS
SoftmaxLayer
:
public
Layer
{
public
:
bool
logSoftMax
;
static
Ptr
<
SoftmaxLayer
>
create
(
const
LayerParams
&
params
);
};
...
...
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
73dc666d
...
...
@@ -436,6 +436,7 @@ namespace dnn //! This namespace is used for dnn module functionlaity.
* - nn.SpatialMaxPooling, nn.SpatialAveragePooling
* - nn.ReLU, nn.TanH, nn.Sigmoid
* - nn.Reshape
* - nn.SoftMax, nn.LogSoftMax
*
* Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.
*/
...
...
modules/dnn/src/layers/softmax_layer.cpp
View file @
73dc666d
...
...
@@ -57,6 +57,7 @@ public:
SoftMaxLayerImpl
(
const
LayerParams
&
params
)
{
axisRaw
=
params
.
get
<
int
>
(
"axis"
,
1
);
logSoftMax
=
params
.
get
<
int
>
(
"log_softmax"
,
false
);
setParamsFrom
(
params
);
}
...
...
@@ -143,6 +144,14 @@ public:
for
(
size_t
i
=
0
;
i
<
innerSize
;
i
++
)
dstPtr
[
srcOffset
+
cnDim
*
cnStep
+
i
]
/=
bufPtr
[
bufOffset
+
i
];
}
if
(
logSoftMax
)
{
for
(
size_t
cnDim
=
0
;
cnDim
<
channels
;
cnDim
++
)
{
for
(
size_t
i
=
0
;
i
<
innerSize
;
i
++
)
dstPtr
[
srcOffset
+
cnDim
*
cnStep
+
i
]
=
log
(
dstPtr
[
srcOffset
+
cnDim
*
cnStep
+
i
]);
}
}
}
}
...
...
modules/dnn/src/torch/torch_importer.cpp
View file @
73dc666d
...
...
@@ -741,6 +741,17 @@ struct TorchImporter : public ::cv::dnn::Importer
layerParams
.
set
(
"indices_blob_id"
,
tensorParams
[
"indices"
].
first
);
curModule
->
modules
.
push_back
(
newModule
);
}
else
if
(
nnName
==
"SoftMax"
)
{
newModule
->
apiType
=
"SoftMax"
;
curModule
->
modules
.
push_back
(
newModule
);
}
else
if
(
nnName
==
"LogSoftMax"
)
{
newModule
->
apiType
=
"SoftMax"
;
layerParams
.
set
(
"log_softmax"
,
true
);
curModule
->
modules
.
push_back
(
newModule
);
}
else
{
CV_Error
(
Error
::
StsNotImplemented
,
"Unknown nn class
\"
"
+
className
+
"
\"
"
);
...
...
modules/dnn/test/test_torch_importer.cpp
View file @
73dc666d
...
...
@@ -159,6 +159,18 @@ TEST(Torch_Importer, net_cadd_table)
runTorchNet
(
"net_cadd_table"
);
}
TEST
(
Torch_Importer
,
net_softmax
)
{
runTorchNet
(
"net_softmax"
);
runTorchNet
(
"net_softmax_spatial"
);
}
TEST
(
Torch_Importer
,
net_logsoftmax
)
{
runTorchNet
(
"net_logsoftmax"
);
runTorchNet
(
"net_logsoftmax_spatial"
);
}
TEST
(
Torch_Importer
,
ENet_accuracy
)
{
Net
net
;
...
...
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