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
d392375c
Commit
d392375c
authored
Jul 21, 2016
by
Anna Petrovicheva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed NormalizeBBox layer
parent
80d35faf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
55 deletions
+33
-55
normalize_bbox_layer.cpp
modules/dnn/src/layers/normalize_bbox_layer.cpp
+30
-49
normalize_bbox_layer.hpp
modules/dnn/src/layers/normalize_bbox_layer.hpp
+3
-6
No files found.
modules/dnn/src/layers/normalize_bbox_layer.cpp
View file @
d392375c
...
...
@@ -126,36 +126,12 @@ void NormalizeBBoxLayer::allocate(const std::vector<Blob*> &inputs, std::vector<
_channelSize
=
_rows
*
_cols
;
_imageSize
=
_channelSize
*
_channels
;
_buffer
=
Blob
(
BlobShape
(
1
,
_channels
,
_rows
,
_cols
));
_buffer_channel
=
Blob
(
BlobShape
(
1
,
_channels
,
1
,
1
));
_buffer_spatial
=
Blob
(
BlobShape
(
1
,
1
,
_rows
,
_cols
));
_buffer
=
Mat
(
_channels
,
_channelSize
,
CV_32F
);
if
(
_across_spatial
)
{
_norm
=
Blob
(
BlobShape
(
_num
,
1
,
1
,
1
));
}
else
{
_norm
=
Blob
(
BlobShape
(
_num
,
1
,
_rows
,
_cols
));
}
// add eps to avoid overflow
_norm
.
matRef
()
=
Scalar
(
_eps
);
_sumChannelMultiplier
=
Mat
(
_channels
,
1
,
CV_32F
,
Scalar
(
1.0
));
_sumSpatialMultiplier
=
Mat
(
1
,
_channelSize
,
CV_32F
,
Scalar
(
1.0
));
_sumChannelMultiplier
=
Blob
(
BlobShape
(
1
,
_channels
,
1
,
1
));
_sumChannelMultiplier
.
matRef
()
=
Scalar
(
1.0
);
_sumSpatialMultiplier
=
Blob
(
BlobShape
(
1
,
1
,
_rows
,
_cols
));
_sumSpatialMultiplier
.
matRef
()
=
Scalar
(
1.0
);
if
(
_channel_shared
)
{
_scale
=
Blob
(
BlobShape
(
1
,
1
,
1
,
1
));
}
else
{
_scale
=
Blob
(
BlobShape
(
1
,
1
,
1
,
_channels
));
}
_scale
=
blobs
[
0
];
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
{
...
...
@@ -165,54 +141,59 @@ void NormalizeBBoxLayer::allocate(const std::vector<Blob*> &inputs, std::vector<
void
NormalizeBBoxLayer
::
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
)
{
Mat
zeroBuffer
=
Mat
(
_buffer
.
matRef
().
rows
,
_buffer
.
matRef
().
cols
,
_buffer
.
matRef
().
type
(),
Scalar
(
0
));
Mat
sumAbs
;
Mat
zeroBuffer
(
_channels
,
_channelSize
,
CV_32F
,
Scalar
(
0
));
Mat
absDiff
;
for
(
size_t
j
=
0
;
j
<
inputs
.
size
();
j
++
)
{
for
(
size_t
n
=
0
;
n
<
_num
;
++
n
)
{
Mat
src
=
inputs
[
j
]
->
getPlanes
(
n
);
Mat
dst
=
outputs
[
j
].
getPlanes
(
n
);
Mat
src
=
Mat
(
_channels
,
_channelSize
,
CV_32F
,
inputs
[
j
]
->
ptrf
(
n
)
);
Mat
dst
=
Mat
(
_channels
,
_channelSize
,
CV_32F
,
outputs
[
j
].
ptrf
(
n
)
);
Mat
normCurrent
=
_norm
.
getPlanes
(
n
);
cv
::
sqrt
(
src
,
_buffer
.
matRef
());
_buffer
=
src
.
mul
(
src
);
if
(
_across_spatial
)
{
absdiff
(
_buffer
.
matRef
(),
zeroBuffer
,
sumAbs
);
// add eps to avoid overflow
sumAbs
+=
_eps
;
absdiff
(
_buffer
,
zeroBuffer
,
absDiff
);
pow
(
sumAbs
,
0.5
f
,
normCurrent
);
// add eps to avoid overflow
double
absSum
=
sum
(
absDiff
)[
0
]
+
_eps
;
dst
=
src
/
normCurrent
;
float
norm
=
sqrt
(
absSum
);
dst
=
src
/
norm
;
}
else
{
gemmCPU
(
_buffer
.
matRef
(),
_sumChannelMultiplier
.
matRef
(),
1
,
normCurrent
,
GEMM_1_T
&
GEMM_2_T
);
Mat
norm
;
// 1 x _channelSize
// (_channels x_channelSize)T * _channels x 1 -> _channelSize x 1
gemmCPU
(
_buffer
,
_sumChannelMultiplier
,
1
,
norm
,
0
,
GEMM_1_T
);
// compute norm
pow
(
norm
Current
,
0.5
f
,
normCurrent
);
pow
(
norm
,
0.5
f
,
norm
);
// scale the layer
gemmCPU
(
_sumChannelMultiplier
.
matRef
(),
normCurrent
,
1
,
_buffer
.
matRef
(),
0
);
// _channels x 1 * (_channelSize x 1)T -> _channels x _channelSize
gemmCPU
(
_sumChannelMultiplier
,
norm
,
1
,
_buffer
,
0
,
GEMM_2_T
);
dst
=
src
/
_buffer
.
matRef
().
at
<
float
>
(
0
,
0
)
;
dst
=
src
/
_buffer
;
}
// scale the output
if
(
_channel_shared
)
{
dst
*=
_scale
.
matRef
();
// _scale: 1 x 1
dst
*=
_scale
.
matRef
().
at
<
float
>
(
0
,
0
);
}
else
{
gemmCPU
(
_scale
.
matRef
(),
_sumSpatialMultiplier
.
matRef
(),
1
,
_buffer
.
matRef
(),
0
);
dst
*=
_buffer
.
matRef
();
}
// _scale: _channels x 1
// _channels x 1 * 1 x _channelSize -> _channels x _channelSize
gemmCPU
(
_scale
.
matRef
(),
_sumSpatialMultiplier
,
1
,
_buffer
,
0
);
dst
=
dst
.
mul
(
_buffer
);
}
}
}
}
...
...
modules/dnn/src/layers/normalize_bbox_layer.hpp
View file @
d392375c
...
...
@@ -49,13 +49,10 @@ namespace dnn
{
class
NormalizeBBoxLayer
:
public
Layer
{
Blob
_buffer
;
Blob
_buffer_channel
;
Blob
_buffer_spatial
;
Mat
_buffer
;
Blob
_norm
;
Blob
_sumChannelMultiplier
;
Blob
_sumSpatialMultiplier
;
Mat
_sumChannelMultiplier
;
Mat
_sumSpatialMultiplier
;
Blob
_scale
;
...
...
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