Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
96947c30
O
Opencv
项目概览
Greenplum
/
Opencv
12 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
96947c30
编写于
2月 20, 2021
作者:
S
SamFC10
提交者:
Alexander Alekhin
2月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added exp layer
backport of commit:
61119358
partial backport of commit:
dd597616
上级
19f1bac1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
173 addition
and
2 deletion
+173
-2
modules/dnn/include/opencv2/dnn/all_layers.hpp
modules/dnn/include/opencv2/dnn/all_layers.hpp
+8
-0
modules/dnn/src/init.cpp
modules/dnn/src/init.cpp
+1
-0
modules/dnn/src/layers/elementwise_layers.cpp
modules/dnn/src/layers/elementwise_layers.cpp
+113
-0
modules/dnn/src/opencl/activations.cl
modules/dnn/src/opencl/activations.cl
+11
-0
modules/dnn/src/tensorflow/tf_importer.cpp
modules/dnn/src/tensorflow/tf_importer.cpp
+1
-1
modules/dnn/test/test_halide_layers.cpp
modules/dnn/test/test_halide_layers.cpp
+25
-0
modules/dnn/test/test_layers.cpp
modules/dnn/test/test_layers.cpp
+7
-1
modules/dnn/test/test_onnx_importer.cpp
modules/dnn/test/test_onnx_importer.cpp
+7
-0
未找到文件。
modules/dnn/include/opencv2/dnn/all_layers.hpp
浏览文件 @
96947c30
...
...
@@ -499,6 +499,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
static
Ptr
<
PowerLayer
>
create
(
const
LayerParams
&
params
);
};
class
CV_EXPORTS
ExpLayer
:
public
ActivationLayer
{
public:
float
base
,
scale
,
shift
;
static
Ptr
<
ExpLayer
>
create
(
const
LayerParams
&
params
);
};
/* Layers used in semantic segmentation */
class
CV_EXPORTS
CropLayer
:
public
Layer
...
...
modules/dnn/src/init.cpp
浏览文件 @
96947c30
...
...
@@ -110,6 +110,7 @@ void initializeLayerFactory()
CV_DNN_REGISTER_LAYER_CLASS
(
BNLL
,
BNLLLayer
);
CV_DNN_REGISTER_LAYER_CLASS
(
AbsVal
,
AbsLayer
);
CV_DNN_REGISTER_LAYER_CLASS
(
Power
,
PowerLayer
);
CV_DNN_REGISTER_LAYER_CLASS
(
Exp
,
ExpLayer
);
CV_DNN_REGISTER_LAYER_CLASS
(
BatchNorm
,
BatchNormLayer
);
CV_DNN_REGISTER_LAYER_CLASS
(
MaxUnpool
,
MaxUnpoolLayer
);
CV_DNN_REGISTER_LAYER_CLASS
(
Dropout
,
BlankLayer
);
...
...
modules/dnn/src/layers/elementwise_layers.cpp
浏览文件 @
96947c30
...
...
@@ -1202,6 +1202,105 @@ struct PowerFunctor : public BaseFunctor
int64
getFLOPSPerElement
()
const
{
return
power
==
1
?
2
:
10
;
}
};
struct
ExpFunctor
:
public
BaseFunctor
{
typedef
ExpLayer
Layer
;
float
base
,
scale
,
shift
;
float
normScale
,
normShift
;
ExpFunctor
(
float
base_
=
-
1.
f
,
float
scale_
=
1.
f
,
float
shift_
=
0.
f
)
:
base
(
base_
),
scale
(
scale_
),
shift
(
shift_
)
{
// For base > 0 :
// y = base^(scale * input + shift)
// ln(y) = ln(base)*(scale * input + shift)
// y = exp((ln(base)*scale) * input + (ln(base)*shift))
// y = exp(normalized_scale * input + normalized_shift)
CV_Check
(
base
,
base
==
-
1.
f
||
base
>
0.
f
,
"Unsupported 'base' value"
);
const
float
ln_base
=
(
base
==
-
1.
f
)
?
1.
f
:
log
(
base
);
normScale
=
scale
*
ln_base
;
normShift
=
shift
*
ln_base
;
}
bool
supportBackend
(
int
backendId
,
int
targetId
)
{
return
backendId
==
DNN_BACKEND_OPENCV
||
backendId
==
DNN_BACKEND_HALIDE
||
backendId
==
DNN_BACKEND_INFERENCE_ENGINE_NGRAPH
;
}
void
apply
(
const
float
*
srcptr
,
float
*
dstptr
,
int
len
,
size_t
planeSize
,
int
cn0
,
int
cn1
)
const
{
float
a
=
normScale
,
b
=
normShift
;
for
(
int
cn
=
cn0
;
cn
<
cn1
;
cn
++
,
srcptr
+=
planeSize
,
dstptr
+=
planeSize
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
float
x
=
srcptr
[
i
];
dstptr
[
i
]
=
exp
(
a
*
x
+
b
);
}
}
}
#ifdef HAVE_OPENCL
bool
applyOCL
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
OutputArrayOfArrays
internals
)
{
std
::
vector
<
UMat
>
inputs
;
std
::
vector
<
UMat
>
outputs
;
inps
.
getUMatVector
(
inputs
);
outs
.
getUMatVector
(
outputs
);
String
buildopt
=
oclGetTMacro
(
inputs
[
0
]);
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
{
UMat
&
src
=
inputs
[
i
];
UMat
&
dst
=
outputs
[
i
];
ocl
::
Kernel
kernel
(
"ExpForward"
,
ocl
::
dnn
::
activations_oclsrc
,
buildopt
);
kernel
.
set
(
0
,
(
int
)
src
.
total
());
kernel
.
set
(
1
,
ocl
::
KernelArg
::
PtrReadOnly
(
src
));
kernel
.
set
(
2
,
ocl
::
KernelArg
::
PtrWriteOnly
(
dst
));
kernel
.
set
(
3
,
(
float
)
normScale
);
kernel
.
set
(
4
,
(
float
)
normShift
);
size_t
gSize
=
src
.
total
();
CV_Assert
(
kernel
.
run
(
1
,
&
gSize
,
NULL
,
false
));
}
return
true
;
}
#endif
#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
)
=
exp
(
normScale
*
input
+
normShift
);
}
#endif // HAVE_HALIDE
#ifdef HAVE_DNN_IE_NN_BUILDER_2019
InferenceEngine
::
Builder
::
Layer
initInfEngineBuilderAPI
()
{
CV_Error
(
Error
::
StsNotImplemented
,
""
);
}
#endif // HAVE_DNN_IE_NN_BUILDER_2019
#ifdef HAVE_DNN_NGRAPH
std
::
shared_ptr
<
ngraph
::
Node
>
initNgraphAPI
(
const
std
::
shared_ptr
<
ngraph
::
Node
>&
node
)
{
auto
scale_node
=
std
::
make_shared
<
ngraph
::
op
::
Constant
>
(
ngraph
::
element
::
f32
,
ngraph
::
Shape
{
1
},
&
normScale
);
auto
shift_node
=
std
::
make_shared
<
ngraph
::
op
::
Constant
>
(
ngraph
::
element
::
f32
,
ngraph
::
Shape
{
1
},
&
normShift
);
auto
mul
=
std
::
make_shared
<
ngraph
::
op
::
v1
::
Multiply
>
(
scale_node
,
node
,
ngraph
::
op
::
AutoBroadcastType
::
NUMPY
);
auto
scale_shift
=
std
::
make_shared
<
ngraph
::
op
::
v1
::
Add
>
(
mul
,
shift_node
,
ngraph
::
op
::
AutoBroadcastType
::
NUMPY
);
return
std
::
make_shared
<
ngraph
::
op
::
v0
::
Exp
>
(
scale_shift
);
}
#endif // HAVE_DNN_NGRAPH
int64
getFLOPSPerElement
()
const
{
return
3
;
}
};
struct
ChannelsPReLUFunctor
:
public
BaseFunctor
{
typedef
ChannelsPReLULayer
Layer
;
...
...
@@ -1419,6 +1518,20 @@ Ptr<PowerLayer> PowerLayer::create(const LayerParams& params)
return
l
;
}
Ptr
<
ExpLayer
>
ExpLayer
::
create
(
const
LayerParams
&
params
)
{
float
base
=
params
.
get
<
float
>
(
"base"
,
-
1.0
f
);
float
scale
=
params
.
get
<
float
>
(
"scale"
,
1.0
f
);
float
shift
=
params
.
get
<
float
>
(
"shift"
,
0.0
f
);
Ptr
<
ExpLayer
>
l
(
new
ElementWiseLayer
<
ExpFunctor
>
(
ExpFunctor
(
base
,
scale
,
shift
)));
l
->
setParamsFrom
(
params
);
l
->
base
=
base
;
l
->
scale
=
scale
;
l
->
shift
=
shift
;
return
l
;
}
Ptr
<
Layer
>
ChannelsPReLULayer
::
create
(
const
LayerParams
&
params
)
{
CV_Assert
(
params
.
blobs
.
size
()
==
1
);
...
...
modules/dnn/src/opencl/activations.cl
浏览文件 @
96947c30
...
...
@@ -140,3 +140,14 @@ __kernel void ELUForward(const int n, __global const T* in, __global T* out)
out[index]
=
(
src
>=
0.f
)
?
src
:
exp
(
src
)
-
1
;
}
}
__kernel
void
ExpForward
(
const
int
n,
__global
const
T*
in,
__global
T*
out,
const
KERNEL_ARG_DTYPE
normScale,
const
KERNEL_ARG_DTYPE
normShift
)
{
int
index
=
get_global_id
(
0
)
;
if
(
index
<
n
)
{
out[index]
=
exp
(
normShift
+
normScale
*
in[index]
)
;
}
}
modules/dnn/src/tensorflow/tf_importer.cpp
浏览文件 @
96947c30
...
...
@@ -2425,7 +2425,7 @@ void TFImporter::parseNode(const tensorflow::NodeDef& layer_)
connectToAllBlobs
(
layer_id
,
dstNet
,
parsePin
(
layer
.
input
(
0
)),
id
,
num_inputs
);
}
else
if
(
type
==
"Abs"
||
type
==
"Tanh"
||
type
==
"Sigmoid"
||
type
==
"Relu"
||
type
==
"Elu"
||
type
==
"Relu"
||
type
==
"Elu"
||
type
==
"Exp"
||
type
==
"Identity"
||
type
==
"Relu6"
)
{
CV_CheckGT
(
num_inputs
,
0
,
""
);
...
...
modules/dnn/test/test_halide_layers.cpp
浏览文件 @
96947c30
...
...
@@ -621,6 +621,31 @@ INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Power, Combine(
dnnBackendsAndTargetsWithHalide
()
));
typedef
TestWithParam
<
tuple
<
Vec3f
,
tuple
<
Backend
,
Target
>
>
>
Exp
;
TEST_P
(
Exp
,
Accuracy
)
{
float
base
=
get
<
0
>
(
GetParam
())[
0
];
float
scale
=
get
<
0
>
(
GetParam
())[
1
];
float
shift
=
get
<
0
>
(
GetParam
())[
2
];
Backend
backendId
=
get
<
0
>
(
get
<
1
>
(
GetParam
()));
Target
targetId
=
get
<
1
>
(
get
<
1
>
(
GetParam
()));
LayerParams
lp
;
lp
.
set
(
"base"
,
base
);
lp
.
set
(
"scale"
,
scale
);
lp
.
set
(
"shift"
,
shift
);
lp
.
type
=
"Exp"
;
lp
.
name
=
"testLayer"
;
testInPlaceActivation
(
lp
,
backendId
,
targetId
);
}
INSTANTIATE_TEST_CASE_P
(
Layer_Test_Halide
,
Exp
,
Combine
(
/*base, scale, shift*/
Values
(
Vec3f
(
0.9
f
,
-
1.0
f
,
1.1
f
),
Vec3f
(
0.9
f
,
1.1
f
,
-
1.0
f
),
Vec3f
(
-
1.0
f
,
0.9
f
,
1.1
f
),
Vec3f
(
-
1.0
f
,
1.1
f
,
0.9
f
),
Vec3f
(
1.1
f
,
0.9
f
,
-
1.0
f
),
Vec3f
(
1.1
f
,
-
1.0
f
,
0.9
f
)),
dnnBackendsAndTargetsWithHalide
()
));
TEST_P
(
Test_Halide_layers
,
ChannelsPReLU
)
{
LayerParams
lp
;
...
...
modules/dnn/test/test_layers.cpp
浏览文件 @
96947c30
...
...
@@ -2107,6 +2107,12 @@ public:
randu
(
scales
,
-
1.0
f
,
1.0
f
);
activationParams
.
blobs
.
push_back
(
scales
);
}
else
if
(
activationParams
.
type
==
"Exp"
)
{
activationParams
.
set
(
"base"
,
-
1.0
f
);
activationParams
.
set
(
"scale"
,
0.3
f
);
activationParams
.
set
(
"shift"
,
0.6
f
);
}
}
static
void
makeDefaultTestEltwiseLayer
(
LayerParams
&
eltwiseParams
,
const
std
::
string
&
op
,
bool
withCoefficients
)
...
...
@@ -2178,7 +2184,7 @@ public:
static
testing
::
internal
::
ParamGenerator
<
std
::
string
>
activationLayersList
()
{
// TODO: automate list generation
return
Values
(
"ReLU"
,
"ReLU6"
,
"ChannelsPReLU"
,
"TanH"
,
"Swish"
,
"Mish"
,
"Sigmoid"
,
"ELU"
,
"AbsVal"
,
"BNLL"
,
"Power"
);
return
Values
(
"ReLU"
,
"ReLU6"
,
"ChannelsPReLU"
,
"TanH"
,
"Swish"
,
"Mish"
,
"Sigmoid"
,
"ELU"
,
"AbsVal"
,
"BNLL"
,
"Power"
,
"Exp"
);
}
static
testing
::
internal
::
ParamGenerator
<
tuple
<
Backend
,
Target
>
>
dnnBackendsAndTargetsForFusionTests
()
...
...
modules/dnn/test/test_onnx_importer.cpp
浏览文件 @
96947c30
...
...
@@ -307,6 +307,13 @@ TEST_P(Test_ONNX_layers, Power)
testONNXModels
(
"pow2"
,
npy
,
0
,
0
,
false
,
false
);
}
TEST_P
(
Test_ONNX_layers
,
Exp
)
{
if
(
backend
==
DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
)
applyTestTag
(
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER
);
testONNXModels
(
"exp"
);
}
TEST_P
(
Test_ONNX_layers
,
Concatenation
)
{
if
(
backend
==
DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录