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
e7d62d6e
Commit
e7d62d6e
authored
Nov 22, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10126 from alalek:dnn_issue_10125
parents
f8ad2893
9db5cbf9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
82 deletions
+91
-82
mat.hpp
modules/core/include/opencv2/core/mat.hpp
+3
-0
matrix.cpp
modules/core/src/matrix.cpp
+76
-0
dnn.cpp
modules/dnn/src/dnn.cpp
+4
-0
detection_output_layer.cpp
modules/dnn/src/layers/detection_output_layer.cpp
+0
-81
ssd_mobilenet_object_detection.cpp
samples/dnn/ssd_mobilenet_object_detection.cpp
+8
-1
No files found.
modules/core/include/opencv2/core/mat.hpp
View file @
e7d62d6e
...
...
@@ -357,6 +357,9 @@ public:
void
assign
(
const
UMat
&
u
)
const
;
void
assign
(
const
Mat
&
m
)
const
;
void
assign
(
const
std
::
vector
<
UMat
>&
v
)
const
;
void
assign
(
const
std
::
vector
<
Mat
>&
v
)
const
;
};
...
...
modules/core/src/matrix.cpp
View file @
e7d62d6e
...
...
@@ -3053,6 +3053,82 @@ void _OutputArray::assign(const Mat& m) const
}
void
_OutputArray
::
assign
(
const
std
::
vector
<
UMat
>&
v
)
const
{
int
k
=
kind
();
if
(
k
==
STD_VECTOR_UMAT
)
{
std
::
vector
<
UMat
>&
this_v
=
*
(
std
::
vector
<
UMat
>*
)
obj
;
CV_Assert
(
this_v
.
size
()
==
v
.
size
());
for
(
size_t
i
=
0
;
i
<
v
.
size
();
i
++
)
{
const
UMat
&
m
=
v
[
i
];
UMat
&
this_m
=
this_v
[
i
];
if
(
this_m
.
u
!=
NULL
&&
this_m
.
u
==
m
.
u
)
continue
;
// same object (see dnn::Layer::forward_fallback)
m
.
copyTo
(
this_m
);
}
}
else
if
(
k
==
STD_VECTOR_MAT
)
{
std
::
vector
<
Mat
>&
this_v
=
*
(
std
::
vector
<
Mat
>*
)
obj
;
CV_Assert
(
this_v
.
size
()
==
v
.
size
());
for
(
size_t
i
=
0
;
i
<
v
.
size
();
i
++
)
{
const
UMat
&
m
=
v
[
i
];
Mat
&
this_m
=
this_v
[
i
];
if
(
this_m
.
u
!=
NULL
&&
this_m
.
u
==
m
.
u
)
continue
;
// same object (see dnn::Layer::forward_fallback)
m
.
copyTo
(
this_m
);
}
}
else
{
CV_Error
(
Error
::
StsNotImplemented
,
""
);
}
}
void
_OutputArray
::
assign
(
const
std
::
vector
<
Mat
>&
v
)
const
{
int
k
=
kind
();
if
(
k
==
STD_VECTOR_UMAT
)
{
std
::
vector
<
UMat
>&
this_v
=
*
(
std
::
vector
<
UMat
>*
)
obj
;
CV_Assert
(
this_v
.
size
()
==
v
.
size
());
for
(
size_t
i
=
0
;
i
<
v
.
size
();
i
++
)
{
const
Mat
&
m
=
v
[
i
];
UMat
&
this_m
=
this_v
[
i
];
if
(
this_m
.
u
!=
NULL
&&
this_m
.
u
==
m
.
u
)
continue
;
// same object (see dnn::Layer::forward_fallback)
m
.
copyTo
(
this_m
);
}
}
else
if
(
k
==
STD_VECTOR_MAT
)
{
std
::
vector
<
Mat
>&
this_v
=
*
(
std
::
vector
<
Mat
>*
)
obj
;
CV_Assert
(
this_v
.
size
()
==
v
.
size
());
for
(
size_t
i
=
0
;
i
<
v
.
size
();
i
++
)
{
const
Mat
&
m
=
v
[
i
];
Mat
&
this_m
=
this_v
[
i
];
if
(
this_m
.
u
!=
NULL
&&
this_m
.
u
==
m
.
u
)
continue
;
// same object (see dnn::Layer::forward_fallback)
m
.
copyTo
(
this_m
);
}
}
else
{
CV_Error
(
Error
::
StsNotImplemented
,
""
);
}
}
static
_InputOutputArray
_none
;
InputOutputArray
noArray
()
{
return
_none
;
}
...
...
modules/dnn/src/dnn.cpp
View file @
e7d62d6e
...
...
@@ -2381,6 +2381,10 @@ void Layer::forward_fallback(InputArrayOfArrays inputs_arr, OutputArrayOfArrays
inputs
[
i
]
=
&
inpvec
[
i
];
this
->
forward
(
inputs
,
outputs
,
internals
);
// sync results back
outputs_arr
.
assign
(
outputs
);
internals_arr
.
assign
(
internals
);
}
void
Layer
::
run
(
const
std
::
vector
<
Mat
>
&
inputs
,
std
::
vector
<
Mat
>
&
outputs
,
std
::
vector
<
Mat
>
&
internals
)
...
...
modules/dnn/src/layers/detection_output_layer.cpp
View file @
e7d62d6e
...
...
@@ -211,92 +211,11 @@ public:
return
false
;
}
#ifdef HAVE_OPENCL
bool
forward_ocl
(
InputArrayOfArrays
inputs_arr
,
OutputArrayOfArrays
outputs_arr
,
OutputArrayOfArrays
internals_arr
)
{
std
::
vector
<
Mat
>
inpvec
;
std
::
vector
<
Mat
>
outputs
;
inputs_arr
.
getMatVector
(
inpvec
);
outputs_arr
.
getMatVector
(
outputs
);
std
::
vector
<
Mat
*>
inputs
(
inpvec
.
size
());
for
(
size_t
i
=
0
;
i
<
inpvec
.
size
();
i
++
)
inputs
[
i
]
=
&
inpvec
[
i
];
std
::
vector
<
LabelBBox
>
allDecodedBBoxes
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>
>
>
allConfidenceScores
;
int
num
=
inputs
[
0
]
->
size
[
0
];
// extract predictions from input layers
{
int
numPriors
=
inputs
[
2
]
->
size
[
2
]
/
4
;
const
float
*
locationData
=
inputs
[
0
]
->
ptr
<
float
>
();
const
float
*
confidenceData
=
inputs
[
1
]
->
ptr
<
float
>
();
const
float
*
priorData
=
inputs
[
2
]
->
ptr
<
float
>
();
// Retrieve all location predictions
std
::
vector
<
LabelBBox
>
allLocationPredictions
;
GetLocPredictions
(
locationData
,
num
,
numPriors
,
_numLocClasses
,
_shareLocation
,
_locPredTransposed
,
allLocationPredictions
);
// Retrieve all confidences
GetConfidenceScores
(
confidenceData
,
num
,
numPriors
,
_numClasses
,
allConfidenceScores
);
// Retrieve all prior bboxes
std
::
vector
<
util
::
NormalizedBBox
>
priorBBoxes
;
std
::
vector
<
std
::
vector
<
float
>
>
priorVariances
;
GetPriorBBoxes
(
priorData
,
numPriors
,
priorBBoxes
,
priorVariances
);
// Decode all loc predictions to bboxes
DecodeBBoxesAll
(
allLocationPredictions
,
priorBBoxes
,
priorVariances
,
num
,
_shareLocation
,
_numLocClasses
,
_backgroundLabelId
,
_codeType
,
_varianceEncodedInTarget
,
false
,
allDecodedBBoxes
);
}
size_t
numKept
=
0
;
std
::
vector
<
std
::
map
<
int
,
std
::
vector
<
int
>
>
>
allIndices
;
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
numKept
+=
processDetections_
(
allDecodedBBoxes
[
i
],
allConfidenceScores
[
i
],
allIndices
);
}
if
(
numKept
==
0
)
{
// Set confidences to zeros.
Range
ranges
[]
=
{
Range
::
all
(),
Range
::
all
(),
Range
::
all
(),
Range
(
2
,
3
)};
outputs
[
0
](
ranges
).
setTo
(
0
);
return
true
;
}
int
outputShape
[]
=
{
1
,
1
,
(
int
)
numKept
,
7
};
Mat
mat
(
4
,
outputShape
,
CV_32F
);
float
*
outputsData
=
mat
.
ptr
<
float
>
();
size_t
count
=
0
;
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
count
+=
outputDetections_
(
i
,
&
outputsData
[
count
*
7
],
allDecodedBBoxes
[
i
],
allConfidenceScores
[
i
],
allIndices
[
i
]);
}
UMat
&
output
=
outputs_arr
.
getUMatRef
(
0
);
output
=
mat
.
getUMat
(
ACCESS_READ
);
CV_Assert
(
count
==
numKept
);
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
);
}
...
...
samples/dnn/ssd_mobilenet_object_detection.cpp
View file @
e7d62d6e
...
...
@@ -37,7 +37,9 @@ const char* params
"{ camera_device | 0 | camera device number }"
"{ video | | video or image for detection}"
"{ out | | path to output video file}"
"{ min_confidence | 0.2 | min confidence }"
;
"{ min_confidence | 0.2 | min confidence }"
"{ opencl | false | enable OpenCL }"
;
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -57,6 +59,11 @@ int main(int argc, char** argv)
dnn
::
Net
net
=
readNetFromCaffe
(
modelConfiguration
,
modelBinary
);
//! [Initialize network]
if
(
parser
.
get
<
bool
>
(
"opencl"
))
{
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
}
if
(
net
.
empty
())
{
cerr
<<
"Can't load network by using the following files: "
<<
endl
;
...
...
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