Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
e07b56a9
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看板
提交
e07b56a9
编写于
5月 09, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add inception_v4 config in fluid
上级
e785f604
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
415 addition
and
3 deletion
+415
-3
fluid/image_classification/inception_v4.py
fluid/image_classification/inception_v4.py
+405
-0
fluid/image_classification/train.py
fluid/image_classification/train.py
+10
-3
未找到文件。
fluid/image_classification/inception_v4.py
0 → 100644
浏览文件 @
e07b56a9
import
os
import
paddle.fluid
as
fluid
def
inception_v4
(
image
,
label
):
tmp
=
stem
(
input
=
image
)
for
i
in
range
(
0
,
4
):
tmp
=
inception_A
(
input
=
tmp
,
depth
=
i
)
tmp
=
reduction_A
(
input
=
tmp
)
for
i
in
range
(
0
,
7
):
tmp
=
inception_B
(
input
=
tmp
,
depth
=
i
)
reduction_B
(
input
=
tmp
)
for
i
in
range
(
0
,
3
):
tmp
=
inception_C
(
input
=
tmp
,
depth
=
i
)
pool
=
fluid
.
layers
.
pool2d
(
pool_type
=
'ave'
,
input
=
tmp
,
pool_size
=
7
,
pool_stride
=
1
)
dropout
=
fluid
.
layers
.
dropout
(
input
=
pool
,
drop_prob
=
0.2
)
out
=
fluid
.
layers
.
softmax
(
input
=
dropout
)
return
out
def
conv_bn_layer
(
input
,
num_filters
,
filter_size
,
padding
=
1
,
stride
=
1
,
groups
=
1
,
act
=
None
):
conv
=
fluid
.
layers
.
conv2d
(
input
=
input
,
num_filters
=
num_filters
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
padding
,
groups
=
groups
,
act
=
None
,
bias_attr
=
False
)
return
fluid
.
layers
.
batch_norm
(
input
=
conv
,
act
=
act
)
def
stem
(
input
):
conv1
=
conv_bn_layer
(
input
=
input
,
num_filters
=
32
,
filter_size
=
3
,
stride
=
2
)
conv2
=
conv_bn_layer
(
input
=
conv1
,
num_filters
=
32
,
filter_size
=
3
)
conv3
=
conv_bn_layer
(
input
=
conv2
,
num_filters
=
64
,
filter_size
=
3
)
def
block0
(
input
):
pool0
=
fluid
.
layers
.
pool2d
(
input
=
input
,
pool_size
=
3
,
pool_stride
=
2
,
pool_type
=
'max'
)
conv0
=
conv_bn_layer
(
input
=
input
,
num_filters
=
96
,
filter_size
=
3
,
stride
=
2
)
return
fluid
.
layers
.
concat
(
input
=
[
pool0
,
conv0
])
def
block1
(
input
):
l_conv0
=
conv_bn_layer
(
input
=
input
,
num_filters
=
64
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
l_conv1
=
conv_bn_layer
(
input
=
l_conv0
,
num_filters
=
96
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
r_conv0
=
conv_bn_layer
(
input
=
input
,
num_filters
=
64
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
r_conv1
=
conv_bn_layer
(
input
=
r_conv0
,
num_filters
=
64
,
filter_size
=
(
7
,
1
),
stride
=
1
,
padding
=
(
3
,
0
))
r_conv2
=
conv_bn_layer
(
input
=
r_conv1
,
num_filters
=
64
,
filter_size
=
(
1
,
7
),
stride
=
1
,
padding
=
(
0
,
3
))
r_conv3
=
conv_bn_layer
(
input
=
r_conv2
,
num_filters
=
96
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
return
fluid
.
layers
.
concat
(
input
=
[
l_conv1
,
r_conv3
])
def
block2
(
input
):
conv0
=
conv_bn_layer
(
input
=
input
,
num_filters
=
192
,
filter_size
=
3
,
stride
=
2
,
padding
=
1
)
pool0
=
fluid
.
layers
.
pool2d
(
input
=
input
,
pool_size
=
3
,
pool_stride
=
2
,
pool_type
=
'max'
)
return
fluid
.
layers
.
concat
(
input
=
[
conv0
,
pool0
])
conv3
=
block0
(
conv2
)
conv4
=
block1
(
conv3
)
conv5
=
block2
(
conv4
)
return
conv5
def
inception_A
(
input
,
depth
):
b0_pool0
=
paddle
.
layer
.
pool2d
(
name
=
'inceptA{0}_branch0_pool0'
.
format
(
depth
),
input
=
input
,
pool_size
=
3
,
stride
=
1
,
padding
=
1
,
pool_type
=
'avg'
)
b0_conv0
=
conv_bn_layer
(
name
=
'inceptA{0}_branch0_conv0'
.
format
(
depth
),
input
=
b0_pool0
,
num_filters
=
96
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b1_conv0
=
conv_bn_layer
(
name
=
'inceptA{0}_branch1_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
96
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv0
=
conv_bn_layer
(
name
=
'inceptA{0}_branch2_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
64
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv1
=
conv_bn_layer
(
name
=
'inceptA{0}_branch2_conv1'
.
format
(
depth
),
input
=
b2_conv0
,
num_channels
=
64
,
num_filters
=
96
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
b3_conv0
=
conv_bn_layer
(
name
=
'inceptA{0}_branch3_conv0'
.
format
(
depth
),
input
=
input
,
num_channels
=
384
,
num_filters
=
64
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b3_conv1
=
conv_bn_layer
(
name
=
'inceptA{0}_branch3_conv1'
.
format
(
depth
),
input
=
b3_conv0
,
num_filters
=
96
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
b3_conv2
=
conv_bn_layer
(
name
=
'inceptA{0}_branch3_conv2'
.
format
(
depth
),
input
=
b3_conv1
,
num_filters
=
96
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
return
paddle
.
layer
.
concat
(
input
=
[
b0_conv0
,
b1_conv0
,
b2_conv1
,
b3_conv2
])
def
reduction_A
(
input
):
b0_pool0
=
fluid
.
layers
.
pool2d
(
name
=
'ReductA_branch0_pool0'
,
input
=
input
,
pool_size
=
3
,
pool_stride
=
2
,
pool_type
=
'max'
)
b1_conv0
=
conv_bn_layer
(
name
=
'ReductA_branch1_conv0'
,
input
=
input
,
num_filters
=
384
,
filter_size
=
3
,
stride
=
2
,
padding
=
1
)
b2_conv0
=
conv_bn_layer
(
name
=
'ReductA_branch2_conv0'
,
input
=
input
,
num_filters
=
192
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv1
=
conv_bn_layer
(
name
=
'ReductA_branch2_conv1'
,
input
=
b2_conv0
,
num_filters
=
224
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
)
b2_conv2
=
conv_bn_layer
(
name
=
'ReductA_branch2_conv2'
,
input
=
b2_conv1
,
num_filters
=
256
,
filter_size
=
3
,
stride
=
2
,
padding
=
1
)
return
fluid
.
layers
.
concat
(
input
=
[
b0_pool0
,
b1_conv0
,
b2_conv2
])
def
inception_B
(
input
,
depth
):
b0_pool0
=
fluid
.
layers
.
pool2d
(
name
=
'inceptB{0}_branch0_pool0'
.
format
(
depth
),
input
=
input
,
pool_size
=
3
,
pool_stride
=
1
,
pool_padding
=
1
,
pool_type
=
'avg'
)
b0_conv0
=
conv_bn_layer
(
name
=
'inceptB{0}_branch0_conv0'
.
format
(
depth
),
input
=
b0_pool0
,
num_filters
=
128
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b1_conv0
=
conv_bn_layer
(
name
=
'inceptB{0}_branch1_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
384
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv0
=
conv_bn_layer
(
name
=
'inceptB{0}_branch2_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
192
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv1
=
conv_bn_layer
(
name
=
'inceptB{0}_branch2_conv1'
.
format
(
depth
),
input
=
b2_conv0
,
num_filters
=
224
,
filter_size
=
(
1
,
7
),
stride
=
1
,
padding
=
(
0
,
3
))
b2_conv2
=
conv_bn_layer
(
name
=
'inceptB{0}_branch2_conv2'
.
format
(
depth
),
input
=
b2_conv1
,
num_filters
=
256
,
filter_size
=
(
7
,
1
),
stride
=
1
,
padding
=
(
3
,
0
))
b3_conv0
=
conv_bn_layer
(
name
=
'inceptB{0}_branch3_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
192
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b3_conv1
=
conv_bn_layer
(
name
=
'inceptB{0}_branch3_conv1'
.
format
(
depth
),
input
=
b3_conv0
,
num_filters
=
192
,
filter_size
=
(
1
,
7
),
stride
=
1
,
padding
=
(
0
,
3
))
b3_conv2
=
conv_bn_layer
(
name
=
'inceptB{0}_branch3_conv2'
.
format
(
depth
),
input
=
b3_conv1
,
num_filters
=
224
,
filter_size
=
(
7
,
1
),
stride
=
1
,
padding
=
(
3
,
0
))
b3_conv3
=
conv_bn_layer
(
name
=
'inceptB{0}_branch3_conv3'
.
format
(
depth
),
input
=
b3_conv2
,
num_filters
=
224
,
filter_size
=
(
1
,
7
),
stride
=
1
,
padding
=
(
0
,
3
))
b3_conv4
=
conv_bn_layer
(
name
=
'inceptB{0}_branch3_conv4'
.
format
(
depth
),
input
=
b3_conv3
,
num_filters
=
256
,
filter_size
=
(
7
,
1
),
stride
=
1
,
padding
=
(
3
,
0
))
return
fluid
.
layers
.
concat
(
input
=
[
b0_conv0
,
b1_conv0
,
b2_conv2
,
b3_conv4
])
def
reduction_B
(
input
):
b0_pool0
=
fluid
.
layers
.
pool2d
(
name
=
'ReductB_branch0_pool0'
,
input
=
input
,
pool_size
=
3
,
pool_stride
=
2
,
pool_type
=
'max'
)
b1_conv0
=
conv_bn_layer
(
name
=
'ReductB_branch1_conv0'
,
input
=
input
,
num_filters
=
192
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b1_conv1
=
conv_bn_layer
(
name
=
'ReductB_branch1_conv1'
,
input
=
b1_conv0
,
num_filters
=
192
,
filter_size
=
3
,
stride
=
2
,
padding
=
1
)
b2_conv0
=
conv_bn_layer
(
name
=
'ReductB_branch2_conv0'
,
input
=
input
,
num_filters
=
256
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv1
=
conv_bn_layer
(
name
=
'ReductB_branch2_conv1'
,
input
=
b2_conv0
,
num_filters
=
256
,
filter_size
=
(
1
,
7
),
stride
=
1
,
padding
=
(
0
,
3
))
b2_conv2
=
conv_bn_layer
(
name
=
'ReductB_branch2_conv2'
,
input
=
b2_conv1
,
num_filters
=
320
,
filter_size
=
(
7
,
1
),
stride
=
1
,
padding
=
(
3
,
0
))
b2_conv3
=
conv_bn_layer
(
name
=
'ReductB_branch2_conv3'
,
input
=
b2_conv2
,
num_filters
=
320
,
filter_size
=
3
,
stride
=
2
,
padding
=
1
)
return
fluid
.
layers
.
concat
(
input
=
[
b0_pool0
,
b1_conv1
,
b2_conv3
])
def
inception_C
(
input
,
depth
):
b0_pool0
=
fluid
.
layers
.
pool2d
(
name
=
'inceptC{0}_branch0_pool0'
.
format
(
depth
),
input
=
input
,
pool_size
=
3
,
pool_stride
=
1
,
pool_padding
=
1
,
pool_type
=
'avg'
)
b0_conv0
=
conv_bn_layer
(
name
=
'inceptC{0}_branch0_conv0'
.
format
(
depth
),
input
=
b0_pool0
,
num_filters
=
256
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b1_conv0
=
conv_bn_layer
(
name
=
'inceptC{0}_branch1_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
256
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv0
=
conv_bn_layer
(
name
=
'inceptC{0}_branch2_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
384
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b2_conv1
=
conv_bn_layer
(
name
=
'inceptC{0}_branch2_conv1'
.
format
(
depth
),
input
=
b2_conv0
,
num_filters
=
256
,
filter_size
=
(
1
,
3
),
stride
=
1
,
padding
=
(
0
,
1
))
b2_conv2
=
conv_bn_layer
(
name
=
'inceptC{0}_branch2_conv2'
.
format
(
depth
),
input
=
b2_conv0
,
num_filters
=
256
,
filter_size
=
(
3
,
1
),
stride
=
1
,
padding
=
(
1
,
0
))
b3_conv0
=
conv_bn_layer
(
name
=
'inceptC{0}_branch3_conv0'
.
format
(
depth
),
input
=
input
,
num_filters
=
384
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
)
b3_conv1
=
conv_bn_layer
(
name
=
'inceptC{0}_branch3_conv1'
.
format
(
depth
),
input
=
b3_conv0
,
num_filters
=
448
,
filter_size
=
(
1
,
3
),
stride
=
1
,
padding
=
(
0
,
1
))
b3_conv2
=
conv_bn_layer
(
name
=
'inceptC{0}_branch3_conv2'
.
format
(
depth
),
input
=
b3_conv1
,
num_filters
=
512
,
filter_size
=
(
3
,
1
),
stride
=
1
,
padding
=
(
1
,
0
))
b3_conv3
=
conv_bn_layer
(
name
=
'inceptC{0}_branch3_conv3'
.
format
(
depth
),
input
=
b3_conv2
,
num_filters
=
256
,
filter_size
=
(
3
,
1
),
stride
=
1
,
padding
=
(
1
,
0
))
b3_conv4
=
conv_bn_layer
(
name
=
'inceptC{0}_branch3_conv4'
.
format
(
depth
),
input
=
b3_conv2
,
num_filters
=
256
,
filter_size
=
(
1
,
3
),
stride
=
1
,
padding
=
(
0
,
1
))
return
fluid
.
layers
.
concat
(
input
=
[
b0_conv0
,
b1_conv0
,
b2_conv1
,
b2_conv2
,
b3_conv3
,
b3_conv4
])
fluid/image_classification/train.py
浏览文件 @
e07b56a9
...
...
@@ -6,6 +6,7 @@ import paddle
import
paddle.fluid
as
fluid
from
se_resnext
import
SE_ResNeXt
from
mobilenet
import
mobile_net
from
inception_v4
import
inception_v4
import
reader
import
argparse
import
functools
...
...
@@ -70,8 +71,10 @@ def train_parallel_do(args,
if
args
.
model
is
'se_resnext'
:
out
=
SE_ResNeXt
(
input
=
image_
,
class_dim
=
class_dim
,
layers
=
layers
)
el
se
:
el
if
args
.
model
is
'mobile_net'
:
out
=
mobile_net
(
img
=
image_
,
class_dim
=
class_dim
)
else
:
out
=
inception_v4
(
img
=
image_
,
class_dim
=
class_dim
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label_
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
...
...
@@ -88,8 +91,10 @@ def train_parallel_do(args,
else
:
if
args
.
model
is
'se_resnext'
:
out
=
SE_ResNeXt
(
input
=
image
,
class_dim
=
class_dim
,
layers
=
layers
)
el
se
:
el
if
args
.
model
is
'mobile_net'
:
out
=
mobile_net
(
img
=
image
,
class_dim
=
class_dim
)
else
:
out
=
inception_v4
(
img
=
image
,
class_dim
=
class_dim
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
...
...
@@ -224,8 +229,10 @@ def train_parallel_exe(args,
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
if
args
.
model
is
'se_resnext'
:
out
=
SE_ResNeXt
(
input
=
image
,
class_dim
=
class_dim
,
layers
=
layers
)
el
se
:
el
if
args
.
model
is
'mobile_net'
:
out
=
mobile_net
(
img
=
image
,
class_dim
=
class_dim
)
else
:
out
=
inception_v4
(
img
=
image
,
class_dim
=
class_dim
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label
)
acc_top1
=
fluid
.
layers
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录