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
d83aa810
Commit
d83aa810
authored
Jul 18, 2016
by
Anna Petrovicheva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some fixes for layers
parent
15358eb4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
47 deletions
+53
-47
detection_output_layer.cpp
modules/dnn/src/layers/detection_output_layer.cpp
+0
-0
detection_output_layer.hpp
modules/dnn/src/layers/detection_output_layer.hpp
+44
-38
flatten_layer.cpp
modules/dnn/src/layers/flatten_layer.cpp
+4
-4
flatten_layer.hpp
modules/dnn/src/layers/flatten_layer.hpp
+1
-1
normalize_bbox_layer.cpp
modules/dnn/src/layers/normalize_bbox_layer.cpp
+3
-3
prior_box_layer.cpp
modules/dnn/src/layers/prior_box_layer.cpp
+1
-1
No files found.
modules/dnn/src/layers/detection_output_layer.cpp
View file @
d83aa810
This diff is collapsed.
Click to expand it.
modules/dnn/src/layers/detection_output_layer.hpp
View file @
d83aa810
...
@@ -41,7 +41,9 @@
...
@@ -41,7 +41,9 @@
#ifndef __OPENCV_DNN_LAYERS_DETECTION_OUTPUT_LAYER_HPP__
#ifndef __OPENCV_DNN_LAYERS_DETECTION_OUTPUT_LAYER_HPP__
#define __OPENCV_DNN_LAYERS_DETECTION_OUTPUT_LAYER_HPP__
#define __OPENCV_DNN_LAYERS_DETECTION_OUTPUT_LAYER_HPP__
#include "../precomp.hpp"
#include "../precomp.hpp"
#include "caffe.pb.h"
namespace
cv
namespace
cv
{
{
...
@@ -54,7 +56,10 @@ class DetectionOutputLayer : public Layer
...
@@ -54,7 +56,10 @@ class DetectionOutputLayer : public Layer
int
_numLocClasses
;
int
_numLocClasses
;
int
_backgroundLabelId
;
int
_backgroundLabelId
;
typedef
caffe
::
PriorBoxParameter_CodeType
CodeType
;
CodeType
_codeType
;
CodeType
_codeType
;
bool
_varianceEncodedInTarget
;
bool
_varianceEncodedInTarget
;
int
_keepTopK
;
int
_keepTopK
;
float
_confidenceThreshold
;
float
_confidenceThreshold
;
...
@@ -66,38 +71,45 @@ class DetectionOutputLayer : public Layer
...
@@ -66,38 +71,45 @@ class DetectionOutputLayer : public Layer
int
_topK
;
int
_topK
;
static
const
size_t
_numAxes
=
4
;
static
const
size_t
_numAxes
=
4
;
static
const
std
::
string
_layerName
;
public
:
public
:
DetectionOutputLayer
(
LayerParams
&
params
);
DetectionOutputLayer
(
LayerParams
&
params
);
void
allocate
(
const
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
allocate
(
const
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
checkParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
);
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
typedef
std
::
map
<
int
,
std
::
vector
<
NormalizedBBox
>
>
LabelBBox
;
template
<
typename
T
>
typedef
PriorBoxParameter_CodeType
CodeType
;
T
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
const
size_t
&
idx
=
0
);
// Clip the NormalizedBBox such that the range for each corner is [0, 1].
DictValue
getParameterDict
(
const
LayerParams
&
params
,
void
ClipBBox
(
const
NormalizedBBox
&
bbox
,
NormalizedBBox
*
clip_bbox
);
const
std
::
string
&
parameterName
);
typedef
std
::
map
<
int
,
std
::
vector
<
caffe
::
NormalizedBBox
>
>
LabelBBox
;
// Clip the caffe::NormalizedBBox such that the range for each corner is [0, 1].
void
ClipBBox
(
const
caffe
::
NormalizedBBox
&
bbox
,
caffe
::
NormalizedBBox
*
clip_bbox
);
// Decode a bbox according to a prior bbox.
// Decode a bbox according to a prior bbox.
void
DecodeBBox
(
const
NormalizedBBox
&
prior_bbox
,
void
DecodeBBox
(
const
caffe
::
NormalizedBBox
&
prior_bbox
,
const
std
::
vector
<
float
>&
prior_variance
,
const
CodeType
code_type
,
const
std
::
vector
<
float
>&
prior_variance
,
const
CodeType
code_type
,
const
bool
variance_encoded_in_target
,
const
NormalizedBBox
&
bbox
,
const
bool
variance_encoded_in_target
,
const
caffe
::
NormalizedBBox
&
bbox
,
NormalizedBBox
*
decode_bbox
);
caffe
::
NormalizedBBox
*
decode_bbox
);
// Decode a set of bboxes according to a set of prior bboxes.
// Decode a set of bboxes according to a set of prior bboxes.
void
DecodeBBoxes
(
const
std
::
vector
<
NormalizedBBox
>&
prior_bboxes
,
void
DecodeBBoxes
(
const
std
::
vector
<
caffe
::
NormalizedBBox
>&
prior_bboxes
,
const
std
::
vector
<
std
::
vector
<
float
>
>&
prior_variances
,
const
std
::
vector
<
std
::
vector
<
float
>
>&
prior_variances
,
const
CodeType
code_type
,
const
bool
variance_encoded_in_target
,
const
CodeType
code_type
,
const
bool
variance_encoded_in_target
,
const
std
::
vector
<
NormalizedBBox
>&
bboxes
,
const
std
::
vector
<
caffe
::
NormalizedBBox
>&
bboxes
,
std
::
vector
<
NormalizedBBox
>*
decode_bboxes
);
std
::
vector
<
caffe
::
NormalizedBBox
>*
decode_bboxes
);
// Decode all bboxes in a batch.
// Decode all bboxes in a batch.
void
DecodeBBoxesAll
(
const
std
::
vector
<
LabelBBox
>&
all_loc_pred
,
void
DecodeBBoxesAll
(
const
std
::
vector
<
LabelBBox
>&
all_loc_pred
,
const
std
::
vector
<
NormalizedBBox
>&
prior_bboxes
,
const
std
::
vector
<
caffe
::
NormalizedBBox
>&
prior_bboxes
,
const
std
::
vector
<
std
::
vector
<
float
>
>&
prior_variances
,
const
std
::
vector
<
std
::
vector
<
float
>
>&
prior_variances
,
const
in
t
num
,
const
bool
share_location
,
const
size_
t
num
,
const
bool
share_location
,
const
int
num_loc_classes
,
const
int
background_label_id
,
const
int
num_loc_classes
,
const
int
background_label_id
,
const
CodeType
code_type
,
const
bool
variance_encoded_in_target
,
const
CodeType
code_type
,
const
bool
variance_encoded_in_target
,
std
::
vector
<
LabelBBox
>*
all_decode_bboxes
);
std
::
vector
<
LabelBBox
>*
all_decode_bboxes
);
...
@@ -105,16 +117,15 @@ public:
...
@@ -105,16 +117,15 @@ public:
// Get prior bounding boxes from prior_data.
// Get prior bounding boxes from prior_data.
// prior_data: 1 x 2 x num_priors * 4 x 1 blob.
// prior_data: 1 x 2 x num_priors * 4 x 1 blob.
// num_priors: number of priors.
// num_priors: number of priors.
// prior_bboxes: stores all the prior bboxes in the format of NormalizedBBox.
// prior_bboxes: stores all the prior bboxes in the format of
caffe::
NormalizedBBox.
// prior_variances: stores all the variances needed by prior bboxes.
// prior_variances: stores all the variances needed by prior bboxes.
template
<
typename
Dtype
>
void
GetPriorBBoxes
(
const
float
*
priorData
,
const
int
&
numPriors
,
void
GetPriorBBoxes
(
const
Dtype
*
prior_data
,
const
int
num_priors
,
std
::
vector
<
caffe
::
NormalizedBBox
>*
priorBBoxes
,
std
::
vector
<
NormalizedBBox
>*
prior_bboxes
,
std
::
vector
<
std
::
vector
<
float
>
>*
priorVariances
);
std
::
vector
<
std
::
vector
<
float
>
>*
prior_variances
);
// Scale the NormalizedBBox w.r.t. height and width.
// Scale the
caffe::
NormalizedBBox w.r.t. height and width.
void
ScaleBBox
(
const
NormalizedBBox
&
bbox
,
const
int
height
,
const
int
width
,
void
ScaleBBox
(
const
caffe
::
NormalizedBBox
&
bbox
,
const
int
height
,
const
int
width
,
NormalizedBBox
*
scale_bbox
);
caffe
::
NormalizedBBox
*
scale_bbox
);
// Do non maximum suppression given bboxes and scores.
// Do non maximum suppression given bboxes and scores.
// Inspired by Piotr Dollar's NMS implementation in EdgeBox.
// Inspired by Piotr Dollar's NMS implementation in EdgeBox.
...
@@ -125,7 +136,7 @@ public:
...
@@ -125,7 +136,7 @@ public:
// nms_threshold: a threshold used in non maximum suppression.
// nms_threshold: a threshold used in non maximum suppression.
// top_k: if not -1, keep at most top_k picked indices.
// top_k: if not -1, keep at most top_k picked indices.
// indices: the kept indices of bboxes after nms.
// indices: the kept indices of bboxes after nms.
void
ApplyNMSFast
(
const
std
::
vector
<
NormalizedBBox
>&
bboxes
,
void
ApplyNMSFast
(
const
std
::
vector
<
caffe
::
NormalizedBBox
>&
bboxes
,
const
std
::
vector
<
float
>&
scores
,
const
float
score_threshold
,
const
std
::
vector
<
float
>&
scores
,
const
float
score_threshold
,
const
float
nms_threshold
,
const
int
top_k
,
std
::
vector
<
int
>*
indices
);
const
float
nms_threshold
,
const
int
top_k
,
std
::
vector
<
int
>*
indices
);
...
@@ -140,7 +151,8 @@ public:
...
@@ -140,7 +151,8 @@ public:
// overlaps: a temp place to optionally store the overlaps between pairs of
// overlaps: a temp place to optionally store the overlaps between pairs of
// bboxes if reuse_overlaps is true.
// bboxes if reuse_overlaps is true.
// indices: the kept indices of bboxes after nms.
// indices: the kept indices of bboxes after nms.
void
ApplyNMS
(
const
std
::
vector
<
NormalizedBBox
>&
bboxes
,
const
std
::
vector
<
float
>&
scores
,
void
ApplyNMS
(
const
std
::
vector
<
caffe
::
NormalizedBBox
>&
bboxes
,
const
std
::
vector
<
float
>&
scores
,
const
float
threshold
,
const
int
top_k
,
const
bool
reuse_overlaps
,
const
float
threshold
,
const
int
top_k
,
const
bool
reuse_overlaps
,
std
::
map
<
int
,
std
::
map
<
int
,
float
>
>*
overlaps
,
std
::
vector
<
int
>*
indices
);
std
::
map
<
int
,
std
::
map
<
int
,
float
>
>*
overlaps
,
std
::
vector
<
int
>*
indices
);
...
@@ -153,8 +165,7 @@ public:
...
@@ -153,8 +165,7 @@ public:
// num_classes: number of classes.
// num_classes: number of classes.
// conf_preds: stores the confidence prediction, where each item contains
// conf_preds: stores the confidence prediction, where each item contains
// confidence prediction for an image.
// confidence prediction for an image.
template
<
typename
Dtype
>
void
GetConfidenceScores
(
const
float
*
conf_data
,
const
int
num
,
void
GetConfidenceScores
(
const
Dtype
*
conf_data
,
const
int
num
,
const
int
num_preds_per_class
,
const
int
num_classes
,
const
int
num_preds_per_class
,
const
int
num_classes
,
std
::
vector
<
std
::
map
<
int
,
std
::
vector
<
float
>
>
>*
conf_scores
);
std
::
vector
<
std
::
map
<
int
,
std
::
vector
<
float
>
>
>*
conf_scores
);
...
@@ -168,10 +179,10 @@ public:
...
@@ -168,10 +179,10 @@ public:
// num x num_preds_per_class * num_classes.
// num x num_preds_per_class * num_classes.
// conf_preds: stores the confidence prediction, where each item contains
// conf_preds: stores the confidence prediction, where each item contains
// confidence prediction for an image.
// confidence prediction for an image.
template
<
typename
Dtype
>
void
GetConfidenceScores
(
const
float
*
conf_data
,
const
int
num
,
void
GetConfidenceScores
(
const
Dtype
*
conf_data
,
const
int
num
,
const
int
num_preds_per_class
,
const
int
num_classes
,
const
int
num_preds_per_class
,
const
int
num_classes
,
const
bool
class_major
,
std
::
vector
<
std
::
map
<
int
,
std
::
vector
<
float
>
>
>*
conf_scores
);
const
bool
class_major
,
std
::
vector
<
std
::
map
<
int
,
std
::
vector
<
float
>
>
>*
conf_scores
);
// Get location predictions from loc_data.
// Get location predictions from loc_data.
// loc_data: num x num_preds_per_class * num_loc_classes * 4 blob.
// loc_data: num x num_preds_per_class * num_loc_classes * 4 blob.
...
@@ -182,8 +193,7 @@ public:
...
@@ -182,8 +193,7 @@ public:
// share_location: if true, all classes share the same location prediction.
// share_location: if true, all classes share the same location prediction.
// loc_preds: stores the location prediction, where each item contains
// loc_preds: stores the location prediction, where each item contains
// location prediction for an image.
// location prediction for an image.
template
<
typename
Dtype
>
void
GetLocPredictions
(
const
float
*
loc_data
,
const
int
num
,
void
GetLocPredictions
(
const
Dtype
*
loc_data
,
const
int
num
,
const
int
num_preds_per_class
,
const
int
num_loc_classes
,
const
int
num_preds_per_class
,
const
int
num_loc_classes
,
const
bool
share_location
,
std
::
vector
<
LabelBBox
>*
loc_preds
);
const
bool
share_location
,
std
::
vector
<
LabelBBox
>*
loc_preds
);
...
@@ -195,20 +205,16 @@ public:
...
@@ -195,20 +205,16 @@ public:
void
GetMaxScoreIndex
(
const
std
::
vector
<
float
>&
scores
,
const
float
threshold
,
void
GetMaxScoreIndex
(
const
std
::
vector
<
float
>&
scores
,
const
float
threshold
,
const
int
top_k
,
std
::
vector
<
std
::
pair
<
float
,
int
>
>*
score_index_vec
);
const
int
top_k
,
std
::
vector
<
std
::
pair
<
float
,
int
>
>*
score_index_vec
);
template
<
typename
T
>
bool
SortScorePairDescend
(
const
std
::
pair
<
float
,
T
>&
pair1
,
const
std
::
pair
<
float
,
T
>&
pair2
);
// Compute the jaccard (intersection over union IoU) overlap between two bboxes.
// Compute the jaccard (intersection over union IoU) overlap between two bboxes.
float
JaccardOverlap
(
const
NormalizedBBox
&
bbox1
,
const
NormalizedBBox
&
bbox2
,
float
JaccardOverlap
(
const
caffe
::
NormalizedBBox
&
bbox1
,
const
caffe
::
NormalizedBBox
&
bbox2
,
const
bool
normalized
=
true
);
const
bool
normalized
=
true
);
// Compute the intersection between two bboxes.
// Compute the intersection between two bboxes.
void
IntersectBBox
(
const
NormalizedBBox
&
bbox1
,
const
NormalizedBBox
&
bbox2
,
void
IntersectBBox
(
const
caffe
::
NormalizedBBox
&
bbox1
,
const
caffe
::
NormalizedBBox
&
bbox2
,
NormalizedBBox
*
intersect_bbox
);
caffe
::
NormalizedBBox
*
intersect_bbox
);
// Compute bbox size.
// Compute bbox size.
float
BBoxSize
(
const
NormalizedBBox
&
bbox
,
const
bool
normalized
=
true
);
float
BBoxSize
(
const
caffe
::
NormalizedBBox
&
bbox
,
const
bool
normalized
=
true
);
};
};
}
}
}
}
...
...
modules/dnn/src/layers/flatten_layer.cpp
View file @
d83aa810
...
@@ -87,8 +87,8 @@ T FlattenLayer::getParameter(const LayerParams ¶ms,
...
@@ -87,8 +87,8 @@ T FlattenLayer::getParameter(const LayerParams ¶ms,
FlattenLayer
::
FlattenLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
FlattenLayer
::
FlattenLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
{
{
_startAxis
=
getParameter
<
size_
t
>
(
params
,
"start_axis"
);
_startAxis
=
getParameter
<
in
t
>
(
params
,
"start_axis"
);
_endAxis
=
getParameter
<
size_
t
>
(
params
,
"end_axis"
);
_endAxis
=
getParameter
<
in
t
>
(
params
,
"end_axis"
);
if
(
_endAxis
<=
0
)
if
(
_endAxis
<=
0
)
{
{
...
@@ -113,7 +113,7 @@ void FlattenLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
...
@@ -113,7 +113,7 @@ void FlattenLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
checkInputs
(
inputs
);
checkInputs
(
inputs
);
size_t
flattenedDimensionSize
=
1
;
size_t
flattenedDimensionSize
=
1
;
for
(
size_
t
i
=
_startAxis
;
i
<=
_endAxis
;
i
++
)
for
(
in
t
i
=
_startAxis
;
i
<=
_endAxis
;
i
++
)
{
{
flattenedDimensionSize
*=
inputs
[
0
]
->
shape
()[
i
];
flattenedDimensionSize
*=
inputs
[
0
]
->
shape
()[
i
];
}
}
...
@@ -126,7 +126,7 @@ void FlattenLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
...
@@ -126,7 +126,7 @@ void FlattenLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
{
{
outputShape
[
i
]
=
1
;
outputShape
[
i
]
=
1
;
}
}
for
(
size_
t
i
=
interval
;
i
<
_endAxis
;
i
++
)
for
(
in
t
i
=
interval
;
i
<
_endAxis
;
i
++
)
{
{
outputShape
[
i
]
=
inputs
[
0
]
->
shape
()[
i
-
interval
];
outputShape
[
i
]
=
inputs
[
0
]
->
shape
()[
i
-
interval
];
}
}
...
...
modules/dnn/src/layers/flatten_layer.hpp
View file @
d83aa810
...
@@ -50,7 +50,7 @@ namespace dnn
...
@@ -50,7 +50,7 @@ namespace dnn
class
FlattenLayer
:
public
Layer
class
FlattenLayer
:
public
Layer
{
{
size_t
_startAxis
;
size_t
_startAxis
;
size_
t
_endAxis
;
in
t
_endAxis
;
static
const
size_t
_numAxes
=
4
;
static
const
size_t
_numAxes
=
4
;
static
const
std
::
string
_layerName
;
static
const
std
::
string
_layerName
;
...
...
modules/dnn/src/layers/normalize_bbox_layer.cpp
View file @
d83aa810
...
@@ -134,13 +134,13 @@ void NormalizeBBoxLayer::allocate(const std::vector<Blob*> &inputs, std::vector<
...
@@ -134,13 +134,13 @@ void NormalizeBBoxLayer::allocate(const std::vector<Blob*> &inputs, std::vector<
}
}
// add eps to avoid overflow
// add eps to avoid overflow
_norm
.
fill
(
Scalar
(
_eps
)
);
_norm
.
matRef
()
=
Scalar
(
_eps
);
_sumChannelMultiplier
=
Blob
(
BlobShape
(
1
,
_channels
,
1
,
1
));
_sumChannelMultiplier
=
Blob
(
BlobShape
(
1
,
_channels
,
1
,
1
));
_sumChannelMultiplier
.
fill
(
Scalar
(
1.0
)
);
_sumChannelMultiplier
.
matRef
()
=
Scalar
(
1.0
);
_sumSpatialMultiplier
=
Blob
(
BlobShape
(
1
,
1
,
_rows
,
_cols
));
_sumSpatialMultiplier
=
Blob
(
BlobShape
(
1
,
1
,
_rows
,
_cols
));
_sumSpatialMultiplier
.
fill
(
Scalar
(
1.0
)
);
_sumSpatialMultiplier
.
matRef
()
=
Scalar
(
1.0
);
if
(
_channel_shared
)
if
(
_channel_shared
)
{
{
...
...
modules/dnn/src/layers/prior_box_layer.cpp
View file @
d83aa810
...
@@ -147,7 +147,7 @@ void PriorBoxLayer::getVariance(const LayerParams ¶ms)
...
@@ -147,7 +147,7 @@ void PriorBoxLayer::getVariance(const LayerParams ¶ms)
PriorBoxLayer
::
PriorBoxLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
PriorBoxLayer
::
PriorBoxLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
{
{
_minSize
=
getParameter
<
size_t
>
(
params
,
"min_size"
);
_minSize
=
getParameter
<
unsigned
>
(
params
,
"min_size"
);
CV_Assert
(
_minSize
>
0
);
CV_Assert
(
_minSize
>
0
);
_flip
=
getParameter
<
bool
>
(
params
,
"flip"
);
_flip
=
getParameter
<
bool
>
(
params
,
"flip"
);
...
...
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