Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenCV
opencv
提交
dad2b9aa
O
opencv
项目概览
OpenCV
/
opencv
上一次同步 大约 1 年
通知
1005
Star
71102
Fork
55580
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dad2b9aa
编写于
12月 02, 2021
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21160 from rogday:elu_alpha
上级
1613d305
0e2a3686
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
6 deletion
+19
-6
modules/dnn/include/opencv2/dnn/all_layers.hpp
modules/dnn/include/opencv2/dnn/all_layers.hpp
+2
-0
modules/dnn/src/layers/elementwise_layers.cpp
modules/dnn/src/layers/elementwise_layers.cpp
+14
-4
modules/dnn/src/opencl/activations.cl
modules/dnn/src/opencl/activations.cl
+3
-2
未找到文件。
modules/dnn/include/opencv2/dnn/all_layers.hpp
浏览文件 @
dad2b9aa
...
...
@@ -453,6 +453,8 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
class
CV_EXPORTS
ELULayer
:
public
ActivationLayer
{
public:
float
alpha
;
static
Ptr
<
ELULayer
>
create
(
const
LayerParams
&
params
);
};
...
...
modules/dnn/src/layers/elementwise_layers.cpp
浏览文件 @
dad2b9aa
...
...
@@ -740,6 +740,9 @@ const char* const SigmoidFunctor::BaseDefaultFunctor<SigmoidFunctor>::ocl_kernel
struct
ELUFunctor
:
public
BaseDefaultFunctor
<
ELUFunctor
>
{
typedef
ELULayer
Layer
;
float
alpha
;
explicit
ELUFunctor
(
float
alpha_
=
1.
f
)
:
alpha
(
alpha_
)
{}
bool
supportBackend
(
int
backendId
,
int
)
{
...
...
@@ -749,14 +752,19 @@ struct ELUFunctor : public BaseDefaultFunctor<ELUFunctor>
inline
float
calculate
(
float
x
)
const
{
return
x
>=
0.
f
?
x
:
exp
(
x
)
-
1.
f
;
return
x
>=
0.
f
?
x
:
alpha
*
(
exp
(
x
)
-
1.
f
);
}
inline
void
setKernelParams
(
ocl
::
Kernel
&
kernel
)
const
{
kernel
.
set
(
3
,
alpha
);
}
#ifdef HAVE_HALIDE
void
attachHalide
(
const
Halide
::
Expr
&
input
,
Halide
::
Func
&
top
)
{
Halide
::
Var
x
(
"x"
),
y
(
"y"
),
c
(
"c"
),
n
(
"n"
);
top
(
x
,
y
,
c
,
n
)
=
select
(
input
>=
0.0
f
,
input
,
exp
(
input
)
-
1
);
top
(
x
,
y
,
c
,
n
)
=
select
(
input
>=
0.0
f
,
input
,
alpha
*
(
exp
(
input
)
-
1
)
);
}
#endif // HAVE_HALIDE
...
...
@@ -770,7 +778,7 @@ struct ELUFunctor : public BaseDefaultFunctor<ELUFunctor>
#ifdef HAVE_DNN_NGRAPH
std
::
shared_ptr
<
ngraph
::
Node
>
initNgraphAPI
(
const
std
::
shared_ptr
<
ngraph
::
Node
>&
node
)
{
return
std
::
make_shared
<
ngraph
::
op
::
Elu
>
(
node
,
1.0
);
return
std
::
make_shared
<
ngraph
::
op
::
Elu
>
(
node
,
alpha
);
}
#endif // HAVE_DNN_NGRAPH
...
...
@@ -1263,8 +1271,10 @@ Ptr<SigmoidLayer> SigmoidLayer::create(const LayerParams& params)
Ptr
<
ELULayer
>
ELULayer
::
create
(
const
LayerParams
&
params
)
{
Ptr
<
ELULayer
>
l
(
new
ElementWiseLayer
<
ELUFunctor
>
(
ELUFunctor
()));
float
alpha
=
params
.
get
<
float
>
(
"alpha"
,
1.0
f
);
Ptr
<
ELULayer
>
l
(
new
ElementWiseLayer
<
ELUFunctor
>
(
ELUFunctor
(
alpha
)));
l
->
setParamsFrom
(
params
);
l
->
alpha
=
alpha
;
return
l
;
}
...
...
modules/dnn/src/opencl/activations.cl
浏览文件 @
dad2b9aa
...
...
@@ -131,13 +131,14 @@ __kernel void PowForward(const int n, __global const T* in, __global T* out,
out[index]
=
pow
(
shift
+
scale
*
in[index],
power
)
;
}
__kernel
void
ELUForward
(
const
int
n,
__global
const
T*
in,
__global
T*
out
)
__kernel
void
ELUForward
(
const
int
n,
__global
const
T*
in,
__global
T*
out,
const
KERNEL_ARG_DTYPE
alpha
)
{
int
index
=
get_global_id
(
0
)
;
if
(
index
<
n
)
{
T
src
=
in[index]
;
out[index]
=
(
src
>=
0.f
)
?
src
:
exp
(
src
)
-
1
;
out[index]
=
(
src
>=
0.f
)
?
src
:
alpha
*
(
exp
(
src
)
-
1
)
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录