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
355d07ec
Commit
355d07ec
authored
Jul 20, 2016
by
Anna Petrovicheva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Network initialized successfully
parent
b65a84fa
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
275 additions
and
211 deletions
+275
-211
ssd_ilsvrc15_300x300.prototxt
modules/dnn/samples/ssd_ilsvrc15_300x300.prototxt
+2
-2
ssd_object_detection.cpp
modules/dnn/samples/ssd_object_detection.cpp
+56
-54
caffe.proto
modules/dnn/src/caffe/caffe.proto
+1
-1
init.cpp
modules/dnn/src/init.cpp
+12
-1
convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+3
-2
detection_output_layer.cpp
modules/dnn/src/layers/detection_output_layer.cpp
+47
-34
detection_output_layer.hpp
modules/dnn/src/layers/detection_output_layer.hpp
+11
-6
flatten_layer.cpp
modules/dnn/src/layers/flatten_layer.cpp
+45
-41
flatten_layer.hpp
modules/dnn/src/layers/flatten_layer.hpp
+9
-6
layers_common.cpp
modules/dnn/src/layers/layers_common.cpp
+8
-7
normalize_bbox_layer.cpp
modules/dnn/src/layers/normalize_bbox_layer.cpp
+29
-23
normalize_bbox_layer.hpp
modules/dnn/src/layers/normalize_bbox_layer.hpp
+8
-4
prior_box_layer.cpp
modules/dnn/src/layers/prior_box_layer.cpp
+36
-26
prior_box_layer.hpp
modules/dnn/src/layers/prior_box_layer.hpp
+8
-4
No files found.
modules/dnn/samples/ssd_ilsvrc15_300x300.prototxt
View file @
355d07ec
...
@@ -500,7 +500,7 @@ layer {
...
@@ -500,7 +500,7 @@ layer {
type: "constant"
type: "constant"
value: 0
value: 0
}
}
#
dilation: 6
dilation: 6
}
}
}
}
layer {
layer {
...
@@ -750,7 +750,7 @@ layer {
...
@@ -750,7 +750,7 @@ layer {
}
}
layer {
layer {
name: "conv4_3_norm"
name: "conv4_3_norm"
type: "Normalize"
type: "Normalize
BBox
"
bottom: "conv4_3"
bottom: "conv4_3"
top: "conv4_3_norm"
top: "conv4_3_norm"
normalize_bbox_param {
normalize_bbox_param {
...
...
modules/dnn/samples/ssd_object_detection.cpp
View file @
355d07ec
...
@@ -9,48 +9,46 @@ using namespace cv::dnn;
...
@@ -9,48 +9,46 @@ using namespace cv::dnn;
#include <cstdlib>
#include <cstdlib>
using
namespace
std
;
using
namespace
std
;
static
const
string
fcnType
=
"fcn8s"
;
//static void colorizeSegmentation(dnn::Blob& score,
static
void
colorizeSegmentation
(
dnn
::
Blob
&
score
,
// const vector<cv::Vec3b>& colors,
const
vector
<
cv
::
Vec3b
>&
colors
,
// cv::Mat& segm)
cv
::
Mat
&
segm
)
//{
{
// const int rows = score.rows();
const
int
rows
=
score
.
rows
();
// const int cols = score.cols();
const
int
cols
=
score
.
cols
();
// const int chns = score.channels();
const
int
chns
=
score
.
channels
();
// cv::Mat maxCl(rows, cols, CV_8UC1);
cv
::
Mat
maxCl
(
rows
,
cols
,
CV_8UC1
);
// cv::Mat maxVal(rows, cols, CV_32FC1);
cv
::
Mat
maxVal
(
rows
,
cols
,
CV_32FC1
);
// for (int ch = 0; ch < chns; ch++)
for
(
int
ch
=
0
;
ch
<
chns
;
ch
++
)
// {
{
// for (int row = 0; row < rows; row++)
for
(
int
row
=
0
;
row
<
rows
;
row
++
)
// {
{
// const float* ptrScore = score.ptrf(0, ch, row);
const
float
*
ptrScore
=
score
.
ptrf
(
0
,
ch
,
row
);
// uchar* ptrMaxCl = maxCl.ptr<uchar>(row);
uchar
*
ptrMaxCl
=
maxCl
.
ptr
<
uchar
>
(
row
);
// float* ptrMaxVal = maxVal.ptr<float>(row);
float
*
ptrMaxVal
=
maxVal
.
ptr
<
float
>
(
row
);
// for (int col = 0; col < cols; col++)
for
(
int
col
=
0
;
col
<
cols
;
col
++
)
// {
{
// if (ptrScore[col] > ptrMaxVal[col])
if
(
ptrScore
[
col
]
>
ptrMaxVal
[
col
])
// {
{
// ptrMaxVal[col] = ptrScore[col];
ptrMaxVal
[
col
]
=
ptrScore
[
col
];
// ptrMaxCl[col] = ch;
ptrMaxCl
[
col
]
=
ch
;
// }
}
// }
}
// }
}
// }
}
// segm.create(rows, cols, CV_8UC3);
segm
.
create
(
rows
,
cols
,
CV_8UC3
);
// for (int row = 0; row < rows; row++)
for
(
int
row
=
0
;
row
<
rows
;
row
++
)
// {
{
// const uchar* ptrMaxCl = maxCl.ptr<uchar>(row);
const
uchar
*
ptrMaxCl
=
maxCl
.
ptr
<
uchar
>
(
row
);
// cv::Vec3b* ptrSegm = segm.ptr<cv::Vec3b>(row);
cv
::
Vec3b
*
ptrSegm
=
segm
.
ptr
<
cv
::
Vec3b
>
(
row
);
// for (int col = 0; col < cols; col++)
for
(
int
col
=
0
;
col
<
cols
;
col
++
)
// {
{
// ptrSegm[col] = colors[ptrMaxCl[col]];
ptrSegm
[
col
]
=
colors
[
ptrMaxCl
[
col
]];
// }
}
// }
}
//}
}
const
char
*
about
=
"This sample uses Single-Shot Detector to detect objects "
const
char
*
about
=
"This sample uses Single-Shot Detector to detect objects "
"from camera
\n
"
;
// TODO: link
"from camera
\n
"
;
// TODO: link
...
@@ -111,6 +109,7 @@ int main(int argc, char** argv)
...
@@ -111,6 +109,7 @@ int main(int argc, char** argv)
return
0
;
return
0
;
}
}
size_t
i
=
0
;
for
(;;
)
for
(;;
)
{
{
Mat
frame
;
Mat
frame
;
...
@@ -118,12 +117,15 @@ int main(int argc, char** argv)
...
@@ -118,12 +117,15 @@ int main(int argc, char** argv)
if
(
frame
.
empty
())
if
(
frame
.
empty
())
break
;
break
;
//! [Prepare blob]
//! [Prepare blob]
resize
(
frame
,
frame
,
Size
(
300
,
300
));
//SSD accepts 300x300 RGB-images
resize
(
frame
,
frame
,
Size
(
300
,
300
));
//SSD accepts 300x300 RGB-images
dnn
::
Blob
inputBlob
=
dnn
::
Blob
(
frame
);
//Convert Mat to dnn::Blob image
dnn
::
Blob
inputBlob
=
dnn
::
Blob
(
frame
);
//Convert Mat to dnn::Blob image
//! [Prepare blob]
//! [Prepare blob]
std
::
ostringstream
stream
;
stream
<<
"folder/"
<<
i
<<
".jpg"
;
imwrite
(
stream
.
str
(),
frame
);
//! [Set input blob]
//! [Set input blob]
net
.
setBlob
(
".data"
,
inputBlob
);
//set the network input
net
.
setBlob
(
".data"
,
inputBlob
);
//set the network input
//! [Set input blob]
//! [Set input blob]
...
@@ -132,20 +134,20 @@ int main(int argc, char** argv)
...
@@ -132,20 +134,20 @@ int main(int argc, char** argv)
net
.
forward
();
//compute output
net
.
forward
();
//compute output
//! [Make forward pass]
//! [Make forward pass]
//! [Gather output]
//
//! [Gather output]
dnn
::
Blob
detection
=
net
.
getBlob
(
"detection_out"
);
//
dnn::Blob detection = net.getBlob("detection_out");
// cv::Mat colorize;
//
// cv::Mat colorize;
// colorizeSegmentation(score, colors, colorize);
//
// colorizeSegmentation(score, colors, colorize);
// cv::Mat show;
//
// cv::Mat show;
// cv::addWeighted(img, 0.4, colorize, 0.6, 0.0, show);
//
// cv::addWeighted(img, 0.4, colorize, 0.6, 0.0, show);
// cv::imshow("show", show);
//
// cv::imshow("show", show);
// cv::waitKey(0);
//
// cv::waitKey(0);
// return 0;
//
// return 0;
imshow
(
"frame"
,
frame
);
//
imshow("frame", frame);
if
(
waitKey
(
1
)
==
27
)
//
if (waitKey(1) == 27)
break
;
// stop capturing by pressing ESC
//
break; // stop capturing by pressing ESC
}
}
camera
.
release
();
camera
.
release
();
...
...
modules/dnn/src/caffe/caffe.proto
View file @
355d07ec
...
@@ -404,7 +404,7 @@ message ParamSpec {
...
@@ -404,7 +404,7 @@ message ParamSpec {
// NOTE
// NOTE
// Update the next available ID when you add a new LayerParameter field.
// Update the next available ID when you add a new LayerParameter field.
//
//
// LayerParameter next available layer-specific ID: 1
38
(last added: detection_output_param)
// LayerParameter next available layer-specific ID: 1
42
(last added: detection_output_param)
message
LayerParameter
{
message
LayerParameter
{
optional
string
name
=
1
;
// the layer name
optional
string
name
=
1
;
// the layer name
optional
string
type
=
2
;
// the layer type
optional
string
type
=
2
;
// the layer type
...
...
modules/dnn/src/init.cpp
View file @
355d07ec
...
@@ -55,6 +55,11 @@
...
@@ -55,6 +55,11 @@
#include "layers/split_layer.hpp"
#include "layers/split_layer.hpp"
#include "layers/crop_layer.hpp"
#include "layers/crop_layer.hpp"
#include "layers/eltwise_layer.hpp"
#include "layers/eltwise_layer.hpp"
#include "layers/flatten_layer.hpp"
#include "layers/permute_layer.hpp"
#include "layers/prior_box_layer.hpp"
#include "layers/detection_output_layer.hpp"
#include "layers/normalize_bbox_layer.hpp"
namespace
cv
namespace
cv
{
{
...
@@ -82,7 +87,7 @@ void initModule()
...
@@ -82,7 +87,7 @@ void initModule()
REG_RUNTIME_LAYER_CLASS
(
Softmax
,
SoftMaxLayer
)
REG_RUNTIME_LAYER_CLASS
(
Softmax
,
SoftMaxLayer
)
REG_RUNTIME_LAYER_CLASS
(
Split
,
SplitLayer
)
REG_RUNTIME_LAYER_CLASS
(
Split
,
SplitLayer
)
REG_RUNTIME_LAYER_CLASS
(
Reshape
,
ReshapeLayer
)
REG_RUNTIME_LAYER_CLASS
(
Reshape
,
ReshapeLayer
)
REG_STATIC_LAYER_FUNC
(
Flatten
,
createFlattenLayer
)
//
REG_STATIC_LAYER_FUNC(Flatten, createFlattenLayer)
REG_RUNTIME_LAYER_CLASS
(
Pooling
,
PoolingLayer
)
REG_RUNTIME_LAYER_CLASS
(
Pooling
,
PoolingLayer
)
REG_RUNTIME_LAYER_CLASS
(
MVN
,
MVNLayer
)
REG_RUNTIME_LAYER_CLASS
(
MVN
,
MVNLayer
)
REG_RUNTIME_LAYER_CLASS
(
LRN
,
LRNLayer
)
REG_RUNTIME_LAYER_CLASS
(
LRN
,
LRNLayer
)
...
@@ -103,6 +108,12 @@ void initModule()
...
@@ -103,6 +108,12 @@ void initModule()
REG_RUNTIME_LAYER_CLASS
(
Crop
,
CropLayer
)
REG_RUNTIME_LAYER_CLASS
(
Crop
,
CropLayer
)
REG_RUNTIME_LAYER_CLASS
(
Eltwise
,
EltwiseLayer
)
REG_RUNTIME_LAYER_CLASS
(
Eltwise
,
EltwiseLayer
)
REG_RUNTIME_LAYER_CLASS
(
Permute
,
PermuteLayer
)
REG_RUNTIME_LAYER_CLASS
(
Flatten
,
FlattenLayer
)
REG_RUNTIME_LAYER_CLASS
(
PriorBox
,
PriorBoxLayer
)
REG_RUNTIME_LAYER_CLASS
(
DetectionOutput
,
DetectionOutputLayer
)
REG_RUNTIME_LAYER_CLASS
(
NormalizeBBox
,
NormalizeBBoxLayer
)
init
.
status
=
true
;
init
.
status
=
true
;
}
}
...
...
modules/dnn/src/layers/convolution_layer.cpp
View file @
355d07ec
...
@@ -190,8 +190,9 @@ namespace dnn
...
@@ -190,8 +190,9 @@ namespace dnn
inpW
=
inpBlob
.
cols
();
inpW
=
inpBlob
.
cols
();
inpCn
=
inpBlob
.
channels
();
inpCn
=
inpBlob
.
channels
();
outH
=
(
inpH
+
2
*
padH
-
kerH
)
/
strideH
+
1
;
outH
=
(
inpH
+
2
*
padH
-
(
dilationH
*
(
kerH
-
1
)
+
1
))
/
strideH
+
1
;
outW
=
(
inpW
+
2
*
padW
-
kerW
)
/
strideW
+
1
;
outW
=
(
inpW
+
2
*
padW
-
(
dilationW
*
(
kerW
-
1
)
+
1
))
/
strideW
+
1
;
outCn
=
numOutput
;
outCn
=
numOutput
;
topH
=
outH
;
topW
=
outW
;
topCn
=
outCn
;
topH
=
outH
;
topW
=
outW
;
topCn
=
outCn
;
...
...
modules/dnn/src/layers/detection_output_layer.cpp
View file @
355d07ec
...
@@ -79,65 +79,78 @@ bool SortScorePairDescend(const std::pair<float, T>& pair1,
...
@@ -79,65 +79,78 @@ bool SortScorePairDescend(const std::pair<float, T>& pair1,
const
std
::
string
DetectionOutputLayer
::
_layerName
=
std
::
string
(
"DetectionOutput"
);
const
std
::
string
DetectionOutputLayer
::
_layerName
=
std
::
string
(
"DetectionOutput"
);
DictValue
DetectionOutputLayer
::
getParameterDict
(
const
LayerParams
&
params
,
bool
DetectionOutputLayer
::
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
)
const
std
::
string
&
parameterName
,
DictValue
&
result
)
{
{
if
(
!
params
.
has
(
parameterName
))
if
(
!
params
.
has
(
parameterName
))
{
{
std
::
string
message
=
_layerName
;
return
false
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" index."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
}
DictValue
parameter
=
params
.
get
(
parameterName
);
result
=
params
.
get
(
parameterName
);
if
(
parameter
.
size
()
!=
1
)
return
true
;
{
std
::
string
message
=
parameterName
;
message
+=
" field in "
;
message
+=
_layerName
;
message
+=
" layer parameter is required"
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
return
parameter
;
}
}
template
<
typename
T
>
template
<
typename
T
>
T
DetectionOutputLayer
::
getParameter
(
const
LayerParams
&
params
,
T
DetectionOutputLayer
::
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
const
std
::
string
&
parameterName
,
const
size_t
&
idx
)
const
size_t
&
idx
,
const
bool
required
,
const
T
&
defaultValue
)
{
DictValue
dictValue
;
bool
success
=
getParameterDict
(
params
,
parameterName
,
dictValue
);
if
(
!
success
)
{
if
(
required
)
{
std
::
string
message
=
_layerName
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" parameter."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
else
{
return
defaultValue
;
}
}
return
dictValue
.
get
<
T
>
(
idx
);
}
void
DetectionOutputLayer
::
getCodeType
(
LayerParams
&
params
)
{
{
return
getParameterDict
(
params
,
parameterName
).
get
<
T
>
(
idx
);
String
codeTypeString
=
params
.
get
<
String
>
(
"code_type"
).
toLowerCase
();
if
(
codeTypeString
==
"corner"
)
_codeType
=
caffe
::
PriorBoxParameter_CodeType_CORNER
;
else
if
(
codeTypeString
==
"center_size"
)
_codeType
=
caffe
::
PriorBoxParameter_CodeType_CENTER_SIZE
;
else
_codeType
=
caffe
::
PriorBoxParameter_CodeType_CORNER
;
}
}
DetectionOutputLayer
::
DetectionOutputLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
DetectionOutputLayer
::
DetectionOutputLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
{
{
_numClasses
=
getParameter
<
int
>
(
params
,
"num_classes"
);
_numClasses
=
getParameter
<
unsigned
>
(
params
,
"num_classes"
);
_shareLocation
=
getParameter
<
int
>
(
params
,
"share_location"
);
_shareLocation
=
getParameter
<
bool
>
(
params
,
"share_location"
);
_numLocClasses
=
_shareLocation
?
1
:
_numClasses
;
_numLocClasses
=
_shareLocation
?
1
:
_numClasses
;
_backgroundLabelId
=
getParameter
<
int
>
(
params
,
"background_label_id"
);
_backgroundLabelId
=
getParameter
<
int
>
(
params
,
"background_label_id"
);
_codeType
=
static_cast
<
CodeType
>
(
getParameter
<
int
>
(
params
,
"code_type"
));
_varianceEncodedInTarget
=
getParameter
<
bool
>
(
params
,
"variance_encoded_in_target"
,
0
,
false
,
false
);
_varianceEncodedInTarget
=
getParameter
<
int
>
(
params
,
"variance_encoded_in_target"
);
_keepTopK
=
getParameter
<
int
>
(
params
,
"keep_top_k"
);
_keepTopK
=
getParameter
<
int
>
(
params
,
"keep_top_k"
);
_confidenceThreshold
=
params
.
has
(
"confidence_threshold"
)
?
_confidenceThreshold
=
getParameter
<
float
>
(
params
,
"confidence_threshold"
,
0
,
false
,
-
FLT_MAX
);
getParameter
<
int
>
(
params
,
"confidence_threshold"
)
:
-
FLT_MAX
;
_topK
=
getParameter
<
int
>
(
params
,
"top_k"
,
0
,
false
,
-
1
);
getCodeType
(
params
);
// Parameters used in nms.
// Parameters used in nms.
_nmsThreshold
=
getParameter
<
float
>
(
params
,
"nms_threshold"
);
_nmsThreshold
=
getParameter
<
float
>
(
params
,
"nms_threshold"
);
CV_Assert
(
_nmsThreshold
>
0.
);
CV_Assert
(
_nmsThreshold
>
0.
);
_topK
=
-
1
;
if
(
params
.
has
(
"top_k"
))
{
_topK
=
getParameter
<
int
>
(
params
,
"top_k"
);
}
}
}
void
DetectionOutputLayer
::
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
)
void
DetectionOutputLayer
::
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
)
{
{
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
for
(
size_t
i
=
1
;
i
<
inputs
.
size
();
i
++
)
{
{
for
(
size_t
j
=
0
;
j
<
_numAxes
;
j
++
)
for
(
size_t
j
=
0
;
j
<
_numAxes
;
j
++
)
{
{
...
...
modules/dnn/src/layers/detection_output_layer.hpp
View file @
355d07ec
...
@@ -51,7 +51,7 @@ namespace dnn
...
@@ -51,7 +51,7 @@ namespace dnn
{
{
class
DetectionOutputLayer
:
public
Layer
class
DetectionOutputLayer
:
public
Layer
{
{
int
_numClasses
;
unsigned
_numClasses
;
bool
_shareLocation
;
bool
_shareLocation
;
int
_numLocClasses
;
int
_numLocClasses
;
...
@@ -79,13 +79,18 @@ public:
...
@@ -79,13 +79,18 @@ public:
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
void
getCodeType
(
LayerParams
&
params
);
template
<
typename
T
>
template
<
typename
T
>
T
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
T
getParameter
(
const
LayerParams
&
params
,
const
size_t
&
idx
=
0
);
const
std
::
string
&
parameterName
,
const
size_t
&
idx
=
0
,
DictValue
getParameterDict
(
const
LayerParams
&
params
,
const
bool
required
=
true
,
const
std
::
string
&
parameterName
);
const
T
&
defaultValue
=
T
());
bool
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
DictValue
&
result
);
typedef
std
::
map
<
int
,
std
::
vector
<
caffe
::
NormalizedBBox
>
>
LabelBBox
;
typedef
std
::
map
<
int
,
std
::
vector
<
caffe
::
NormalizedBBox
>
>
LabelBBox
;
...
...
modules/dnn/src/layers/flatten_layer.cpp
View file @
355d07ec
...
@@ -52,54 +52,56 @@ namespace dnn
...
@@ -52,54 +52,56 @@ namespace dnn
const
std
::
string
FlattenLayer
::
_layerName
=
std
::
string
(
"Flatten"
);
const
std
::
string
FlattenLayer
::
_layerName
=
std
::
string
(
"Flatten"
);
DictValue
FlattenLayer
::
getParameterDict
(
const
LayerParams
&
params
,
bool
FlattenLayer
::
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
)
const
std
::
string
&
parameterName
,
DictValue
&
result
)
{
{
if
(
!
params
.
has
(
parameterName
))
if
(
!
params
.
has
(
parameterName
))
{
{
std
::
string
message
=
_layerName
;
return
false
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" index."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
}
DictValue
parameter
=
params
.
get
(
parameterName
);
result
=
params
.
get
(
parameterName
);
if
(
parameter
.
size
()
!=
1
)
return
true
;
{
std
::
string
message
=
parameterName
;
message
+=
" field in "
;
message
+=
_layerName
;
message
+=
" layer parameter is required"
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
return
parameter
;
}
}
template
<
typename
T
>
template
<
typename
T
>
T
FlattenLayer
::
getParameter
(
const
LayerParams
&
params
,
T
FlattenLayer
::
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
const
std
::
string
&
parameterName
,
const
size_t
&
idx
)
const
size_t
&
idx
,
const
bool
required
,
const
T
&
defaultValue
)
{
{
return
getParameterDict
(
params
,
parameterName
).
get
<
T
>
(
idx
);
DictValue
dictValue
;
bool
success
=
getParameterDict
(
params
,
parameterName
,
dictValue
);
if
(
!
success
)
{
if
(
required
)
{
std
::
string
message
=
_layerName
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" parameter."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
else
{
return
defaultValue
;
}
}
return
dictValue
.
get
<
T
>
(
idx
);
}
}
FlattenLayer
::
FlattenLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
FlattenLayer
::
FlattenLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
{
{
_startAxis
=
getParameter
<
int
>
(
params
,
"start_axis"
);
_startAxis
=
getParameter
<
int
>
(
params
,
"axis"
);
_endAxis
=
getParameter
<
int
>
(
params
,
"end_axis"
);
_endAxis
=
getParameter
<
int
>
(
params
,
"end_axis"
,
0
,
false
,
-
1
);
if
(
_endAxis
<=
0
)
{
_endAxis
+=
_numAxes
;
}
}
}
void
FlattenLayer
::
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
)
void
FlattenLayer
::
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
)
{
{
CV_Assert
(
inputs
.
size
()
>
0
);
CV_Assert
(
inputs
.
size
()
>
0
);
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
for
(
size_t
i
=
1
;
i
<
inputs
.
size
();
i
++
)
{
{
for
(
size_t
j
=
0
;
j
<
_numAxes
;
j
++
)
for
(
size_t
j
=
0
;
j
<
_numAxes
;
j
++
)
{
{
...
@@ -112,29 +114,31 @@ void FlattenLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
...
@@ -112,29 +114,31 @@ void FlattenLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
{
{
checkInputs
(
inputs
);
checkInputs
(
inputs
);
_numAxes
=
inputs
[
0
]
->
shape
().
dims
();
if
(
_endAxis
<=
0
)
{
_endAxis
+=
_numAxes
;
}
CV_Assert
(
_startAxis
>=
0
);
CV_Assert
(
_endAxis
>=
_startAxis
&&
_endAxis
<
(
int
)
_numAxes
);
size_t
flattenedDimensionSize
=
1
;
size_t
flattenedDimensionSize
=
1
;
for
(
int
i
=
_startAxis
;
i
<=
_endAxis
;
i
++
)
for
(
int
i
=
_startAxis
;
i
<=
_endAxis
;
i
++
)
{
{
flattenedDimensionSize
*=
inputs
[
0
]
->
shape
()[
i
];
flattenedDimensionSize
*=
inputs
[
0
]
->
shape
()[
i
];
}
}
BlobShape
outputShape
;
std
::
vector
<
int
>
outputShape
;
size_t
interval
=
_endAxis
-
_startAxis
;
for
(
int
i
=
0
;
i
<
_startAxis
;
i
++
)
// imitate flexible number of axes: make first dimension sizes = 1
for
(
size_t
i
=
0
;
i
<
interval
;
i
++
)
{
outputShape
[
i
]
=
1
;
}
for
(
int
i
=
interval
;
i
<
_endAxis
;
i
++
)
{
{
outputShape
[
i
]
=
inputs
[
0
]
->
shape
()[
i
-
interval
]
;
outputShape
.
push_back
(
inputs
[
0
]
->
shape
()[
i
])
;
}
}
outputShape
[
_endAxis
]
=
flattenedDimensionSize
;
outputShape
.
push_back
(
flattenedDimensionSize
)
;
for
(
size_t
i
=
_endAxis
+
1
;
i
<
_numAxes
;
i
++
)
for
(
size_t
i
=
_endAxis
+
1
;
i
<
_numAxes
;
i
++
)
{
{
outputShape
[
i
]
=
inputs
[
0
]
->
shape
()[
i
]
;
outputShape
.
push_back
(
inputs
[
0
]
->
shape
()[
i
])
;
}
}
CV_Assert
(
outputShape
.
size
()
<=
4
);
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
{
{
...
...
modules/dnn/src/layers/flatten_layer.hpp
View file @
355d07ec
...
@@ -49,10 +49,10 @@ namespace dnn
...
@@ -49,10 +49,10 @@ namespace dnn
{
{
class
FlattenLayer
:
public
Layer
class
FlattenLayer
:
public
Layer
{
{
size_
t
_startAxis
;
in
t
_startAxis
;
int
_endAxis
;
int
_endAxis
;
s
tatic
const
size_t
_numAxes
=
4
;
s
ize_t
_numAxes
;
static
const
std
::
string
_layerName
;
static
const
std
::
string
_layerName
;
public
:
public
:
...
@@ -63,11 +63,14 @@ public:
...
@@ -63,11 +63,14 @@ public:
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
template
<
typename
T
>
template
<
typename
T
>
T
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
T
getParameter
(
const
LayerParams
&
params
,
const
size_t
&
idx
=
0
);
const
std
::
string
&
parameterName
,
const
size_t
&
idx
=
0
,
const
bool
required
=
true
,
const
T
&
defaultValue
=
T
());
DictValue
getParameterDict
(
const
LayerParams
&
params
,
bool
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
);
const
std
::
string
&
parameterName
,
DictValue
&
result
);
};
};
}
}
}
}
...
...
modules/dnn/src/layers/layers_common.cpp
View file @
355d07ec
...
@@ -72,20 +72,21 @@ bool getParameter(LayerParams ¶ms, const std::string& nameBase, const std::s
...
@@ -72,20 +72,21 @@ bool getParameter(LayerParams ¶ms, const std::string& nameBase, const std::s
else
else
{
{
if
(
params
.
has
(
nameAll_
))
if
(
params
.
has
(
nameAll_
))
{
parameterH
=
parameterW
=
params
.
get
<
int
>
(
nameAll_
);
return
true
;
}
else
{
{
if
(
hasDefault
)
if
(
hasDefault
)
{
{
parameterH
=
parameterW
=
params
.
get
<
int
>
(
nameAll_
,
defaultValue
);
parameterH
=
parameterW
=
defaultValue
;
return
true
;
}
}
else
else
{
{
parameterH
=
parameterW
=
params
.
get
<
int
>
(
nameAll_
)
;
return
false
;
}
}
return
true
;
}
else
{
return
false
;
}
}
}
}
}
}
...
...
modules/dnn/src/layers/normalize_bbox_layer.cpp
View file @
355d07ec
...
@@ -54,43 +54,49 @@ namespace dnn
...
@@ -54,43 +54,49 @@ namespace dnn
const
std
::
string
NormalizeBBoxLayer
::
_layerName
=
std
::
string
(
"NormalizeBBox"
);
const
std
::
string
NormalizeBBoxLayer
::
_layerName
=
std
::
string
(
"NormalizeBBox"
);
DictValue
NormalizeBBoxLayer
::
getParameterDict
(
const
LayerParams
&
params
,
bool
NormalizeBBoxLayer
::
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
)
const
std
::
string
&
parameterName
,
DictValue
&
result
)
{
{
if
(
!
params
.
has
(
parameterName
))
if
(
!
params
.
has
(
parameterName
))
{
{
std
::
string
message
=
_layerName
;
return
false
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" index."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
}
DictValue
parameter
=
params
.
get
(
parameterName
);
result
=
params
.
get
(
parameterName
);
if
(
parameter
.
size
()
!=
1
)
return
true
;
{
std
::
string
message
=
parameterName
;
message
+=
" field in "
;
message
+=
_layerName
;
message
+=
" layer parameter is required"
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
return
parameter
;
}
}
template
<
typename
T
>
template
<
typename
T
>
T
NormalizeBBoxLayer
::
getParameter
(
const
LayerParams
&
params
,
T
NormalizeBBoxLayer
::
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
const
std
::
string
&
parameterName
,
const
size_t
&
idx
)
const
size_t
&
idx
,
const
bool
required
,
const
T
&
defaultValue
)
{
{
return
getParameterDict
(
params
,
parameterName
).
get
<
T
>
(
idx
);
DictValue
dictValue
;
bool
success
=
getParameterDict
(
params
,
parameterName
,
dictValue
);
if
(
!
success
)
{
if
(
required
)
{
std
::
string
message
=
_layerName
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" parameter."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
else
{
return
defaultValue
;
}
}
return
dictValue
.
get
<
T
>
(
idx
);
}
}
NormalizeBBoxLayer
::
NormalizeBBoxLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
NormalizeBBoxLayer
::
NormalizeBBoxLayer
(
LayerParams
&
params
)
:
Layer
(
params
)
{
{
_eps
=
getParameter
<
float
>
(
params
,
"eps"
);
_eps
=
getParameter
<
float
>
(
params
,
"eps"
,
0
,
false
,
1e-10
);
_across_spatial
=
getParameter
<
bool
>
(
params
,
"across_spatial"
);
_across_spatial
=
getParameter
<
bool
>
(
params
,
"across_spatial"
);
_channel_shared
=
getParameter
<
bool
>
(
params
,
"channel_shared"
);
_channel_shared
=
getParameter
<
bool
>
(
params
,
"channel_shared"
);
}
}
...
@@ -98,7 +104,7 @@ NormalizeBBoxLayer::NormalizeBBoxLayer(LayerParams ¶ms) : Layer(params)
...
@@ -98,7 +104,7 @@ NormalizeBBoxLayer::NormalizeBBoxLayer(LayerParams ¶ms) : Layer(params)
void
NormalizeBBoxLayer
::
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
)
void
NormalizeBBoxLayer
::
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
)
{
{
CV_Assert
(
inputs
.
size
()
>
0
);
CV_Assert
(
inputs
.
size
()
>
0
);
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
for
(
size_t
i
=
1
;
i
<
inputs
.
size
();
i
++
)
{
{
for
(
size_t
j
=
0
;
j
<
_numAxes
;
j
++
)
for
(
size_t
j
=
0
;
j
<
_numAxes
;
j
++
)
{
{
...
...
modules/dnn/src/layers/normalize_bbox_layer.hpp
View file @
355d07ec
...
@@ -82,11 +82,15 @@ public:
...
@@ -82,11 +82,15 @@ public:
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
void
checkInputs
(
const
std
::
vector
<
Blob
*>
&
inputs
);
template
<
typename
T
>
template
<
typename
T
>
T
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
T
getParameter
(
const
LayerParams
&
params
,
const
size_t
&
idx
=
0
);
const
std
::
string
&
parameterName
,
const
size_t
&
idx
=
0
,
const
bool
required
=
true
,
const
T
&
defaultValue
=
T
());
DictValue
getParameterDict
(
const
LayerParams
&
params
,
bool
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
);
const
std
::
string
&
parameterName
,
DictValue
&
result
);
};
};
}
}
}
}
...
...
modules/dnn/src/layers/prior_box_layer.cpp
View file @
355d07ec
...
@@ -53,42 +53,52 @@ namespace dnn
...
@@ -53,42 +53,52 @@ namespace dnn
const
std
::
string
PriorBoxLayer
::
_layerName
=
std
::
string
(
"PriorBox"
);
const
std
::
string
PriorBoxLayer
::
_layerName
=
std
::
string
(
"PriorBox"
);
DictValue
PriorBoxLayer
::
getParameterDict
(
const
LayerParams
&
params
,
bool
PriorBoxLayer
::
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
)
const
std
::
string
&
parameterName
,
DictValue
&
result
)
{
{
if
(
!
params
.
has
(
parameterName
))
if
(
!
params
.
has
(
parameterName
))
{
{
std
::
string
message
=
_layerName
;
return
false
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" index."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
}
DictValue
parameter
=
params
.
get
(
parameterName
);
result
=
params
.
get
(
parameterName
);
if
(
parameter
.
size
()
!=
1
)
return
true
;
{
std
::
string
message
=
parameterName
;
message
+=
" field in "
;
message
+=
_layerName
;
message
+=
" layer parameter is required"
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
return
parameter
;
}
}
template
<
typename
T
>
template
<
typename
T
>
T
PriorBoxLayer
::
getParameter
(
const
LayerParams
&
params
,
T
PriorBoxLayer
::
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
const
std
::
string
&
parameterName
,
const
size_t
&
idx
)
const
size_t
&
idx
,
const
bool
required
,
const
T
&
defaultValue
)
{
{
return
getParameterDict
(
params
,
parameterName
).
get
<
T
>
(
idx
);
DictValue
dictValue
;
bool
success
=
getParameterDict
(
params
,
parameterName
,
dictValue
);
if
(
!
success
)
{
if
(
required
)
{
std
::
string
message
=
_layerName
;
message
+=
" layer parameter does not contain "
;
message
+=
parameterName
;
message
+=
" parameter."
;
CV_Error
(
Error
::
StsBadArg
,
message
);
}
else
{
return
defaultValue
;
}
}
return
dictValue
.
get
<
T
>
(
idx
);
}
}
void
PriorBoxLayer
::
getAspectRatios
(
const
LayerParams
&
params
)
void
PriorBoxLayer
::
getAspectRatios
(
const
LayerParams
&
params
)
{
{
DictValue
aspectRatioParameter
=
getParameterDict
(
params
,
"aspect_ratio"
);
DictValue
aspectRatioParameter
;
bool
aspectRatioRetieved
=
getParameterDict
(
params
,
"aspect_ratio"
,
aspectRatioParameter
);
CV_Assert
(
aspectRatioRetieved
);
for
(
int
i
=
0
;
i
<
aspectRatioParameter
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
aspectRatioParameter
.
size
();
++
i
)
{
{
float
aspectRatio
=
aspectRatioParameter
.
get
<
float
>
(
i
);
float
aspectRatio
=
aspectRatioParameter
.
get
<
float
>
(
i
);
...
@@ -115,7 +125,10 @@ void PriorBoxLayer::getAspectRatios(const LayerParams ¶ms)
...
@@ -115,7 +125,10 @@ void PriorBoxLayer::getAspectRatios(const LayerParams ¶ms)
void
PriorBoxLayer
::
getVariance
(
const
LayerParams
&
params
)
void
PriorBoxLayer
::
getVariance
(
const
LayerParams
&
params
)
{
{
DictValue
varianceParameter
=
getParameterDict
(
params
,
"variance"
);
DictValue
varianceParameter
;
bool
varianceParameterRetrieved
=
getParameterDict
(
params
,
"variance"
,
varianceParameter
);
CV_Assert
(
varianceParameterRetrieved
);
int
varianceSize
=
varianceParameter
.
size
();
int
varianceSize
=
varianceParameter
.
size
();
if
(
varianceSize
>
1
)
if
(
varianceSize
>
1
)
{
{
...
@@ -190,12 +203,9 @@ void PriorBoxLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
...
@@ -190,12 +203,9 @@ void PriorBoxLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
// 2 channels. First channel stores the mean of each prior coordinate.
// 2 channels. First channel stores the mean of each prior coordinate.
// Second channel stores the variance of each prior coordinate.
// Second channel stores the variance of each prior coordinate.
size_t
outChannels
=
2
;
size_t
outChannels
=
2
;
size_t
outHeight
=
_layerHeight
;
size_t
outWidth
=
_layerWidth
*
_numPriors
*
4
;
_outChannelSize
=
_layerHeight
*
_layerWidth
*
_numPriors
*
4
;
_outChannelSize
=
_layerHeight
*
_layerWidth
*
_numPriors
*
4
;
outputs
[
0
].
create
(
BlobShape
(
outNum
,
outChannels
,
outHeight
,
outWidth
));
outputs
[
0
].
create
(
BlobShape
(
outNum
,
outChannels
,
_outChannelSize
));
}
}
void
PriorBoxLayer
::
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
)
void
PriorBoxLayer
::
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
)
...
...
modules/dnn/src/layers/prior_box_layer.hpp
View file @
355d07ec
...
@@ -83,11 +83,15 @@ public:
...
@@ -83,11 +83,15 @@ public:
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
template
<
typename
T
>
template
<
typename
T
>
T
getParameter
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
,
T
getParameter
(
const
LayerParams
&
params
,
const
size_t
&
idx
=
0
);
const
std
::
string
&
parameterName
,
const
size_t
&
idx
=
0
,
const
bool
required
=
true
,
const
T
&
defaultValue
=
T
());
DictValue
getParameterDict
(
const
LayerParams
&
params
,
bool
getParameterDict
(
const
LayerParams
&
params
,
const
std
::
string
&
parameterName
);
const
std
::
string
&
parameterName
,
DictValue
&
result
);
void
getAspectRatios
(
const
LayerParams
&
params
);
void
getAspectRatios
(
const
LayerParams
&
params
);
void
getVariance
(
const
LayerParams
&
params
);
void
getVariance
(
const
LayerParams
&
params
);
...
...
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