Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
ee1ef241
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ee1ef241
编写于
2月 25, 2019
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add resnext
上级
de8b1b78
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
68 addition
and
17 deletion
+68
-17
fluid/PaddleCV/image_classification/models/se_resnext.py
fluid/PaddleCV/image_classification/models/se_resnext.py
+68
-17
未找到文件。
fluid/PaddleCV/image_classification/models/se_resnext.py
浏览文件 @
ee1ef241
...
...
@@ -7,7 +7,8 @@ import math
__all__
=
[
"SE_ResNeXt"
,
"SE_ResNeXt50_32x4d"
,
"SE_ResNeXt101_32x4d"
,
"SE_ResNeXt152_32x4d"
"SE_ResNeXt152_32x4d"
,
"ResNeXt50_32x4d"
,
"ResNeXt101_32x4d"
,
"ResNeXt152_32x4d"
]
train_parameters
=
{
...
...
@@ -25,9 +26,11 @@ train_parameters = {
class
SE_ResNeXt
():
def
__init__
(
self
,
layers
=
50
):
def
__init__
(
self
,
layers
=
50
,
SE
=
True
,
is_train
=
True
):
self
.
params
=
train_parameters
self
.
layers
=
layers
self
.
SE
=
SE
self
.
is_train
=
is_train
def
net
(
self
,
input
,
class_dim
=
1000
):
layers
=
self
.
layers
...
...
@@ -96,19 +99,31 @@ class SE_ResNeXt():
for
block
in
range
(
len
(
depth
)):
for
i
in
range
(
depth
[
block
]):
if
self
.
SE
:
conv
=
self
.
bottleneck_block
(
input
=
conv
,
num_filters
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
cardinality
=
cardinality
,
reduction_ratio
=
reduction_ratio
)
else
:
conv
=
self
.
bottleneckX_block
(
input
=
conv
,
num_filters
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
cardinality
=
4
)
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
if
self
.
SE
:
drop
=
fluid
.
layers
.
dropout
(
x
=
pool
,
dropout_prob
=
0.5
,
seed
=
self
.
params
[
'dropout_seed'
])
x
=
pool
,
dropout_prob
=
0.5
,
seed
=
self
.
params
[
'dropout_seed'
],
is_test
=
not
self
.
is_train
)
else
:
drop
=
pool
stdv
=
1.0
/
math
.
sqrt
(
drop
.
shape
[
1
]
*
1.0
)
out
=
fluid
.
layers
.
fc
(
input
=
drop
,
act
=
"softmax"
,
size
=
class_dim
,
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
...
...
@@ -145,6 +160,24 @@ class SE_ResNeXt():
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
scale
,
act
=
'relu'
)
def
bottleneckX_block
(
self
,
input
,
num_filters
,
stride
,
cardinality
):
conv0
=
self
.
conv_bn_layer
(
input
=
input
,
num_filters
=
num_filters
,
filter_size
=
1
,
act
=
'relu'
)
conv1
=
self
.
conv_bn_layer
(
input
=
conv0
,
num_filters
=
num_filters
,
filter_size
=
3
,
stride
=
stride
,
groups
=
cardinality
,
act
=
'relu'
)
conv2
=
self
.
conv_bn_layer
(
input
=
conv1
,
num_filters
=
num_filters
*
2
,
filter_size
=
1
,
act
=
None
)
short
=
self
.
shortcut
(
input
,
num_filters
*
2
,
stride
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv2
,
act
=
'relu'
)
def
conv_bn_layer
(
self
,
input
,
num_filters
,
...
...
@@ -152,6 +185,9 @@ class SE_ResNeXt():
stride
=
1
,
groups
=
1
,
act
=
None
):
# initializer for webvision
n
=
filter_size
*
filter_size
*
num_filters
std
=
math
.
sqrt
(
2.0
/
n
)
conv
=
fluid
.
layers
.
conv2d
(
input
=
input
,
num_filters
=
num_filters
,
...
...
@@ -160,8 +196,11 @@ class SE_ResNeXt():
padding
=
(
filter_size
-
1
)
//
2
,
groups
=
groups
,
act
=
None
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
0.0
,
std
)
),
bias_attr
=
False
)
return
fluid
.
layers
.
batch_norm
(
input
=
conv
,
act
=
act
)
return
fluid
.
layers
.
batch_norm
(
input
=
conv
,
act
=
act
,
is_test
=
not
self
.
is_train
)
def
squeeze_excitation
(
self
,
input
,
num_channels
,
reduction_ratio
):
pool
=
fluid
.
layers
.
pool2d
(
...
...
@@ -184,16 +223,28 @@ class SE_ResNeXt():
return
scale
def
SE_ResNeXt50_32x4d
():
model
=
SE_ResNeXt
(
layers
=
50
)
def
SE_ResNeXt50_32x4d
(
is_train
=
True
):
model
=
SE_ResNeXt
(
layers
=
50
,
is_train
=
is_train
)
return
model
def
SE_ResNeXt101_32x4d
():
model
=
SE_ResNeXt
(
layers
=
101
)
def
SE_ResNeXt101_32x4d
(
is_train
=
True
):
model
=
SE_ResNeXt
(
layers
=
101
,
is_train
=
is_train
)
return
model
def
SE_ResNeXt152_32x4d
():
model
=
SE_ResNeXt
(
layers
=
152
)
def
SE_ResNeXt152_32x4d
(
is_train
=
True
):
model
=
SE_ResNeXt
(
layers
=
152
,
is_train
=
is_train
)
return
model
def
ResNeXt50_32x4d
(
is_train
=
True
):
model
=
SE_ResNeXt
(
layers
=
50
,
SE
=
False
,
is_train
=
is_train
)
return
model
def
ResNeXt101_32x4d
(
is_train
=
True
):
model
=
SE_ResNeXt
(
layers
=
101
,
SE
=
False
,
is_train
=
is_train
)
return
model
def
ResNeXt152_32x4d
(
is_train
=
True
):
model
=
SE_ResNeXt
(
layers
=
152
,
SE
=
False
,
is_train
=
is_train
)
return
model
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录