Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
08b441af
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看板
提交
08b441af
编写于
12月 20, 2017
作者:
W
wangmeng28
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add xception model for image classification
上级
0aaa92db
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
205 addition
and
2 deletion
+205
-2
image_classification/infer.py
image_classification/infer.py
+6
-1
image_classification/train.py
image_classification/train.py
+6
-1
image_classification/xception.py
image_classification/xception.py
+193
-0
未找到文件。
image_classification/infer.py
浏览文件 @
08b441af
...
@@ -26,7 +26,10 @@ def main():
...
@@ -26,7 +26,10 @@ def main():
parser
.
add_argument
(
parser
.
add_argument
(
'model'
,
'model'
,
help
=
'The model for image classification'
,
help
=
'The model for image classification'
,
choices
=
[
'alexnet'
,
'vgg13'
,
'vgg16'
,
'vgg19'
,
'resnet'
,
'googlenet'
])
choices
=
[
'alexnet'
,
'vgg13'
,
'vgg16'
,
'vgg19'
,
'resnet'
,
'googlenet'
,
'xception'
])
parser
.
add_argument
(
parser
.
add_argument
(
'params_path'
,
help
=
'The file which stores the parameters'
)
'params_path'
,
help
=
'The file which stores the parameters'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -49,6 +52,8 @@ def main():
...
@@ -49,6 +52,8 @@ def main():
out
=
resnet
.
resnet_imagenet
(
image
,
class_dim
=
CLASS_DIM
)
out
=
resnet
.
resnet_imagenet
(
image
,
class_dim
=
CLASS_DIM
)
elif
args
.
model
==
'googlenet'
:
elif
args
.
model
==
'googlenet'
:
out
,
_
,
_
=
googlenet
.
googlenet
(
image
,
class_dim
=
CLASS_DIM
)
out
,
_
,
_
=
googlenet
.
googlenet
(
image
,
class_dim
=
CLASS_DIM
)
elif
args
.
model
==
'xception'
:
out
=
xception
.
xception
(
image
,
class_dim
=
CLASS_DIM
)
# load parameters
# load parameters
with
gzip
.
open
(
args
.
params_path
,
'r'
)
as
f
:
with
gzip
.
open
(
args
.
params_path
,
'r'
)
as
f
:
...
...
image_classification/train.py
浏览文件 @
08b441af
...
@@ -19,7 +19,10 @@ def main():
...
@@ -19,7 +19,10 @@ def main():
parser
.
add_argument
(
parser
.
add_argument
(
'model'
,
'model'
,
help
=
'The model for image classification'
,
help
=
'The model for image classification'
,
choices
=
[
'alexnet'
,
'vgg13'
,
'vgg16'
,
'vgg19'
,
'resnet'
,
'googlenet'
])
choices
=
[
'alexnet'
,
'vgg13'
,
'vgg16'
,
'vgg19'
,
'resnet'
,
'googlenet'
,
'xception'
])
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
# PaddlePaddle init
# PaddlePaddle init
...
@@ -52,6 +55,8 @@ def main():
...
@@ -52,6 +55,8 @@ def main():
input
=
out2
,
label
=
lbl
,
coeff
=
0.3
)
input
=
out2
,
label
=
lbl
,
coeff
=
0.3
)
paddle
.
evaluator
.
classification_error
(
input
=
out2
,
label
=
lbl
)
paddle
.
evaluator
.
classification_error
(
input
=
out2
,
label
=
lbl
)
extra_layers
=
[
loss1
,
loss2
]
extra_layers
=
[
loss1
,
loss2
]
elif
args
.
model
==
'xception'
:
out
=
xception
.
xception
(
image
,
class_dim
=
CLASS_DIM
)
cost
=
paddle
.
layer
.
classification_cost
(
input
=
out
,
label
=
lbl
)
cost
=
paddle
.
layer
.
classification_cost
(
input
=
out
,
label
=
lbl
)
...
...
image_classification/xception.py
0 → 100644
浏览文件 @
08b441af
import
paddle.v2
as
paddle
__all__
=
[
'xception'
]
def
img_separable_conv_bn
(
name
,
input
,
num_channels
,
num_out_channels
,
filter_size
,
stride
,
padding
,
act
):
conv
=
paddle
.
networks
.
img_separable_conv
(
name
=
name
,
input
=
input
,
num_channels
=
num_channels
,
num_out_channels
=
num_out_channels
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
padding
,
act
=
paddle
.
activation
.
Linear
())
norm
=
paddle
.
layer
.
batch_norm
(
name
=
name
+
'_norm'
,
input
=
conv
,
act
=
act
)
return
norm
def
img_conv_bn
(
name
,
input
,
num_channels
,
num_filters
,
filter_size
,
stride
,
padding
,
act
):
conv
=
paddle
.
layer
.
img_conv
(
name
=
name
,
input
=
input
,
num_channels
=
num_channels
,
num_filters
=
num_filters
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
padding
,
act
=
paddle
.
activation
.
Linear
())
norm
=
paddle
.
layer
.
batch_norm
(
name
=
name
+
'_norm'
,
input
=
conv
,
act
=
act
)
return
norm
def
conv_block0
(
input
,
group
,
num_channels
,
num_filters
,
num_filters2
=
None
,
filter_size
=
3
,
pool_padding
=
0
,
entry_relu
=
True
):
if
num_filters2
is
None
:
num_filters2
=
num_filters
if
entry_relu
:
act_input
=
paddle
.
layer
.
mixed
(
input
=
paddle
.
layer
.
identity_projection
(
input
=
input
),
act
=
paddle
.
activation
.
Relu
())
else
:
act_input
=
input
conv0
=
img_separable_conv_bn
(
name
=
'xception_block{0}_conv0'
.
format
(
group
),
input
=
act_input
,
num_channels
=
num_channels
,
num_out_channels
=
num_filters
,
filter_size
=
filter_size
,
stride
=
1
,
padding
=
(
filter_size
-
1
)
/
2
,
act
=
paddle
.
activation
.
Relu
())
conv1
=
img_separable_conv_bn
(
name
=
'xception_block{0}_conv1'
.
format
(
group
),
input
=
conv0
,
num_channels
=
num_filters
,
num_out_channels
=
num_filters2
,
filter_size
=
filter_size
,
stride
=
1
,
padding
=
(
filter_size
-
1
)
/
2
,
act
=
paddle
.
activation
.
Linear
())
pool0
=
paddle
.
layer
.
img_pool
(
name
=
'xception_block{0}_pool'
.
format
(
group
),
input
=
conv1
,
pool_size
=
3
,
stride
=
2
,
padding
=
pool_padding
,
num_channels
=
num_filters2
,
pool_type
=
paddle
.
pooling
.
CudnnMax
())
shortcut
=
img_conv_bn
(
name
=
'xception_block{0}_shortcut'
.
format
(
group
),
input
=
input
,
num_channels
=
num_channels
,
num_filters
=
num_filters2
,
filter_size
=
1
,
stride
=
2
,
padding
=
0
,
act
=
paddle
.
activation
.
Linear
())
return
paddle
.
layer
.
addto
(
input
=
[
pool0
,
shortcut
],
act
=
paddle
.
activation
.
Linear
())
def
conv_block1
(
input
,
group
,
num_channels
,
num_filters
,
filter_size
=
3
):
act_input
=
paddle
.
layer
.
mixed
(
input
=
paddle
.
layer
.
identity_projection
(
input
=
input
),
act
=
paddle
.
activation
.
Relu
())
conv0
=
img_separable_conv_bn
(
name
=
'xception_block{0}_conv0'
.
format
(
group
),
input
=
act_input
,
num_channels
=
num_channels
,
num_out_channels
=
num_filters
,
filter_size
=
filter_size
,
stride
=
1
,
padding
=
(
filter_size
-
1
)
/
2
,
act
=
paddle
.
activation
.
Relu
())
conv1
=
img_separable_conv_bn
(
name
=
'xception_block{0}_conv1'
.
format
(
group
),
input
=
conv0
,
num_channels
=
num_filters
,
num_out_channels
=
num_filters
,
filter_size
=
filter_size
,
stride
=
1
,
padding
=
(
filter_size
-
1
)
/
2
,
act
=
paddle
.
activation
.
Relu
())
conv2
=
img_separable_conv_bn
(
name
=
'xception_block{0}_conv2'
.
format
(
group
),
input
=
conv1
,
num_channels
=
num_filters
,
num_out_channels
=
num_filters
,
filter_size
=
filter_size
,
stride
=
1
,
padding
=
(
filter_size
-
1
)
/
2
,
act
=
paddle
.
activation
.
Linear
())
shortcut
=
input
return
paddle
.
layer
.
addto
(
input
=
[
conv2
,
shortcut
],
act
=
paddle
.
activation
.
Linear
())
def
xception
(
input
,
class_dim
):
conv
=
img_conv_bn
(
name
=
'xception_conv0'
,
input
=
input
,
num_channels
=
3
,
num_filters
=
32
,
filter_size
=
3
,
stride
=
2
,
padding
=
1
,
act
=
paddle
.
activation
.
Relu
())
conv
=
img_conv_bn
(
name
=
'xception_conv1'
,
input
=
conv
,
num_channels
=
32
,
num_filters
=
64
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
act
=
paddle
.
activation
.
Relu
())
conv
=
conv_block0
(
input
=
conv
,
group
=
2
,
num_channels
=
64
,
num_filters
=
128
,
entry_relu
=
False
)
conv
=
conv_block0
(
input
=
conv
,
group
=
3
,
num_channels
=
128
,
num_filters
=
256
)
conv
=
conv_block0
(
input
=
conv
,
group
=
4
,
num_channels
=
256
,
num_filters
=
728
)
for
group
in
range
(
5
,
13
):
conv
=
conv_block1
(
input
=
conv
,
group
=
group
,
num_channels
=
728
,
num_filters
=
728
)
conv
=
conv_block0
(
input
=
conv
,
group
=
13
,
num_channels
=
728
,
num_filters
=
728
,
num_filters2
=
1024
)
conv
=
img_separable_conv_bn
(
name
=
'xception_conv14'
,
input
=
conv
,
num_channels
=
1024
,
num_out_channels
=
1536
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
act
=
paddle
.
activation
.
Relu
())
conv
=
img_separable_conv_bn
(
name
=
'xception_conv15'
,
input
=
conv
,
num_channels
=
1536
,
num_out_channels
=
2048
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
act
=
paddle
.
activation
.
Relu
())
pool
=
paddle
.
layer
.
img_pool
(
name
=
'xception_global_pool'
,
input
=
conv
,
pool_size
=
7
,
stride
=
1
,
num_channels
=
2048
,
pool_type
=
paddle
.
pooling
.
CudnnAvg
())
out
=
paddle
.
layer
.
fc
(
name
=
'xception_fc'
,
input
=
pool
,
size
=
class_dim
,
act
=
paddle
.
activation
.
Softmax
())
return
out
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录