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
43e66e7f
Commit
43e66e7f
authored
Sep 25, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12644 from dkurt:dnn_out_layers_names
parents
9faacfbc
f8398d80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
20 deletions
+21
-20
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+5
-0
dnn.cpp
modules/dnn/src/dnn.cpp
+12
-0
object_detection.cpp
samples/dnn/object_detection.cpp
+2
-15
object_detection.py
samples/dnn/object_detection.py
+2
-5
No files found.
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
43e66e7f
...
...
@@ -535,6 +535,11 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
/** @brief Returns indexes of layers with unconnected outputs.
*/
CV_WRAP
std
::
vector
<
int
>
getUnconnectedOutLayers
()
const
;
/** @brief Returns names of layers with unconnected outputs.
*/
CV_WRAP
std
::
vector
<
String
>
getUnconnectedOutLayersNames
()
const
;
/** @brief Returns input and output shapes for all layers in loaded model;
* preliminary inferencing isn't necessary.
* @param netInputShapes shapes for all input blobs in net input layer.
...
...
modules/dnn/src/dnn.cpp
View file @
43e66e7f
...
...
@@ -2789,6 +2789,18 @@ std::vector<int> Net::getUnconnectedOutLayers() const
return
layersIds
;
}
std
::
vector
<
String
>
Net
::
getUnconnectedOutLayersNames
()
const
{
std
::
vector
<
int
>
ids
=
getUnconnectedOutLayers
();
const
size_t
n
=
ids
.
size
();
std
::
vector
<
String
>
names
(
n
);
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
names
[
i
]
=
impl
->
layers
[
ids
[
i
]].
name
;
}
return
names
;
}
void
Net
::
getLayersShapes
(
const
ShapesVec
&
netInputShapes
,
std
::
vector
<
int
>&
layersIds
,
std
::
vector
<
ShapesVec
>&
inLayersShapes
,
...
...
samples/dnn/object_detection.cpp
View file @
43e66e7f
...
...
@@ -86,6 +86,7 @@ int main(int argc, char** argv)
Net
net
=
readNet
(
parser
.
get
<
String
>
(
"model"
),
parser
.
get
<
String
>
(
"config"
),
parser
.
get
<
String
>
(
"framework"
));
net
.
setPreferableBackend
(
parser
.
get
<
int
>
(
"backend"
));
net
.
setPreferableTarget
(
parser
.
get
<
int
>
(
"target"
));
std
::
vector
<
String
>
outNames
=
net
.
getUnconnectedOutLayersNames
();
// Create a window
static
const
std
::
string
kWinName
=
"Deep learning object detection in OpenCV"
;
...
...
@@ -125,7 +126,7 @@ int main(int argc, char** argv)
net
.
setInput
(
imInfo
,
"im_info"
);
}
std
::
vector
<
Mat
>
outs
;
net
.
forward
(
outs
,
getOutputsNames
(
net
)
);
net
.
forward
(
outs
,
outNames
);
postprocess
(
frame
,
outs
,
net
);
...
...
@@ -265,17 +266,3 @@ void callback(int pos, void*)
{
confThreshold
=
pos
*
0.01
f
;
}
std
::
vector
<
String
>
getOutputsNames
(
const
Net
&
net
)
{
static
std
::
vector
<
String
>
names
;
if
(
names
.
empty
())
{
std
::
vector
<
int
>
outLayers
=
net
.
getUnconnectedOutLayers
();
std
::
vector
<
String
>
layersNames
=
net
.
getLayerNames
();
names
.
resize
(
outLayers
.
size
());
for
(
size_t
i
=
0
;
i
<
outLayers
.
size
();
++
i
)
names
[
i
]
=
layersNames
[
outLayers
[
i
]
-
1
];
}
return
names
;
}
samples/dnn/object_detection.py
View file @
43e66e7f
...
...
@@ -78,14 +78,11 @@ if args.classes:
net
=
cv
.
dnn
.
readNet
(
args
.
model
,
args
.
config
,
args
.
framework
)
net
.
setPreferableBackend
(
args
.
backend
)
net
.
setPreferableTarget
(
args
.
target
)
outNames
=
net
.
getUnconnectedOutLayersNames
()
confThreshold
=
args
.
thr
nmsThreshold
=
args
.
nms
def
getOutputsNames
(
net
):
layersNames
=
net
.
getLayerNames
()
return
[
layersNames
[
i
[
0
]
-
1
]
for
i
in
net
.
getUnconnectedOutLayers
()]
def
postprocess
(
frame
,
outs
):
frameHeight
=
frame
.
shape
[
0
]
frameWidth
=
frame
.
shape
[
1
]
...
...
@@ -213,7 +210,7 @@ while cv.waitKey(1) < 0:
if
net
.
getLayer
(
0
)
.
outputNameToIndex
(
'im_info'
)
!=
-
1
:
# Faster-RCNN or R-FCN
frame
=
cv
.
resize
(
frame
,
(
inpWidth
,
inpHeight
))
net
.
setInput
(
np
.
array
([[
inpHeight
,
inpWidth
,
1.6
]],
dtype
=
np
.
float32
),
'im_info'
)
outs
=
net
.
forward
(
getOutputsNames
(
net
)
)
outs
=
net
.
forward
(
outNames
)
postprocess
(
frame
,
outs
)
...
...
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