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
f46eff4e
Commit
f46eff4e
authored
Jan 04, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10492 from pengli:dnn
parents
7abaae39
1073175c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
0 deletions
+101
-0
proposal_layer.cpp
modules/dnn/src/layers/proposal_layer.cpp
+95
-0
resnet_ssd_face.cpp
samples/dnn/resnet_ssd_face.cpp
+6
-0
No files found.
modules/dnn/src/layers/proposal_layer.cpp
View file @
f46eff4e
...
...
@@ -148,11 +148,89 @@ public:
deltasPermute
->
finalize
(
layerInputs
,
layerOutputs
);
}
#ifdef HAVE_OPENCL
bool
forward_ocl
(
InputArrayOfArrays
inputs_
,
OutputArrayOfArrays
outputs_
,
OutputArrayOfArrays
internals_
)
{
std
::
vector
<
UMat
>
inputs
;
std
::
vector
<
UMat
>
outputs
;
std
::
vector
<
UMat
>
internals
;
inputs_
.
getUMatVector
(
inputs
);
outputs_
.
getUMatVector
(
outputs
);
internals_
.
getUMatVector
(
internals
);
CV_Assert
(
inputs
.
size
()
==
3
);
CV_Assert
(
internals
.
size
()
==
3
);
const
UMat
&
scores
=
inputs
[
0
];
const
UMat
&
bboxDeltas
=
inputs
[
1
];
const
UMat
&
imInfo
=
inputs
[
2
];
UMat
&
priorBoxes
=
internals
[
0
];
UMat
&
permuttedScores
=
internals
[
1
];
UMat
&
permuttedDeltas
=
internals
[
2
];
CV_Assert
(
imInfo
.
total
()
>=
2
);
// We've chosen the smallest data type because we need just a shape from it.
Mat
szMat
;
imInfo
.
copyTo
(
szMat
);
int
rows
=
(
int
)
szMat
.
at
<
float
>
(
0
);
int
cols
=
(
int
)
szMat
.
at
<
float
>
(
1
);
umat_fakeImageBlob
.
create
(
shape
(
1
,
1
,
rows
,
cols
),
CV_8UC1
);
umat_fakeImageBlob
.
setTo
(
0
);
// Generate prior boxes.
std
::
vector
<
UMat
>
layerInputs
(
2
),
layerOutputs
(
1
,
priorBoxes
);
layerInputs
[
0
]
=
scores
;
layerInputs
[
1
]
=
umat_fakeImageBlob
;
priorBoxLayer
->
forward
(
layerInputs
,
layerOutputs
,
internals
);
// Permute scores.
layerInputs
.
assign
(
1
,
getObjectScores
(
scores
));
layerOutputs
.
assign
(
1
,
permuttedScores
);
scoresPermute
->
forward
(
layerInputs
,
layerOutputs
,
internals
);
// Permute deltas.
layerInputs
.
assign
(
1
,
bboxDeltas
);
layerOutputs
.
assign
(
1
,
permuttedDeltas
);
deltasPermute
->
forward
(
layerInputs
,
layerOutputs
,
internals
);
// Sort predictions by scores and apply NMS. DetectionOutputLayer allocates
// output internally because of different number of objects after NMS.
layerInputs
.
resize
(
4
);
layerInputs
[
0
]
=
permuttedDeltas
;
layerInputs
[
1
]
=
permuttedScores
;
layerInputs
[
2
]
=
priorBoxes
;
layerInputs
[
3
]
=
umat_fakeImageBlob
;
layerOutputs
[
0
]
=
UMat
();
detectionOutputLayer
->
forward
(
layerInputs
,
layerOutputs
,
internals
);
// DetectionOutputLayer produces 1x1xNx7 output where N might be less or
// equal to keepTopAfterNMS. We fill the rest by zeros.
const
int
numDets
=
layerOutputs
[
0
].
total
()
/
7
;
CV_Assert
(
numDets
<=
keepTopAfterNMS
);
MatShape
s
=
shape
(
numDets
,
7
);
UMat
src
=
layerOutputs
[
0
].
reshape
(
1
,
s
.
size
(),
&
s
[
0
]).
colRange
(
3
,
7
);
UMat
dst
=
outputs
[
0
].
rowRange
(
0
,
numDets
);
src
.
copyTo
(
dst
.
colRange
(
1
,
5
));
dst
.
col
(
0
).
setTo
(
0
);
// First column are batch ids. Keep it zeros too.
if
(
numDets
<
keepTopAfterNMS
)
outputs
[
0
].
rowRange
(
numDets
,
keepTopAfterNMS
).
setTo
(
0
);
return
true
;
}
#endif
void
forward
(
InputArrayOfArrays
inputs_arr
,
OutputArrayOfArrays
outputs_arr
,
OutputArrayOfArrays
internals_arr
)
{
CV_TRACE_FUNCTION
();
CV_TRACE_ARG_VALUE
(
name
,
"name"
,
name
.
c_str
());
CV_OCL_RUN
((
preferableTarget
==
DNN_TARGET_OPENCL
)
&&
OCL_PERFORMANCE_CHECK
(
ocl
::
Device
::
getDefault
().
isIntel
()),
forward_ocl
(
inputs_arr
,
outputs_arr
,
internals_arr
))
Layer
::
forward_fallback
(
inputs_arr
,
outputs_arr
,
internals_arr
);
}
...
...
@@ -226,6 +304,20 @@ private:
return
slice
(
m
,
Range
::
all
(),
Range
(
channels
/
2
,
channels
));
}
#ifdef HAVE_OPENCL
static
UMat
getObjectScores
(
const
UMat
&
m
)
{
CV_Assert
(
m
.
dims
==
4
);
CV_Assert
(
m
.
size
[
0
]
==
1
);
int
channels
=
m
.
size
[
1
];
CV_Assert
((
channels
&
1
)
==
0
);
Range
r
=
Range
(
channels
/
2
,
channels
);
Range
ranges
[
4
]
=
{
Range
::
all
(),
r
,
Range
::
all
(),
Range
::
all
()
};
return
m
(
&
ranges
[
0
]);
}
#endif
Ptr
<
PriorBoxLayer
>
priorBoxLayer
;
Ptr
<
DetectionOutputLayer
>
detectionOutputLayer
;
...
...
@@ -233,6 +325,9 @@ private:
Ptr
<
PermuteLayer
>
scoresPermute
;
uint32_t
keepTopAfterNMS
;
Mat
fakeImageBlob
;
#ifdef HAVE_OPENCL
UMat
umat_fakeImageBlob
;
#endif
};
...
...
samples/dnn/resnet_ssd_face.cpp
View file @
f46eff4e
...
...
@@ -30,6 +30,7 @@ const char* params
"{ model | | model weights (res10_300x300_ssd_iter_140000.caffemodel) }"
"{ camera_device | 0 | camera device number }"
"{ video | | video or image for detection }"
"{ opencl | false | enable OpenCL }"
"{ min_confidence | 0.5 | min confidence }"
;
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -62,6 +63,11 @@ int main(int argc, char** argv)
exit
(
-
1
);
}
if
(
parser
.
get
<
bool
>
(
"opencl"
))
{
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
}
VideoCapture
cap
;
if
(
parser
.
get
<
String
>
(
"video"
).
empty
())
{
...
...
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