Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
1f132953
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1f132953
编写于
7月 04, 2022
作者:
N
nihao
提交者:
GitHub
7月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mobileone block k>1 bugfix (#6342)
上级
d409ec06
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
29 deletion
+31
-29
ppdet/modeling/backbones/mobileone.py
ppdet/modeling/backbones/mobileone.py
+31
-29
未找到文件。
ppdet/modeling/backbones/mobileone.py
浏览文件 @
1f132953
...
...
@@ -22,7 +22,7 @@ import paddle
import
paddle.nn
as
nn
from
paddle
import
ParamAttr
from
paddle.regularizer
import
L2Decay
from
paddle.nn.initializer
import
Normal
from
paddle.nn.initializer
import
Normal
,
Constant
from
ppdet.modeling.ops
import
get_act_fn
from
ppdet.modeling.layers
import
ConvNormLayer
...
...
@@ -57,9 +57,7 @@ class MobileOneBlock(nn.Layer):
self
.
depth_conv
=
nn
.
LayerList
()
self
.
point_conv
=
nn
.
LayerList
()
for
i
in
range
(
self
.
k
):
if
i
>
0
:
stride
=
1
for
_
in
range
(
self
.
k
):
self
.
depth_conv
.
append
(
ConvNormLayer
(
ch_in
,
...
...
@@ -112,7 +110,8 @@ class MobileOneBlock(nn.Layer):
self
.
rbr_identity_st2
=
nn
.
BatchNorm2D
(
num_features
=
ch_out
,
weight_attr
=
ParamAttr
(
regularizer
=
L2Decay
(
0.0
)),
bias_attr
=
ParamAttr
(
regularizer
=
L2Decay
(
0.0
)))
bias_attr
=
ParamAttr
(
regularizer
=
L2Decay
(
0.0
)))
if
ch_in
==
ch_out
and
self
.
stride
==
1
else
None
self
.
act
=
get_act_fn
(
act
)
if
act
is
None
or
isinstance
(
act
,
(
str
,
dict
))
else
act
...
...
@@ -125,9 +124,10 @@ class MobileOneBlock(nn.Layer):
else
:
id_out_st1
=
self
.
rbr_identity_st1
(
x
)
x1_1
=
x
.
clone
()
x1_1
=
0
for
i
in
range
(
self
.
k
):
x1_1
=
self
.
depth_conv
[
i
](
x1_1
)
x1_1
+=
self
.
depth_conv
[
i
](
x
)
x1_2
=
self
.
rbr_1x1
(
x
)
x1
=
self
.
act
(
x1_1
+
x1_2
+
id_out_st1
)
...
...
@@ -136,9 +136,9 @@ class MobileOneBlock(nn.Layer):
else
:
id_out_st2
=
self
.
rbr_identity_st2
(
x1
)
x2_1
=
x1
.
clone
()
x2_1
=
0
for
i
in
range
(
self
.
k
):
x2_1
=
self
.
point_conv
[
i
](
x2_
1
)
x2_1
+=
self
.
point_conv
[
i
](
x
1
)
y
=
self
.
act
(
x2_1
+
id_out_st2
)
return
y
...
...
@@ -151,7 +151,9 @@ class MobileOneBlock(nn.Layer):
kernel_size
=
self
.
kernel_size
,
stride
=
self
.
stride
,
padding
=
self
.
padding
,
groups
=
self
.
ch_in
)
groups
=
self
.
ch_in
,
bias_attr
=
ParamAttr
(
initializer
=
Constant
(
value
=
0.
),
learning_rate
=
1.
))
if
not
hasattr
(
self
,
'conv2'
):
self
.
conv2
=
nn
.
Conv2D
(
in_channels
=
self
.
ch_in
,
...
...
@@ -159,7 +161,9 @@ class MobileOneBlock(nn.Layer):
kernel_size
=
1
,
stride
=
1
,
padding
=
'SAME'
,
groups
=
1
)
groups
=
1
,
bias_attr
=
ParamAttr
(
initializer
=
Constant
(
value
=
0.
),
learning_rate
=
1.
))
conv1_kernel
,
conv1_bias
,
conv2_kernel
,
conv2_bias
=
self
.
get_equivalent_kernel_bias
(
)
...
...
@@ -211,26 +215,24 @@ class MobileOneBlock(nn.Layer):
return
0
,
0
if
isinstance
(
branch
,
nn
.
LayerList
):
kernel
=
0
running_mean
=
0
running_var
=
0
gamma
=
0
beta
=
0
eps
=
0
fused_kernels
=
[]
fused_bias
=
[]
for
block
in
branch
:
kernel
+=
block
.
conv
.
weight
running_mean
+=
block
.
norm
.
_mean
running_var
+=
block
.
norm
.
_variance
gamma
+=
block
.
norm
.
weight
beta
+=
block
.
norm
.
bias
eps
+=
block
.
norm
.
_epsilon
kernel
=
block
.
conv
.
weight
running_mean
=
block
.
norm
.
_mean
running_var
=
block
.
norm
.
_variance
gamma
=
block
.
norm
.
weight
beta
=
block
.
norm
.
bias
eps
=
block
.
norm
.
_epsilon
std
=
(
running_var
+
eps
).
sqrt
()
t
=
(
gamma
/
std
).
reshape
((
-
1
,
1
,
1
,
1
))
fused_kernels
.
append
(
kernel
*
t
)
fused_bias
.
append
(
beta
-
running_mean
*
gamma
/
std
)
return
sum
(
fused_kernels
),
sum
(
fused_bias
)
kernel
/=
len
(
branch
)
running_mean
/=
len
(
branch
)
running_var
/=
len
(
branch
)
gamma
/=
len
(
branch
)
beta
/=
len
(
branch
)
eps
/=
len
(
branch
)
elif
isinstance
(
branch
,
ConvNormLayer
):
kernel
=
branch
.
conv
.
weight
running_mean
=
branch
.
norm
.
_mean
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录