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
32036357
Commit
32036357
authored
Jul 10, 2017
by
dkurt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Eltwise layer fixes
parent
cddf8685
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
12 deletions
+25
-12
eltwise_layer.cpp
modules/dnn/src/layers/eltwise_layer.cpp
+9
-9
layers_common.cpp
modules/dnn/src/layers/layers_common.cpp
+2
-1
test_halide_layers.cpp
modules/dnn/test/test_halide_layers.cpp
+14
-2
No files found.
modules/dnn/src/layers/eltwise_layer.cpp
View file @
32036357
...
@@ -53,7 +53,7 @@ class EltwiseLayerImpl : public EltwiseLayer
...
@@ -53,7 +53,7 @@ class EltwiseLayerImpl : public EltwiseLayer
{
{
public
:
public
:
EltwiseOp
op
;
EltwiseOp
op
;
std
::
vector
<
in
t
>
coeffs
;
std
::
vector
<
floa
t
>
coeffs
;
EltwiseLayerImpl
(
const
LayerParams
&
params
)
EltwiseLayerImpl
(
const
LayerParams
&
params
)
{
{
...
@@ -79,7 +79,7 @@ public:
...
@@ -79,7 +79,7 @@ public:
coeffs
.
resize
(
n
);
coeffs
.
resize
(
n
);
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
n
;
i
++
)
{
{
coeffs
[
i
]
=
paramCoeff
.
get
<
in
t
>
(
i
);
coeffs
[
i
]
=
paramCoeff
.
get
<
floa
t
>
(
i
);
}
}
}
}
}
}
...
@@ -115,7 +115,7 @@ public:
...
@@ -115,7 +115,7 @@ public:
const
Mat
**
srcs
;
const
Mat
**
srcs
;
int
nsrcs
;
int
nsrcs
;
Mat
*
dst
;
Mat
*
dst
;
const
std
::
vector
<
in
t
>*
coeffs
;
const
std
::
vector
<
floa
t
>*
coeffs
;
EltwiseOp
op
;
EltwiseOp
op
;
int
nstripes
;
int
nstripes
;
const
ActivationLayer
*
activ
;
const
ActivationLayer
*
activ
;
...
@@ -123,7 +123,7 @@ public:
...
@@ -123,7 +123,7 @@ public:
EltwiseInvoker
()
:
srcs
(
0
),
nsrcs
(
0
),
dst
(
0
),
coeffs
(
0
),
op
(
EltwiseLayer
::
PROD
),
nstripes
(
0
),
activ
(
0
)
{}
EltwiseInvoker
()
:
srcs
(
0
),
nsrcs
(
0
),
dst
(
0
),
coeffs
(
0
),
op
(
EltwiseLayer
::
PROD
),
nstripes
(
0
),
activ
(
0
)
{}
static
void
run
(
const
Mat
**
srcs
,
int
nsrcs
,
Mat
&
dst
,
static
void
run
(
const
Mat
**
srcs
,
int
nsrcs
,
Mat
&
dst
,
const
std
::
vector
<
in
t
>&
coeffs
,
EltwiseOp
op
,
const
std
::
vector
<
floa
t
>&
coeffs
,
EltwiseOp
op
,
const
ActivationLayer
*
activ
,
int
nstripes
)
const
ActivationLayer
*
activ
,
int
nstripes
)
{
{
CV_Assert
(
dst
.
dims
==
4
&&
dst
.
type
()
==
CV_32F
&&
dst
.
isContinuous
());
CV_Assert
(
dst
.
dims
==
4
&&
dst
.
type
()
==
CV_32F
&&
dst
.
isContinuous
());
...
@@ -143,7 +143,7 @@ public:
...
@@ -143,7 +143,7 @@ public:
p
.
op
=
op
;
p
.
op
=
op
;
p
.
nstripes
=
nstripes
;
p
.
nstripes
=
nstripes
;
bool
simpleCoeffs
=
true
;
bool
simpleCoeffs
=
true
;
if
(
op
!
=
EltwiseLayer
::
SUM
&&
!
coeffs
.
empty
()
)
if
(
op
=
=
EltwiseLayer
::
SUM
&&
!
coeffs
.
empty
()
)
{
{
CV_Assert
(
coeffs
.
size
()
==
(
size_t
)
nsrcs
);
CV_Assert
(
coeffs
.
size
()
==
(
size_t
)
nsrcs
);
...
@@ -169,7 +169,7 @@ public:
...
@@ -169,7 +169,7 @@ public:
size_t
stripeEnd
=
std
::
min
(
r
.
end
*
stripeSize
,
total
);
size_t
stripeEnd
=
std
::
min
(
r
.
end
*
stripeSize
,
total
);
int
c
,
j
,
k
,
n
=
nsrcs
;
int
c
,
j
,
k
,
n
=
nsrcs
;
int
channels
=
dst
->
size
[
1
];
int
channels
=
dst
->
size
[
1
];
const
in
t
*
coeffsptr
=
coeffs
&&
!
coeffs
->
empty
()
?
&
coeffs
->
at
(
0
)
:
0
;
const
floa
t
*
coeffsptr
=
coeffs
&&
!
coeffs
->
empty
()
?
&
coeffs
->
at
(
0
)
:
0
;
float
*
dstptr0
=
dst
->
ptr
<
float
>
();
float
*
dstptr0
=
dst
->
ptr
<
float
>
();
int
blockSize0
=
1
<<
12
,
blockSize
=
blockSize0
;
int
blockSize0
=
1
<<
12
,
blockSize
=
blockSize0
;
...
@@ -203,7 +203,7 @@ public:
...
@@ -203,7 +203,7 @@ public:
{
{
for
(
k
=
1
;
k
<
n
;
k
++
)
for
(
k
=
1
;
k
<
n
;
k
++
)
{
{
const
float
*
srcptr1
=
srcs
[
0
]
->
ptr
<
float
>
()
+
globalDelta
;
const
float
*
srcptr1
=
srcs
[
k
]
->
ptr
<
float
>
()
+
globalDelta
;
for
(
j
=
0
;
j
<
blockSize
;
j
++
)
for
(
j
=
0
;
j
<
blockSize
;
j
++
)
{
{
dstptr
[
j
]
=
std
::
max
(
srcptr0
[
j
],
srcptr1
[
j
]);
dstptr
[
j
]
=
std
::
max
(
srcptr0
[
j
],
srcptr1
[
j
]);
...
@@ -225,11 +225,11 @@ public:
...
@@ -225,11 +225,11 @@ public:
}
}
else
else
{
{
in
t
c0
=
coeffsptr
[
0
];
floa
t
c0
=
coeffsptr
[
0
];
for
(
k
=
1
;
k
<
n
;
k
++
)
for
(
k
=
1
;
k
<
n
;
k
++
)
{
{
const
float
*
srcptr1
=
srcs
[
k
]
->
ptr
<
float
>
()
+
globalDelta
;
const
float
*
srcptr1
=
srcs
[
k
]
->
ptr
<
float
>
()
+
globalDelta
;
in
t
c1
=
coeffsptr
[
k
];
floa
t
c1
=
coeffsptr
[
k
];
for
(
j
=
0
;
j
<
blockSize
;
j
++
)
for
(
j
=
0
;
j
<
blockSize
;
j
++
)
{
{
dstptr
[
j
]
=
c0
*
srcptr0
[
j
]
+
c1
*
srcptr1
[
j
];
dstptr
[
j
]
=
c0
*
srcptr0
[
j
]
+
c1
*
srcptr1
[
j
];
...
...
modules/dnn/src/layers/layers_common.cpp
View file @
32036357
...
@@ -125,7 +125,8 @@ void getPoolingKernelParams(const LayerParams ¶ms, int &kernelH, int &kernel
...
@@ -125,7 +125,8 @@ void getPoolingKernelParams(const LayerParams ¶ms, int &kernelH, int &kernel
{
{
util
::
getStrideAndPadding
(
params
,
padH
,
padW
,
strideH
,
strideW
,
padMode
);
util
::
getStrideAndPadding
(
params
,
padH
,
padW
,
strideH
,
strideW
,
padMode
);
globalPooling
=
params
.
has
(
"global_pooling"
);
globalPooling
=
params
.
has
(
"global_pooling"
)
&&
params
.
get
<
bool
>
(
"global_pooling"
);
if
(
globalPooling
)
if
(
globalPooling
)
{
{
...
...
modules/dnn/test/test_halide_layers.cpp
View file @
32036357
...
@@ -575,12 +575,13 @@ INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Concat, Combine(
...
@@ -575,12 +575,13 @@ INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Concat, Combine(
// `--- conv ----^ ^ ^
// `--- conv ----^ ^ ^
// `---- ... ------' '
// `---- ... ------' '
// `-----------------'
// `-----------------'
typedef
TestWithParam
<
tuple
<
Vec3i
,
std
::
string
,
int
>
>
Eltwise
;
typedef
TestWithParam
<
tuple
<
Vec3i
,
std
::
string
,
int
,
bool
>
>
Eltwise
;
TEST_P
(
Eltwise
,
Accuracy
)
TEST_P
(
Eltwise
,
Accuracy
)
{
{
Vec3i
inSize
=
get
<
0
>
(
GetParam
());
Vec3i
inSize
=
get
<
0
>
(
GetParam
());
std
::
string
op
=
get
<
1
>
(
GetParam
());
std
::
string
op
=
get
<
1
>
(
GetParam
());
int
numConv
=
get
<
2
>
(
GetParam
());
int
numConv
=
get
<
2
>
(
GetParam
());
bool
weighted
=
get
<
3
>
(
GetParam
());
Net
net
;
Net
net
;
...
@@ -606,6 +607,16 @@ TEST_P(Eltwise, Accuracy)
...
@@ -606,6 +607,16 @@ TEST_P(Eltwise, Accuracy)
}
}
LayerParams
eltwiseParam
;
LayerParams
eltwiseParam
;
eltwiseParam
.
set
(
"operation"
,
op
);
if
(
op
==
"sum"
&&
weighted
)
{
std
::
vector
<
float
>
coeff
(
1
+
numConv
);
for
(
int
i
=
0
;
i
<
coeff
.
size
();
++
i
)
{
coeff
[
i
]
=
((
float
)
rand
()
/
RAND_MAX
)
*
4
-
2
;
}
eltwiseParam
.
set
(
"coeff"
,
DictValue
::
arrayReal
<
float
*>
(
&
coeff
[
0
],
coeff
.
size
()));
}
eltwiseParam
.
type
=
"Eltwise"
;
eltwiseParam
.
type
=
"Eltwise"
;
eltwiseParam
.
name
=
"testLayer"
;
eltwiseParam
.
name
=
"testLayer"
;
int
eltwiseId
=
net
.
addLayer
(
eltwiseParam
.
name
,
eltwiseParam
.
type
,
eltwiseParam
);
int
eltwiseId
=
net
.
addLayer
(
eltwiseParam
.
name
,
eltwiseParam
.
type
,
eltwiseParam
);
...
@@ -629,7 +640,8 @@ TEST_P(Eltwise, Accuracy)
...
@@ -629,7 +640,8 @@ TEST_P(Eltwise, Accuracy)
INSTANTIATE_TEST_CASE_P
(
Layer_Test_Halide
,
Eltwise
,
Combine
(
INSTANTIATE_TEST_CASE_P
(
Layer_Test_Halide
,
Eltwise
,
Combine
(
/*input size*/
Values
(
Vec3i
(
1
,
4
,
5
),
Vec3i
(
2
,
8
,
6
)),
/*input size*/
Values
(
Vec3i
(
1
,
4
,
5
),
Vec3i
(
2
,
8
,
6
)),
/*operation*/
Values
(
"prod"
,
"sum"
,
"max"
),
/*operation*/
Values
(
"prod"
,
"sum"
,
"max"
),
/*num convs*/
Values
(
1
,
2
,
3
)
/*num convs*/
Values
(
1
,
2
,
3
),
/*weighted(for sum only)*/
Bool
()
));
));
#endif // HAVE_HALIDE
#endif // HAVE_HALIDE
...
...
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