Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
f85ced36
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看板
提交
f85ced36
编写于
6月 28, 2020
作者:
W
wqz960
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
0dfe15d2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
68 addition
and
78 deletion
+68
-78
ppcls/modeling/architectures/darknet.py
ppcls/modeling/architectures/darknet.py
+0
-3
ppcls/modeling/architectures/efficientnet.py
ppcls/modeling/architectures/efficientnet.py
+35
-37
ppcls/modeling/architectures/googlenet.py
ppcls/modeling/architectures/googlenet.py
+0
-2
ppcls/modeling/architectures/inception_v4.py
ppcls/modeling/architectures/inception_v4.py
+3
-6
ppcls/modeling/architectures/resnext101_wsl.py
ppcls/modeling/architectures/resnext101_wsl.py
+7
-7
ppcls/modeling/architectures/squeezenet.py
ppcls/modeling/architectures/squeezenet.py
+23
-23
未找到文件。
ppcls/modeling/architectures/darknet.py
浏览文件 @
f85ced36
# coding=UTF-8
import
numpy
as
np
import
argparse
import
paddle
...
...
@@ -11,8 +10,6 @@ from paddle.fluid.dygraph.base import to_variable
from
paddle.fluid
import
framework
import
math
import
sys
import
time
__all__
=
[
"DarkNet53"
]
...
...
ppcls/modeling/architectures/efficientnet.py
浏览文件 @
f85ced36
...
...
@@ -11,8 +11,6 @@ from paddle.fluid.dygraph.base import to_variable
from
paddle.fluid
import
framework
import
math
import
sys
import
time
import
collections
import
re
import
copy
...
...
@@ -260,7 +258,7 @@ def _drop_connect(inputs, prob, is_test):
return
output
class
conv2d
(
fluid
.
dygraph
.
Layer
):
class
Conv2ds
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels
,
...
...
@@ -274,7 +272,7 @@ class conv2d(fluid.dygraph.Layer):
padding_type
=
None
,
model_name
=
None
,
cur_stage
=
None
):
super
(
conv2d
,
self
).
__init__
()
super
(
Conv2ds
,
self
).
__init__
()
param_attr
,
bias_attr
=
initial_type
(
name
=
name
,
use_bias
=
use_bias
)
...
...
@@ -316,10 +314,6 @@ class conv2d(fluid.dygraph.Layer):
padding
=
padding
,
param_attr
=
param_attr
,
bias_attr
=
bias_attr
)
# debug:
self
.
stride
=
stride
self
.
filter_size
=
filter_size
self
.
inps
=
inps
def
forward
(
self
,
inputs
):
x
=
self
.
_conv
(
inputs
)
...
...
@@ -347,7 +341,7 @@ class ConvBNLayer(fluid.dygraph.Layer):
cur_stage
=
None
):
super
(
ConvBNLayer
,
self
).
__init__
()
self
.
_conv
=
conv2d
(
self
.
_conv
=
Conv2ds
(
input_channels
=
input_channels
,
output_channels
=
output_channels
,
filter_size
=
filter_size
,
...
...
@@ -383,7 +377,7 @@ class ConvBNLayer(fluid.dygraph.Layer):
return
self
.
_conv
(
inputs
)
class
Expand
_Conv_
Norm
(
fluid
.
dygraph
.
Layer
):
class
Expand
Conv
Norm
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
block_args
,
...
...
@@ -391,7 +385,7 @@ class Expand_Conv_Norm(fluid.dygraph.Layer):
name
=
None
,
model_name
=
None
,
cur_stage
=
None
):
super
(
Expand
_Conv_
Norm
,
self
).
__init__
()
super
(
Expand
Conv
Norm
,
self
).
__init__
()
self
.
oup
=
block_args
.
input_filters
*
block_args
.
expand_ratio
self
.
expand_ratio
=
block_args
.
expand_ratio
...
...
@@ -478,7 +472,7 @@ class Project_Conv_Norm(fluid.dygraph.Layer):
return
self
.
_conv
(
inputs
)
class
S
e_
Block
(
fluid
.
dygraph
.
Layer
):
class
S
E
Block
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
num_squeezed_channels
,
...
...
@@ -487,11 +481,11 @@ class Se_Block(fluid.dygraph.Layer):
name
=
None
,
model_name
=
None
,
cur_stage
=
None
):
super
(
S
e_
Block
,
self
).
__init__
()
super
(
S
E
Block
,
self
).
__init__
()
self
.
_pool
=
Pool2D
(
pool_type
=
"avg"
,
global_pooling
=
True
,
use_cudnn
=
False
)
self
.
_conv1
=
conv2d
(
self
.
_conv1
=
Conv2ds
(
input_channels
,
num_squeezed_channels
,
1
,
...
...
@@ -500,7 +494,7 @@ class Se_Block(fluid.dygraph.Layer):
act
=
"swish"
,
name
=
name
+
"_se_reduce"
)
self
.
_conv2
=
conv2d
(
self
.
_conv2
=
Conv2ds
(
num_squeezed_channels
,
oup
,
1
,
...
...
@@ -517,7 +511,7 @@ class Se_Block(fluid.dygraph.Layer):
return
fluid
.
layers
.
elementwise_mul
(
inputs
,
x
)
class
Mb
_Conv_
Block
(
fluid
.
dygraph
.
Layer
):
class
Mb
Conv
Block
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
block_args
,
...
...
@@ -528,7 +522,7 @@ class Mb_Conv_Block(fluid.dygraph.Layer):
is_test
=
False
,
model_name
=
None
,
cur_stage
=
None
):
super
(
Mb
_Conv_
Block
,
self
).
__init__
()
super
(
Mb
Conv
Block
,
self
).
__init__
()
oup
=
block_args
.
input_filters
*
block_args
.
expand_ratio
self
.
block_args
=
block_args
...
...
@@ -540,7 +534,7 @@ class Mb_Conv_Block(fluid.dygraph.Layer):
self
.
is_test
=
is_test
if
self
.
expand_ratio
!=
1
:
self
.
_ecn
=
Expand
_Conv_
Norm
(
self
.
_ecn
=
Expand
Conv
Norm
(
input_channels
,
block_args
,
padding_type
=
padding_type
,
...
...
@@ -559,7 +553,7 @@ class Mb_Conv_Block(fluid.dygraph.Layer):
if
self
.
has_se
:
num_squeezed_channels
=
max
(
1
,
int
(
block_args
.
input_filters
*
block_args
.
se_ratio
))
self
.
_se
=
S
e_
Block
(
self
.
_se
=
S
E
Block
(
input_channels
*
block_args
.
expand_ratio
,
num_squeezed_channels
,
oup
,
...
...
@@ -587,14 +581,16 @@ class Mb_Conv_Block(fluid.dygraph.Layer):
if
self
.
has_se
:
x
=
self
.
_se
(
x
)
x
=
self
.
_pcn
(
x
)
if
self
.
id_skip
and
self
.
block_args
.
stride
==
1
and
self
.
block_args
.
input_filters
==
self
.
block_args
.
output_filters
:
if
self
.
id_skip
and
\
self
.
block_args
.
stride
==
1
and
\
self
.
block_args
.
input_filters
==
self
.
block_args
.
output_filters
:
if
self
.
drop_connect_rate
:
x
=
_drop_connect
(
x
,
self
.
drop_connect_rate
,
self
.
is_test
)
x
=
fluid
.
layers
.
elementwise_add
(
x
,
inputs
)
return
x
class
Conv
_Stem_
Norm
(
fluid
.
dygraph
.
Layer
):
class
Conv
Stem
Norm
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
padding_type
,
...
...
@@ -602,7 +598,7 @@ class Conv_Stem_Norm(fluid.dygraph.Layer):
name
=
None
,
model_name
=
None
,
cur_stage
=
None
):
super
(
Conv
_Stem_
Norm
,
self
).
__init__
()
super
(
Conv
Stem
Norm
,
self
).
__init__
()
output_channels
=
round_filters
(
32
,
_global_params
)
self
.
_conv
=
ConvBNLayer
(
...
...
@@ -622,7 +618,7 @@ class Conv_Stem_Norm(fluid.dygraph.Layer):
return
self
.
_conv
(
inputs
)
class
Extract
_
Features
(
fluid
.
dygraph
.
Layer
):
class
ExtractFeatures
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
_block_args
,
...
...
@@ -631,11 +627,11 @@ class Extract_Features(fluid.dygraph.Layer):
use_se
,
is_test
,
model_name
=
None
):
super
(
Extract
_
Features
,
self
).
__init__
()
super
(
ExtractFeatures
,
self
).
__init__
()
self
.
_global_params
=
_global_params
self
.
_conv_stem
=
Conv
_Stem_
Norm
(
self
.
_conv_stem
=
Conv
Stem
Norm
(
input_channels
,
padding_type
=
padding_type
,
_global_params
=
_global_params
,
...
...
@@ -673,7 +669,7 @@ class Extract_Features(fluid.dygraph.Layer):
_mc_block
=
self
.
add_sublayer
(
"_blocks."
+
str
(
idx
)
+
"."
,
Mb
_Conv_
Block
(
Mb
Conv
Block
(
block_args
.
input_filters
,
block_args
=
block_args
,
padding_type
=
padding_type
,
...
...
@@ -693,7 +689,7 @@ class Extract_Features(fluid.dygraph.Layer):
drop_connect_rate
*=
float
(
idx
)
/
block_size
_mc_block
=
self
.
add_sublayer
(
"block."
+
str
(
idx
)
+
"."
,
Mb
_Conv_
Block
(
Mb
Conv
Block
(
block_args
.
input_filters
,
block_args
,
padding_type
=
padding_type
,
...
...
@@ -733,7 +729,7 @@ class EfficientNet(fluid.dygraph.Layer):
self
.
use_se
=
use_se
self
.
is_test
=
is_test
self
.
_ef
=
Extract
_
Features
(
self
.
_ef
=
ExtractFeatures
(
3
,
self
.
_block_args
,
self
.
_global_params
,
...
...
@@ -799,7 +795,7 @@ def EfficientNetB0_small(is_test=True,
use_se
=
False
):
model
=
EfficientNet
(
name
=
'b0'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -812,7 +808,7 @@ def EfficientNetB0(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b0'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -825,7 +821,7 @@ def EfficientNetB1(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b1'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -838,7 +834,7 @@ def EfficientNetB2(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b2'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -851,7 +847,7 @@ def EfficientNetB3(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b3'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -864,7 +860,7 @@ def EfficientNetB4(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b4'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -877,7 +873,7 @@ def EfficientNetB5(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b5'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -890,7 +886,7 @@ def EfficientNetB6(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b6'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
...
...
@@ -903,8 +899,10 @@ def EfficientNetB7(is_test=False,
use_se
=
True
):
model
=
EfficientNet
(
name
=
'b7'
,
is_test
=
True
,
is_test
=
is_test
,
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
use_se
)
return
model
\ No newline at end of file
ppcls/modeling/architectures/googlenet.py
浏览文件 @
f85ced36
import
numpy
as
np
import
argparse
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
...
...
ppcls/modeling/architectures/inception_v4.py
浏览文件 @
f85ced36
...
...
@@ -8,10 +8,7 @@ from paddle.fluid.dygraph.nn import Conv2D, Pool2D, BatchNorm, Linear, Dropout
from
paddle.fluid.dygraph.base
import
to_variable
from
paddle.fluid
import
framework
import
math
import
sys
import
time
__all__
=
[
"InceptionV4"
]
...
...
@@ -380,9 +377,9 @@ class InceptionC(fluid.dygraph.Layer):
return
concat
class
InceptionV4
_
DY
(
fluid
.
dygraph
.
Layer
):
class
InceptionV4DY
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
class_dim
=
1000
):
super
(
InceptionV4
_
DY
,
self
).
__init__
()
super
(
InceptionV4DY
,
self
).
__init__
()
self
.
_inception_stem
=
Inception_Stem
()
self
.
_inceptionA_1
=
InceptionA
(
name
=
"1"
)
...
...
@@ -445,5 +442,5 @@ class InceptionV4_DY(fluid.dygraph.Layer):
def
InceptionV4
():
model
=
InceptionV4
_
DY
()
model
=
InceptionV4DY
()
return
model
ppcls/modeling/architectures/resnext101_wsl.py
浏览文件 @
f85ced36
...
...
@@ -96,9 +96,9 @@ class Bottleneck_Block(fluid.dygraph.Layer):
y
=
self
.
_short
(
inputs
)
return
fluid
.
layers
.
elementwise_add
(
x
,
y
,
act
=
"relu"
)
class
ResNeXt101
_wsl
(
fluid
.
dygraph
.
Layer
):
class
ResNeXt101
WSL
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
layers
=
101
,
cardinality
=
32
,
width
=
48
,
class_dim
=
1000
):
super
(
ResNeXt101
_wsl
,
self
).
__init__
()
super
(
ResNeXt101
WSL
,
self
).
__init__
()
self
.
class_dim
=
class_dim
...
...
@@ -240,17 +240,17 @@ class ResNeXt101_wsl(fluid.dygraph.Layer):
return
x
def
ResNeXt101_32x8d_wsl
():
model
=
ResNeXt101
_wsl
(
cardinality
=
32
,
width
=
8
)
model
=
ResNeXt101
WSL
(
cardinality
=
32
,
width
=
8
)
return
model
def
ResNeXt101_32x16d_wsl
():
model
=
ResNeXt101
_wsl
(
cardinality
=
32
,
width
=
16
)
model
=
ResNeXt101
WSL
(
cardinality
=
32
,
width
=
16
)
return
model
def
ResNeXt101_32x32d_wsl
():
model
=
ResNeXt101
_wsl
(
cardinality
=
32
,
width
=
32
)
model
=
ResNeXt101
WSL
(
cardinality
=
32
,
width
=
32
)
return
model
def
ResNeXt101_32x48d_wsl
():
model
=
ResNeXt101
_wsl
(
cardinality
=
32
,
width
=
48
)
return
model
model
=
ResNeXt101
WSL
(
cardinality
=
32
,
width
=
48
)
return
model
\ No newline at end of file
ppcls/modeling/architectures/squeezenet.py
浏览文件 @
f85ced36
...
...
@@ -15,14 +15,14 @@ import time
__all__
=
[
"SqueezeNet1_0"
,
"SqueezeNet1_1"
]
class
Make
_Fire_
Conv
(
fluid
.
dygraph
.
Layer
):
class
Make
Fire
Conv
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels
,
filter_size
,
padding
=
0
,
name
=
None
):
super
(
Make
_Fire_
Conv
,
self
).
__init__
()
super
(
Make
Fire
Conv
,
self
).
__init__
()
self
.
_conv
=
Conv2D
(
input_channels
,
output_channels
,
filter_size
,
...
...
@@ -34,23 +34,23 @@ class Make_Fire_Conv(fluid.dygraph.Layer):
def
forward
(
self
,
inputs
):
return
self
.
_conv
(
inputs
)
class
Make
_
Fire
(
fluid
.
dygraph
.
Layer
):
class
MakeFire
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
input_channels
,
squeeze_channels
,
expand1x1_channels
,
expand3x3_channels
,
name
=
None
):
super
(
Make
_
Fire
,
self
).
__init__
()
self
.
_conv
=
Make
_Fire_
Conv
(
input_channels
,
super
(
MakeFire
,
self
).
__init__
()
self
.
_conv
=
Make
Fire
Conv
(
input_channels
,
squeeze_channels
,
1
,
name
=
name
+
"_squeeze1x1"
)
self
.
_conv_path1
=
Make
_Fire_
Conv
(
squeeze_channels
,
self
.
_conv_path1
=
Make
Fire
Conv
(
squeeze_channels
,
expand1x1_channels
,
1
,
name
=
name
+
"_expand1x1"
)
self
.
_conv_path2
=
Make
_Fire_
Conv
(
squeeze_channels
,
self
.
_conv_path2
=
Make
Fire
Conv
(
squeeze_channels
,
expand3x3_channels
,
3
,
padding
=
1
,
...
...
@@ -78,16 +78,16 @@ class SqueezeNet(fluid.dygraph.Layer):
self
.
_pool
=
Pool2D
(
pool_size
=
3
,
pool_stride
=
2
,
pool_type
=
"max"
)
self
.
_conv1
=
Make
_
Fire
(
96
,
16
,
64
,
64
,
name
=
"fire2"
)
self
.
_conv2
=
Make
_
Fire
(
128
,
16
,
64
,
64
,
name
=
"fire3"
)
self
.
_conv3
=
Make
_
Fire
(
128
,
32
,
128
,
128
,
name
=
"fire4"
)
self
.
_conv1
=
MakeFire
(
96
,
16
,
64
,
64
,
name
=
"fire2"
)
self
.
_conv2
=
MakeFire
(
128
,
16
,
64
,
64
,
name
=
"fire3"
)
self
.
_conv3
=
MakeFire
(
128
,
32
,
128
,
128
,
name
=
"fire4"
)
self
.
_conv4
=
Make
_
Fire
(
256
,
32
,
128
,
128
,
name
=
"fire5"
)
self
.
_conv5
=
Make
_
Fire
(
256
,
48
,
192
,
192
,
name
=
"fire6"
)
self
.
_conv6
=
Make
_
Fire
(
384
,
48
,
192
,
192
,
name
=
"fire7"
)
self
.
_conv7
=
Make
_
Fire
(
384
,
64
,
256
,
256
,
name
=
"fire8"
)
self
.
_conv4
=
MakeFire
(
256
,
32
,
128
,
128
,
name
=
"fire5"
)
self
.
_conv5
=
MakeFire
(
256
,
48
,
192
,
192
,
name
=
"fire6"
)
self
.
_conv6
=
MakeFire
(
384
,
48
,
192
,
192
,
name
=
"fire7"
)
self
.
_conv7
=
MakeFire
(
384
,
64
,
256
,
256
,
name
=
"fire8"
)
self
.
_conv8
=
Make
_
Fire
(
512
,
64
,
256
,
256
,
name
=
"fire9"
)
self
.
_conv8
=
MakeFire
(
512
,
64
,
256
,
256
,
name
=
"fire9"
)
else
:
self
.
_conv
=
Conv2D
(
3
,
64
,
...
...
@@ -100,16 +100,16 @@ class SqueezeNet(fluid.dygraph.Layer):
self
.
_pool
=
Pool2D
(
pool_size
=
3
,
pool_stride
=
2
,
pool_type
=
"max"
)
self
.
_conv1
=
Make
_
Fire
(
64
,
16
,
64
,
64
,
name
=
"fire2"
)
self
.
_conv2
=
Make
_
Fire
(
128
,
16
,
64
,
64
,
name
=
"fire3"
)
self
.
_conv1
=
MakeFire
(
64
,
16
,
64
,
64
,
name
=
"fire2"
)
self
.
_conv2
=
MakeFire
(
128
,
16
,
64
,
64
,
name
=
"fire3"
)
self
.
_conv3
=
Make
_
Fire
(
128
,
32
,
128
,
128
,
name
=
"fire4"
)
self
.
_conv4
=
Make
_
Fire
(
256
,
32
,
128
,
128
,
name
=
"fire5"
)
self
.
_conv3
=
MakeFire
(
128
,
32
,
128
,
128
,
name
=
"fire4"
)
self
.
_conv4
=
MakeFire
(
256
,
32
,
128
,
128
,
name
=
"fire5"
)
self
.
_conv5
=
Make
_
Fire
(
256
,
48
,
192
,
192
,
name
=
"fire6"
)
self
.
_conv6
=
Make
_
Fire
(
384
,
48
,
192
,
192
,
name
=
"fire7"
)
self
.
_conv7
=
Make
_
Fire
(
384
,
64
,
256
,
256
,
name
=
"fire8"
)
self
.
_conv8
=
Make
_
Fire
(
512
,
64
,
256
,
256
,
name
=
"fire9"
)
self
.
_conv5
=
MakeFire
(
256
,
48
,
192
,
192
,
name
=
"fire6"
)
self
.
_conv6
=
MakeFire
(
384
,
48
,
192
,
192
,
name
=
"fire7"
)
self
.
_conv7
=
MakeFire
(
384
,
64
,
256
,
256
,
name
=
"fire8"
)
self
.
_conv8
=
MakeFire
(
512
,
64
,
256
,
256
,
name
=
"fire9"
)
self
.
_drop
=
Dropout
(
p
=
0.5
)
self
.
_conv9
=
Conv2D
(
512
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录