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
86c11144
Commit
86c11144
authored
Jun 21, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11798 from dkurt:dnn_layers_names_with_dot
parents
eed43a23
40b85c1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
37 deletions
+47
-37
dnn.cpp
modules/dnn/src/dnn.cpp
+4
-36
test_layers.cpp
modules/dnn/test/test_layers.cpp
+42
-0
test_torch_importer.cpp
modules/dnn/test/test_torch_importer.cpp
+1
-1
No files found.
modules/dnn/src/dnn.cpp
View file @
86c11144
...
...
@@ -988,52 +988,26 @@ struct Net::Impl
ld
.
inputBlobsId
[
inNum
]
=
from
;
}
static
void
splitPin
(
const
String
&
pinAlias
,
String
&
layerName
,
String
&
outName
)
{
size_t
delimPos
=
pinAlias
.
find
(
'.'
);
layerName
=
pinAlias
.
substr
(
0
,
delimPos
);
outName
=
(
delimPos
==
String
::
npos
)
?
String
()
:
pinAlias
.
substr
(
delimPos
+
1
);
}
int
resolvePinOutputName
(
LayerData
&
ld
,
const
String
&
outName
)
{
if
(
outName
.
empty
())
return
0
;
if
(
std
::
isdigit
(
outName
[
0
]))
{
char
*
lastChar
;
long
inum
=
std
::
strtol
(
outName
.
c_str
(),
&
lastChar
,
10
);
if
(
*
lastChar
==
0
)
{
CV_Assert
(
inum
==
(
int
)
inum
);
return
(
int
)
inum
;
}
}
return
ld
.
getLayerInstance
()
->
outputNameToIndex
(
outName
);
}
LayerPin
getPinByAlias
(
const
String
&
pinAlias
)
LayerPin
getPinByAlias
(
const
String
&
layerName
)
{
LayerPin
pin
;
String
layerName
,
outName
;
splitPin
(
pinAlias
,
layerName
,
outName
);
pin
.
lid
=
(
layerName
.
empty
())
?
0
:
getLayerId
(
layerName
);
if
(
pin
.
lid
>=
0
)
pin
.
oid
=
resolvePinOutputName
(
getLayerData
(
pin
.
lid
),
out
Name
);
pin
.
oid
=
resolvePinOutputName
(
getLayerData
(
pin
.
lid
),
layer
Name
);
return
pin
;
}
std
::
vector
<
LayerPin
>
getLayerOutPins
(
const
String
&
pinAlias
)
std
::
vector
<
LayerPin
>
getLayerOutPins
(
const
String
&
layerName
)
{
String
layerName
,
outName
;
splitPin
(
pinAlias
,
layerName
,
outName
);
int
lid
=
(
layerName
.
empty
())
?
0
:
getLayerId
(
layerName
);
std
::
vector
<
LayerPin
>
pins
;
...
...
@@ -2044,12 +2018,6 @@ int Net::addLayer(const String &name, const String &type, LayerParams ¶ms)
{
CV_TRACE_FUNCTION
();
if
(
name
.
find
(
'.'
)
!=
String
::
npos
)
{
CV_Error
(
Error
::
StsBadArg
,
"Added layer name
\"
"
+
name
+
"
\"
must not contain dot symbol"
);
return
-
1
;
}
if
(
impl
->
getLayerId
(
name
)
>=
0
)
{
CV_Error
(
Error
::
StsBadArg
,
"Layer
\"
"
+
name
+
"
\"
already into net"
);
...
...
@@ -2689,7 +2657,7 @@ int Layer::inputNameToIndex(String)
int
Layer
::
outputNameToIndex
(
const
String
&
)
{
return
-
1
;
return
0
;
}
bool
Layer
::
supportBackend
(
int
backendId
)
...
...
modules/dnn/test/test_layers.cpp
View file @
86c11144
...
...
@@ -1144,4 +1144,46 @@ TEST(Layer_Test_Interp, Accuracy)
LayerFactory
::
unregisterLayer
(
"Interp"
);
}
TEST
(
Layer_Test_PoolingIndices
,
Accuracy
)
{
Net
net
;
LayerParams
lp
;
lp
.
set
(
"pool"
,
"max"
);
lp
.
set
(
"kernel_w"
,
2
);
lp
.
set
(
"kernel_h"
,
2
);
lp
.
set
(
"stride_w"
,
2
);
lp
.
set
(
"stride_h"
,
2
);
lp
.
set
(
"pad_w"
,
0
);
lp
.
set
(
"pad_h"
,
0
);
lp
.
name
=
"testLayer.name"
;
// This test also checks that OpenCV lets use names with dots.
lp
.
type
=
"Pooling"
;
net
.
addLayerToPrev
(
lp
.
name
,
lp
.
type
,
lp
);
Mat
inp
(
10
,
10
,
CV_8U
);
randu
(
inp
,
0
,
255
);
Mat
maxValues
(
5
,
5
,
CV_32F
,
Scalar
(
-
1
)),
indices
(
5
,
5
,
CV_32F
,
Scalar
(
-
1
));
for
(
int
y
=
0
;
y
<
10
;
++
y
)
{
int
dstY
=
y
/
2
;
for
(
int
x
=
0
;
x
<
10
;
++
x
)
{
int
dstX
=
x
/
2
;
uint8_t
val
=
inp
.
at
<
uint8_t
>
(
y
,
x
);
if
((
float
)
inp
.
at
<
uint8_t
>
(
y
,
x
)
>
maxValues
.
at
<
float
>
(
dstY
,
dstX
))
{
maxValues
.
at
<
float
>
(
dstY
,
dstX
)
=
val
;
indices
.
at
<
float
>
(
dstY
,
dstX
)
=
y
*
10
+
x
;
}
}
}
net
.
setInput
(
blobFromImage
(
inp
));
std
::
vector
<
Mat
>
outputs
;
net
.
forward
(
outputs
,
lp
.
name
);
normAssert
(
maxValues
,
outputs
[
0
].
reshape
(
1
,
5
));
normAssert
(
indices
,
outputs
[
1
].
reshape
(
1
,
5
));
}
}}
// namespace
modules/dnn/test/test_torch_importer.cpp
View file @
86c11144
...
...
@@ -87,7 +87,7 @@ static void runTorchNet(String prefix, int targetId = DNN_TARGET_CPU, String out
if
(
outLayerName
.
empty
())
outLayerName
=
net
.
getLayerNames
().
back
();
net
.
setInput
(
inp
,
"0"
);
net
.
setInput
(
inp
);
std
::
vector
<
Mat
>
outBlobs
;
net
.
forward
(
outBlobs
,
outLayerName
);
normAssert
(
outRef
,
outBlobs
[
0
]);
...
...
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