Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
54f7dd74
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
116
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看板
提交
54f7dd74
编写于
1月 16, 2023
作者:
weixin_46524038
提交者:
cuicheng01
1月 31, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
watermark
上级
60149626
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
75 addition
and
11 deletion
+75
-11
ppcls/arch/backbone/__init__.py
ppcls/arch/backbone/__init__.py
+1
-0
ppcls/arch/backbone/model_zoo/efficientnet.py
ppcls/arch/backbone/model_zoo/efficientnet.py
+28
-11
ppcls/arch/backbone/variant_models/efficientnet_variant.py
ppcls/arch/backbone/variant_models/efficientnet_variant.py
+46
-0
未找到文件。
ppcls/arch/backbone/__init__.py
浏览文件 @
54f7dd74
...
...
@@ -79,6 +79,7 @@ from .variant_models.resnet_variant import ResNet50_adaptive_max_pool2d
from
.variant_models.vgg_variant
import
VGG19Sigmoid
from
.variant_models.pp_lcnet_variant
import
PPLCNet_x2_5_Tanh
from
.variant_models.pp_lcnetv2_variant
import
PPLCNetV2_base_ShiTu
from
.variant_models.efficientnet_variant
import
EfficientNetB3_watermark
from
.model_zoo.adaface_ir_net
import
AdaFace_IR_18
,
AdaFace_IR_34
,
AdaFace_IR_50
,
AdaFace_IR_101
,
AdaFace_IR_152
,
AdaFace_IR_SE_50
,
AdaFace_IR_SE_101
,
AdaFace_IR_SE_152
,
AdaFace_IR_SE_200
from
.model_zoo.wideresnet
import
WideResNet
from
.model_zoo.uniformer
import
UniFormer_small
,
UniFormer_small_plus
,
UniFormer_small_plus_dim64
,
UniFormer_base
,
UniFormer_base_ls
...
...
ppcls/arch/backbone/model_zoo/efficientnet.py
浏览文件 @
54f7dd74
...
...
@@ -26,6 +26,7 @@ import collections
import
re
import
copy
from
..base.theseus_layer
import
TheseusLayer
from
....utils.save_load
import
load_dygraph_pretrain
,
load_dygraph_pretrain_from_url
MODEL_URLS
=
{
...
...
@@ -289,7 +290,7 @@ def _drop_connect(inputs, prob, is_test):
return
output
class
Conv2ds
(
nn
.
Layer
):
class
Conv2ds
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
output_channels
,
...
...
@@ -361,13 +362,14 @@ class Conv2ds(nn.Layer):
return
x
class
ConvBNLayer
(
nn
.
Layer
):
class
ConvBNLayer
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
filter_size
,
output_channels
,
stride
=
1
,
num_groups
=
1
,
global_params
=
None
,
padding_type
=
"SAME"
,
conv_act
=
None
,
bn_act
=
"swish"
,
...
...
@@ -396,12 +398,13 @@ class ConvBNLayer(nn.Layer):
if
use_bn
is
True
:
bn_name
=
name
+
bn_name
param_attr
,
bias_attr
=
init_batch_norm_layer
(
bn_name
)
epsilon
=
global_params
.
batch_norm_epsilon
self
.
_bn
=
BatchNorm
(
num_channels
=
output_channels
,
act
=
bn_act
,
momentum
=
0.99
,
epsilon
=
0.001
,
epsilon
=
epsilon
,
moving_mean_name
=
bn_name
+
"_mean"
,
moving_variance_name
=
bn_name
+
"_variance"
,
param_attr
=
param_attr
,
...
...
@@ -416,10 +419,11 @@ class ConvBNLayer(nn.Layer):
return
self
.
_conv
(
inputs
)
class
ExpandConvNorm
(
nn
.
Layer
):
class
ExpandConvNorm
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
block_args
,
global_params
,
padding_type
,
name
=
None
,
model_name
=
None
,
...
...
@@ -434,6 +438,7 @@ class ExpandConvNorm(nn.Layer):
input_channels
,
1
,
self
.
oup
,
global_params
=
global_params
,
bn_act
=
None
,
padding_type
=
padding_type
,
name
=
name
,
...
...
@@ -449,10 +454,11 @@ class ExpandConvNorm(nn.Layer):
return
inputs
class
DepthwiseConvNorm
(
nn
.
Layer
):
class
DepthwiseConvNorm
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
block_args
,
global_params
,
padding_type
,
name
=
None
,
model_name
=
None
,
...
...
@@ -471,6 +477,7 @@ class DepthwiseConvNorm(nn.Layer):
oup
,
self
.
s
,
num_groups
=
input_channels
,
global_params
=
global_params
,
bn_act
=
None
,
padding_type
=
padding_type
,
name
=
name
,
...
...
@@ -483,10 +490,11 @@ class DepthwiseConvNorm(nn.Layer):
return
self
.
_conv
(
inputs
)
class
ProjectConvNorm
(
nn
.
Layer
):
class
ProjectConvNorm
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
block_args
,
global_params
,
padding_type
,
name
=
None
,
model_name
=
None
,
...
...
@@ -499,6 +507,7 @@ class ProjectConvNorm(nn.Layer):
input_channels
,
1
,
final_oup
,
global_params
=
global_params
,
bn_act
=
None
,
padding_type
=
padding_type
,
name
=
name
,
...
...
@@ -511,7 +520,7 @@ class ProjectConvNorm(nn.Layer):
return
self
.
_conv
(
inputs
)
class
SEBlock
(
nn
.
Layer
):
class
SEBlock
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
num_squeezed_channels
,
...
...
@@ -549,10 +558,11 @@ class SEBlock(nn.Layer):
return
out
class
MbConvBlock
(
nn
.
Layer
):
class
MbConvBlock
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
block_args
,
global_params
,
padding_type
,
use_se
,
name
=
None
,
...
...
@@ -573,6 +583,7 @@ class MbConvBlock(nn.Layer):
self
.
_ecn
=
ExpandConvNorm
(
input_channels
,
block_args
,
global_params
,
padding_type
=
padding_type
,
name
=
name
,
model_name
=
model_name
,
...
...
@@ -581,6 +592,7 @@ class MbConvBlock(nn.Layer):
self
.
_dcn
=
DepthwiseConvNorm
(
input_channels
*
block_args
.
expand_ratio
,
block_args
,
global_params
,
padding_type
=
padding_type
,
name
=
name
,
model_name
=
model_name
,
...
...
@@ -601,6 +613,7 @@ class MbConvBlock(nn.Layer):
self
.
_pcn
=
ProjectConvNorm
(
input_channels
*
block_args
.
expand_ratio
,
block_args
,
global_params
,
padding_type
=
padding_type
,
name
=
name
,
model_name
=
model_name
,
...
...
@@ -627,7 +640,7 @@ class MbConvBlock(nn.Layer):
return
x
class
ConvStemNorm
(
nn
.
Layer
):
class
ConvStemNorm
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
padding_type
,
...
...
@@ -643,6 +656,7 @@ class ConvStemNorm(nn.Layer):
filter_size
=
3
,
output_channels
=
output_channels
,
stride
=
2
,
global_params
=
_global_params
,
bn_act
=
None
,
padding_type
=
padding_type
,
name
=
""
,
...
...
@@ -655,7 +669,7 @@ class ConvStemNorm(nn.Layer):
return
self
.
_conv
(
inputs
)
class
ExtractFeatures
(
nn
.
Layer
):
class
ExtractFeatures
(
Theseus
Layer
):
def
__init__
(
self
,
input_channels
,
_block_args
,
...
...
@@ -708,6 +722,7 @@ class ExtractFeatures(nn.Layer):
MbConvBlock
(
block_args
.
input_filters
,
block_args
=
block_args
,
global_params
=
_global_params
,
padding_type
=
padding_type
,
use_se
=
use_se
,
name
=
"_blocks."
+
str
(
idx
)
+
"."
,
...
...
@@ -728,6 +743,7 @@ class ExtractFeatures(nn.Layer):
MbConvBlock
(
block_args
.
input_filters
,
block_args
,
global_params
=
_global_params
,
padding_type
=
padding_type
,
use_se
=
use_se
,
name
=
"_blocks."
+
str
(
idx
)
+
"."
,
...
...
@@ -746,7 +762,7 @@ class ExtractFeatures(nn.Layer):
return
x
class
EfficientNet
(
nn
.
Layer
):
class
EfficientNet
(
Theseus
Layer
):
def
__init__
(
self
,
name
=
"b0"
,
padding_type
=
"SAME"
,
...
...
@@ -789,6 +805,7 @@ class EfficientNet(nn.Layer):
oup
,
1
,
output_channels
,
global_params
=
self
.
_global_params
,
bn_act
=
"swish"
,
padding_type
=
self
.
padding_type
,
name
=
""
,
...
...
ppcls/arch/backbone/variant_models/efficientnet_variant.py
0 → 100644
浏览文件 @
54f7dd74
import
paddle
import
paddle.nn
as
nn
from
paddle.nn
import
Sigmoid
from
paddle.nn
import
Tanh
from
..model_zoo.efficientnet
import
EfficientNetB3
,
_load_pretrained
MODEL_URLS
=
{
"EfficientNetB3_watermark"
:
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB3_watermark_pretrained.pdparams"
}
__all__
=
list
(
MODEL_URLS
.
keys
())
def
EfficientNetB3_watermark
(
padding_type
=
'DYNAMIC'
,
override_params
=
{
"batch_norm_epsilon"
:
0.00001
},
use_se
=
True
,
pretrained
=
False
,
use_ssld
=
False
,
**
kwargs
):
def
replace_function
(
_fc
,
pattern
):
classifier
=
nn
.
Sequential
(
# 1536 is the orginal in_features
nn
.
Linear
(
in_features
=
1536
,
out_features
=
625
),
nn
.
ReLU
(),
# ReLu to be the activation function
nn
.
Dropout
(
p
=
0.3
),
nn
.
Linear
(
in_features
=
625
,
out_features
=
256
),
nn
.
ReLU
(),
nn
.
Linear
(
in_features
=
256
,
out_features
=
2
),
)
return
classifier
pattern
=
"_fc"
model
=
EfficientNetB3
(
padding_type
=
padding_type
,
override_params
=
override_params
,
use_se
=
True
,
pretrained
=
False
,
use_ssld
=
False
,
**
kwargs
)
model
.
upgrade_sublayer
(
pattern
,
replace_function
)
_load_pretrained
(
pretrained
,
model
,
MODEL_URLS
[
"EfficientNetB3_watermark"
],
use_ssld
)
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录