Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
7bcdf7ad
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7bcdf7ad
编写于
9月 13, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix xception
上级
9ecc07df
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
50 addition
and
52 deletion
+50
-52
ppcls/modeling/architectures/__init__.py
ppcls/modeling/architectures/__init__.py
+1
-0
ppcls/modeling/architectures/xception.py
ppcls/modeling/architectures/xception.py
+49
-52
未找到文件。
ppcls/modeling/architectures/__init__.py
浏览文件 @
7bcdf7ad
...
...
@@ -33,6 +33,7 @@ from .mobilenet_v3 import MobileNetV3_small_x0_35, MobileNetV3_small_x0_5, Mobil
from
.shufflenet_v2
import
ShuffleNetV2_x0_25
,
ShuffleNetV2_x0_33
,
ShuffleNetV2_x0_5
,
ShuffleNetV2
,
ShuffleNetV2_x1_5
,
ShuffleNetV2_x2_0
,
ShuffleNetV2_swish
from
.alexnet
import
AlexNet
from
.inception_v4
import
InceptionV4
from
.xception
import
Xception41
,
Xception65
,
Xception71
from
.xception_deeplab
import
Xception41_deeplab
,
Xception65_deeplab
,
Xception71_deeplab
from
.resnext101_wsl
import
ResNeXt101_32x8d_wsl
,
ResNeXt101_32x16d_wsl
,
ResNeXt101_32x32d_wsl
,
ResNeXt101_32x48d_wsl
from
.shufflenet_v2
import
ShuffleNetV2_x0_25
,
ShuffleNetV2_x0_33
,
ShuffleNetV2_x0_5
,
ShuffleNetV2
,
ShuffleNetV2_x1_5
,
ShuffleNetV2_x2_0
,
ShuffleNetV2_swish
...
...
ppcls/modeling/architectures/xception.py
浏览文件 @
7bcdf7ad
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
BatchNorm
,
Linear
from
paddle
import
ParamAttr
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddle.nn
import
Conv2d
,
BatchNorm
,
Linear
,
Dropout
from
paddle.nn
import
AdaptiveAvgPool2d
,
MaxPool2d
,
AvgPool2d
from
paddle.nn.initializer
import
Uniform
import
math
__all__
=
[
'Xception41'
,
'Xception65'
,
'Xception71'
]
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
class
ConvBNLayer
(
nn
.
Layer
):
def
__init__
(
self
,
num_channels
,
num_filters
,
...
...
@@ -18,15 +21,14 @@ class ConvBNLayer(fluid.dygraph.Layer):
name
=
None
):
super
(
ConvBNLayer
,
self
).
__init__
()
self
.
_conv
=
Conv2
D
(
num
_channels
=
num_channels
,
num_filter
s
=
num_filters
,
filter
_size
=
filter_size
,
self
.
_conv
=
Conv2
d
(
in
_channels
=
num_channels
,
out_channel
s
=
num_filters
,
kernel
_size
=
filter_size
,
stride
=
stride
,
padding
=
(
filter_size
-
1
)
//
2
,
groups
=
groups
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
weight_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
bias_attr
=
False
)
bn_name
=
"bn_"
+
name
self
.
_batch_norm
=
BatchNorm
(
...
...
@@ -43,7 +45,7 @@ class ConvBNLayer(fluid.dygraph.Layer):
return
y
class
SeparableConv
(
fluid
.
dygraph
.
Layer
):
class
SeparableConv
(
nn
.
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels
,
stride
=
1
,
name
=
None
):
super
(
SeparableConv
,
self
).
__init__
()
...
...
@@ -63,7 +65,7 @@ class SeparableConv(fluid.dygraph.Layer):
return
x
class
EntryFlowBottleneckBlock
(
fluid
.
dygraph
.
Layer
):
class
EntryFlowBottleneckBlock
(
nn
.
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels
,
...
...
@@ -73,14 +75,13 @@ class EntryFlowBottleneckBlock(fluid.dygraph.Layer):
super
(
EntryFlowBottleneckBlock
,
self
).
__init__
()
self
.
relu_first
=
relu_first
self
.
_short
=
Conv2
D
(
num
_channels
=
input_channels
,
num_filter
s
=
output_channels
,
filter
_size
=
1
,
self
.
_short
=
Conv2
d
(
in
_channels
=
input_channels
,
out_channel
s
=
output_channels
,
kernel
_size
=
1
,
stride
=
stride
,
padding
=
0
,
act
=
None
,
param_attr
=
ParamAttr
(
name
+
"_branch1_weights"
),
weight_attr
=
ParamAttr
(
name
+
"_branch1_weights"
),
bias_attr
=
False
)
self
.
_conv1
=
SeparableConv
(
input_channels
,
...
...
@@ -92,22 +93,21 @@ class EntryFlowBottleneckBlock(fluid.dygraph.Layer):
output_channels
,
stride
=
1
,
name
=
name
+
"_branch2b_weights"
)
self
.
_pool
=
Pool2D
(
pool_size
=
3
,
pool_stride
=
stride
,
pool_padding
=
1
,
pool_type
=
"max"
)
self
.
_pool
=
MaxPool2d
(
kernel_size
=
3
,
stride
=
stride
,
padding
=
1
)
def
forward
(
self
,
inputs
):
conv0
=
inputs
short
=
self
.
_short
(
inputs
)
if
self
.
relu_first
:
conv0
=
fluid
.
layers
.
relu
(
conv0
)
conv0
=
F
.
relu
(
conv0
)
conv1
=
self
.
_conv1
(
conv0
)
conv2
=
fluid
.
layers
.
relu
(
conv1
)
conv2
=
F
.
relu
(
conv1
)
conv2
=
self
.
_conv2
(
conv2
)
pool
=
self
.
_pool
(
conv2
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
pool
)
return
paddle
.
elementwise_add
(
x
=
short
,
y
=
pool
)
class
EntryFlow
(
fluid
.
dygraph
.
Layer
):
class
EntryFlow
(
nn
.
Layer
):
def
__init__
(
self
,
block_num
=
3
):
super
(
EntryFlow
,
self
).
__init__
()
...
...
@@ -154,7 +154,7 @@ class EntryFlow(fluid.dygraph.Layer):
return
x
class
MiddleFlowBottleneckBlock
(
fluid
.
dygraph
.
Layer
):
class
MiddleFlowBottleneckBlock
(
nn
.
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels
,
name
):
super
(
MiddleFlowBottleneckBlock
,
self
).
__init__
()
...
...
@@ -175,16 +175,16 @@ class MiddleFlowBottleneckBlock(fluid.dygraph.Layer):
name
=
name
+
"_branch2c_weights"
)
def
forward
(
self
,
inputs
):
conv0
=
fluid
.
layers
.
relu
(
inputs
)
conv0
=
F
.
relu
(
inputs
)
conv0
=
self
.
_conv_0
(
conv0
)
conv1
=
fluid
.
layers
.
relu
(
conv0
)
conv1
=
F
.
relu
(
conv0
)
conv1
=
self
.
_conv_1
(
conv1
)
conv2
=
fluid
.
layers
.
relu
(
conv1
)
conv2
=
F
.
relu
(
conv1
)
conv2
=
self
.
_conv_2
(
conv2
)
return
fluid
.
layers
.
elementwise_add
(
x
=
inputs
,
y
=
conv2
)
return
paddle
.
elementwise_add
(
x
=
inputs
,
y
=
conv2
)
class
MiddleFlow
(
fluid
.
dygraph
.
Layer
):
class
MiddleFlow
(
nn
.
Layer
):
def
__init__
(
self
,
block_num
=
8
):
super
(
MiddleFlow
,
self
).
__init__
()
...
...
@@ -244,19 +244,18 @@ class MiddleFlow(fluid.dygraph.Layer):
return
x
class
ExitFlowBottleneckBlock
(
fluid
.
dygraph
.
Layer
):
class
ExitFlowBottleneckBlock
(
nn
.
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels1
,
output_channels2
,
name
):
super
(
ExitFlowBottleneckBlock
,
self
).
__init__
()
self
.
_short
=
Conv2
D
(
num
_channels
=
input_channels
,
num_filter
s
=
output_channels2
,
filter
_size
=
1
,
self
.
_short
=
Conv2
d
(
in
_channels
=
input_channels
,
out_channel
s
=
output_channels2
,
kernel
_size
=
1
,
stride
=
2
,
padding
=
0
,
act
=
None
,
param_attr
=
ParamAttr
(
name
+
"_branch1_weights"
),
weight_attr
=
ParamAttr
(
name
+
"_branch1_weights"
),
bias_attr
=
False
)
self
.
_conv_1
=
SeparableConv
(
input_channels
,
...
...
@@ -268,20 +267,19 @@ class ExitFlowBottleneckBlock(fluid.dygraph.Layer):
output_channels2
,
stride
=
1
,
name
=
name
+
"_branch2b_weights"
)
self
.
_pool
=
Pool2D
(
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
pool_type
=
"max"
)
self
.
_pool
=
MaxPool2d
(
kernel_size
=
3
,
stride
=
2
,
padding
=
1
)
def
forward
(
self
,
inputs
):
short
=
self
.
_short
(
inputs
)
conv0
=
fluid
.
layers
.
relu
(
inputs
)
conv0
=
F
.
relu
(
inputs
)
conv1
=
self
.
_conv_1
(
conv0
)
conv2
=
fluid
.
layers
.
relu
(
conv1
)
conv2
=
F
.
relu
(
conv1
)
conv2
=
self
.
_conv_2
(
conv2
)
pool
=
self
.
_pool
(
conv2
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
pool
)
return
paddle
.
elementwise_add
(
x
=
short
,
y
=
pool
)
class
ExitFlow
(
fluid
.
dygraph
.
Layer
):
class
ExitFlow
(
nn
.
Layer
):
def
__init__
(
self
,
class_dim
):
super
(
ExitFlow
,
self
).
__init__
()
...
...
@@ -291,29 +289,28 @@ class ExitFlow(fluid.dygraph.Layer):
728
,
728
,
1024
,
name
=
name
+
"_1"
)
self
.
_conv_1
=
SeparableConv
(
1024
,
1536
,
stride
=
1
,
name
=
name
+
"_2"
)
self
.
_conv_2
=
SeparableConv
(
1536
,
2048
,
stride
=
1
,
name
=
name
+
"_3"
)
self
.
_pool
=
Pool2D
(
pool_type
=
"avg"
,
global_pooling
=
True
)
self
.
_pool
=
AdaptiveAvgPool2d
(
1
)
stdv
=
1.0
/
math
.
sqrt
(
2048
*
1.0
)
self
.
_out
=
Linear
(
2048
,
class_dim
,
param_attr
=
ParamAttr
(
name
=
"fc_weights"
,
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
)),
weight_attr
=
ParamAttr
(
name
=
"fc_weights"
,
initializer
=
Uniform
(
-
stdv
,
stdv
)),
bias_attr
=
ParamAttr
(
name
=
"fc_offset"
))
def
forward
(
self
,
inputs
):
conv0
=
self
.
_conv_0
(
inputs
)
conv1
=
self
.
_conv_1
(
conv0
)
conv1
=
fluid
.
layers
.
relu
(
conv1
)
conv1
=
F
.
relu
(
conv1
)
conv2
=
self
.
_conv_2
(
conv1
)
conv2
=
fluid
.
layers
.
relu
(
conv2
)
conv2
=
F
.
relu
(
conv2
)
pool
=
self
.
_pool
(
conv2
)
pool
=
fluid
.
layers
.
reshape
(
pool
,
[
0
,
-
1
])
pool
=
paddle
.
reshape
(
pool
,
[
0
,
-
1
])
out
=
self
.
_out
(
pool
)
return
out
class
Xception
(
fluid
.
dygraph
.
Layer
):
class
Xception
(
nn
.
Layer
):
def
__init__
(
self
,
entry_flow_block_num
=
3
,
middle_flow_block_num
=
8
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录