Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
3ff10601
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3ff10601
编写于
11月 12, 2019
作者:
Y
Yang Zhang
提交者:
qingqing01
11月 12, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix nolocal naming (#24)
* Fix nolocal naming * Fix `cb_resnet` as well
上级
a992fef4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
18 deletion
+17
-18
ppdet/modeling/backbones/cb_resnet.py
ppdet/modeling/backbones/cb_resnet.py
+16
-17
ppdet/modeling/backbones/nonlocal_helper.py
ppdet/modeling/backbones/nonlocal_helper.py
+0
-0
ppdet/modeling/backbones/resnet.py
ppdet/modeling/backbones/resnet.py
+1
-1
未找到文件。
ppdet/modeling/backbones/cb_resnet.py
浏览文件 @
3ff10601
...
@@ -28,7 +28,7 @@ from ppdet.core.workspace import register, serializable
...
@@ -28,7 +28,7 @@ from ppdet.core.workspace import register, serializable
from
numbers
import
Integral
from
numbers
import
Integral
from
.name_adapter
import
NameAdapter
from
.name_adapter
import
NameAdapter
from
.nonlocal
import
add_space_nonlocal
from
.nonlocal
_helper
import
add_space_nonlocal
__all__
=
[
'CBResNet'
]
__all__
=
[
'CBResNet'
]
...
@@ -99,7 +99,7 @@ class CBResNet(object):
...
@@ -99,7 +99,7 @@ class CBResNet(object):
152
:
([
3
,
8
,
36
,
3
],
self
.
bottleneck
),
152
:
([
3
,
8
,
36
,
3
],
self
.
bottleneck
),
200
:
([
3
,
12
,
48
,
3
],
self
.
bottleneck
),
200
:
([
3
,
12
,
48
,
3
],
self
.
bottleneck
),
}
}
self
.
nonlocal_stages
=
nonlocal_stages
self
.
nonlocal_stages
=
nonlocal_stages
self
.
nonlocal_mod_cfg
=
{
self
.
nonlocal_mod_cfg
=
{
50
:
2
,
50
:
2
,
...
@@ -107,11 +107,11 @@ class CBResNet(object):
...
@@ -107,11 +107,11 @@ class CBResNet(object):
152
:
8
,
152
:
8
,
200
:
12
,
200
:
12
,
}
}
self
.
stage_filters
=
[
64
,
128
,
256
,
512
]
self
.
stage_filters
=
[
64
,
128
,
256
,
512
]
self
.
_c1_out_chan_num
=
64
self
.
_c1_out_chan_num
=
64
self
.
na
=
NameAdapter
(
self
)
self
.
na
=
NameAdapter
(
self
)
def
_conv_offset
(
self
,
input
,
filter_size
,
stride
,
padding
,
act
=
None
,
name
=
None
):
def
_conv_offset
(
self
,
input
,
filter_size
,
stride
,
padding
,
act
=
None
,
name
=
None
):
out_channel
=
filter_size
*
filter_size
*
3
out_channel
=
filter_size
*
filter_size
*
3
out
=
fluid
.
layers
.
conv2d
(
input
,
out
=
fluid
.
layers
.
conv2d
(
input
,
...
@@ -126,7 +126,7 @@ class CBResNet(object):
...
@@ -126,7 +126,7 @@ class CBResNet(object):
act
=
act
,
act
=
act
,
name
=
name
)
name
=
name
)
return
out
return
out
def
_conv_norm
(
self
,
def
_conv_norm
(
self
,
input
,
input
,
num_filters
,
num_filters
,
...
@@ -247,7 +247,7 @@ class CBResNet(object):
...
@@ -247,7 +247,7 @@ class CBResNet(object):
conv_name1
,
conv_name2
,
conv_name3
,
\
conv_name1
,
conv_name2
,
conv_name3
,
\
shortcut_name
=
self
.
na
.
fix_bottleneck_name
(
name
)
shortcut_name
=
self
.
na
.
fix_bottleneck_name
(
name
)
conv_def
=
[[
num_filters
,
1
,
stride1
,
'relu'
,
1
,
conv_name1
],
conv_def
=
[[
num_filters
,
1
,
stride1
,
'relu'
,
1
,
conv_name1
],
[
num_filters
,
3
,
stride2
,
'relu'
,
groups
,
conv_name2
],
[
num_filters
,
3
,
stride2
,
'relu'
,
groups
,
conv_name2
],
[
num_filters
*
expand
,
1
,
1
,
None
,
1
,
conv_name3
]]
[
num_filters
*
expand
,
1
,
1
,
None
,
1
,
conv_name3
]]
...
@@ -312,12 +312,12 @@ class CBResNet(object):
...
@@ -312,12 +312,12 @@ class CBResNet(object):
ch_out
=
self
.
stage_filters
[
stage_num
-
2
]
ch_out
=
self
.
stage_filters
[
stage_num
-
2
]
is_first
=
False
if
stage_num
!=
2
else
True
is_first
=
False
if
stage_num
!=
2
else
True
dcn
=
True
if
stage_num
in
self
.
dcn_v2_stages
else
False
dcn
=
True
if
stage_num
in
self
.
dcn_v2_stages
else
False
nonlocal_mod
=
1000
nonlocal_mod
=
1000
if
stage_num
in
self
.
nonlocal_stages
:
if
stage_num
in
self
.
nonlocal_stages
:
nonlocal_mod
=
self
.
nonlocal_mod_cfg
[
self
.
depth
]
if
stage_num
==
4
else
2
nonlocal_mod
=
self
.
nonlocal_mod_cfg
[
self
.
depth
]
if
stage_num
==
4
else
2
# Make the layer name and parameter name consistent
# Make the layer name and parameter name consistent
# with ImageNet pre-trained model
# with ImageNet pre-trained model
conv
=
input
conv
=
input
...
@@ -332,15 +332,15 @@ class CBResNet(object):
...
@@ -332,15 +332,15 @@ class CBResNet(object):
is_first
=
is_first
,
is_first
=
is_first
,
name
=
conv_name
,
name
=
conv_name
,
dcn
=
dcn
)
dcn
=
dcn
)
# add non local model
# add non local model
dim_in
=
conv
.
shape
[
1
]
dim_in
=
conv
.
shape
[
1
]
nonlocal_name
=
"nonlocal_conv{}_lvl{}"
.
format
(
stage_num
,
self
.
curr_level
)
nonlocal_name
=
"nonlocal_conv{}_lvl{}"
.
format
(
stage_num
,
self
.
curr_level
)
if
i
%
nonlocal_mod
==
nonlocal_mod
-
1
:
if
i
%
nonlocal_mod
==
nonlocal_mod
-
1
:
conv
=
add_space_nonlocal
(
conv
=
add_space_nonlocal
(
conv
,
dim_in
,
dim_in
,
conv
,
dim_in
,
dim_in
,
nonlocal_name
+
'_{}'
.
format
(
i
),
int
(
dim_in
/
2
)
)
nonlocal_name
+
'_{}'
.
format
(
i
),
int
(
dim_in
/
2
)
)
return
conv
return
conv
def
c1_stage
(
self
,
input
):
def
c1_stage
(
self
,
input
):
...
@@ -376,7 +376,7 @@ class CBResNet(object):
...
@@ -376,7 +376,7 @@ class CBResNet(object):
pool_padding
=
1
,
pool_padding
=
1
,
pool_type
=
'max'
)
pool_type
=
'max'
)
return
output
return
output
def
connect
(
self
,
left
,
right
,
name
):
def
connect
(
self
,
left
,
right
,
name
):
ch_right
=
right
.
shape
[
1
]
ch_right
=
right
.
shape
[
1
]
conv
=
self
.
_conv_norm
(
left
,
conv
=
self
.
_conv_norm
(
left
,
...
@@ -392,7 +392,7 @@ class CBResNet(object):
...
@@ -392,7 +392,7 @@ class CBResNet(object):
out_shape
.
stop_gradient
=
True
out_shape
.
stop_gradient
=
True
conv
=
fluid
.
layers
.
resize_nearest
(
conv
=
fluid
.
layers
.
resize_nearest
(
conv
,
scale
=
2.
,
actual_shape
=
out_shape
)
conv
,
scale
=
2.
,
actual_shape
=
out_shape
)
output
=
fluid
.
layers
.
elementwise_add
(
x
=
right
,
y
=
conv
)
output
=
fluid
.
layers
.
elementwise_add
(
x
=
right
,
y
=
conv
)
return
output
return
output
...
@@ -410,7 +410,7 @@ class CBResNet(object):
...
@@ -410,7 +410,7 @@ class CBResNet(object):
res
=
self
.
layer_warp
(
res
,
i
)
res
=
self
.
layer_warp
(
res
,
i
)
if
i
in
self
.
feature_maps
:
if
i
in
self
.
feature_maps
:
res_endpoints
.
append
(
res
)
res_endpoints
.
append
(
res
)
for
num
in
range
(
1
,
self
.
repeat_num
):
for
num
in
range
(
1
,
self
.
repeat_num
):
self
.
curr_level
=
num
self
.
curr_level
=
num
res
=
self
.
c1_stage
(
input
)
res
=
self
.
c1_stage
(
input
)
...
@@ -420,7 +420,6 @@ class CBResNet(object):
...
@@ -420,7 +420,6 @@ class CBResNet(object):
res_endpoints
[
i
]
=
res
res_endpoints
[
i
]
=
res
if
self
.
freeze_at
>=
i
+
2
:
if
self
.
freeze_at
>=
i
+
2
:
res
.
stop_gradient
=
True
res
.
stop_gradient
=
True
return
OrderedDict
([(
'res{}_sum'
.
format
(
self
.
feature_maps
[
idx
]),
feat
)
return
OrderedDict
([(
'res{}_sum'
.
format
(
self
.
feature_maps
[
idx
]),
feat
)
for
idx
,
feat
in
enumerate
(
res_endpoints
)])
for
idx
,
feat
in
enumerate
(
res_endpoints
)])
ppdet/modeling/backbones/nonlocal.py
→
ppdet/modeling/backbones/nonlocal
_helper
.py
浏览文件 @
3ff10601
文件已移动
ppdet/modeling/backbones/resnet.py
浏览文件 @
3ff10601
...
@@ -27,7 +27,7 @@ from paddle.fluid.initializer import Constant
...
@@ -27,7 +27,7 @@ from paddle.fluid.initializer import Constant
from
ppdet.core.workspace
import
register
,
serializable
from
ppdet.core.workspace
import
register
,
serializable
from
numbers
import
Integral
from
numbers
import
Integral
from
.nonlocal
import
add_space_nonlocal
from
.nonlocal
_helper
import
add_space_nonlocal
from
.name_adapter
import
NameAdapter
from
.name_adapter
import
NameAdapter
__all__
=
[
'ResNet'
,
'ResNetC5'
]
__all__
=
[
'ResNet'
,
'ResNetC5'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录