Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
fb7c750c
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看板
未验证
提交
fb7c750c
编写于
2月 06, 2021
作者:
L
littletomatodonkey
提交者:
GitHub
2月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update distilled_vision_transformer.py
上级
e08e45e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
94 addition
and
25 deletion
+94
-25
ppcls/modeling/architectures/distilled_vision_transformer.py
ppcls/modeling/architectures/distilled_vision_transformer.py
+94
-25
未找到文件。
ppcls/modeling/architectures/distilled_vision_transformer.py
浏览文件 @
fb7c750c
...
...
@@ -16,7 +16,6 @@ import paddle
import
paddle.nn
as
nn
from
.vision_transformer
import
VisionTransformer
,
Identity
,
trunc_normal_
,
zeros_
__all__
=
[
'DeiT_tiny_patch16_224'
,
'DeiT_small_patch16_224'
,
'DeiT_base_patch16_224'
,
'DeiT_tiny_distilled_patch16_224'
,
'DeiT_small_distilled_patch16_224'
,
...
...
@@ -26,14 +25,33 @@ __all__ = [
class
DistilledVisionTransformer
(
VisionTransformer
):
def
__init__
(
self
,
img_size
=
224
,
patch_size
=
16
,
class_dim
=
1000
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
False
,
norm_layer
=
'nn.LayerNorm'
,
epsilon
=
1e-5
,
def
__init__
(
self
,
img_size
=
224
,
patch_size
=
16
,
class_dim
=
1000
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
False
,
norm_layer
=
'nn.LayerNorm'
,
epsilon
=
1e-5
,
**
kwargs
):
super
().
__init__
(
img_size
=
img_size
,
patch_size
=
patch_size
,
class_dim
=
class_dim
,
embed_dim
=
embed_dim
,
depth
=
depth
,
num_heads
=
num_heads
,
mlp_ratio
=
mlp_ratio
,
qkv_bias
=
qkv_bias
,
norm_layer
=
norm_layer
,
epsilon
=
epsilon
,
**
kwargs
)
super
().
__init__
(
img_size
=
img_size
,
patch_size
=
patch_size
,
class_dim
=
class_dim
,
embed_dim
=
embed_dim
,
depth
=
depth
,
num_heads
=
num_heads
,
mlp_ratio
=
mlp_ratio
,
qkv_bias
=
qkv_bias
,
norm_layer
=
norm_layer
,
epsilon
=
epsilon
,
**
kwargs
)
self
.
pos_embed
=
self
.
create_parameter
(
shape
=
(
1
,
self
.
patch_embed
.
num_patches
+
2
,
self
.
embed_dim
),
default_initializer
=
zeros_
)
shape
=
(
1
,
self
.
patch_embed
.
num_patches
+
2
,
self
.
embed_dim
),
default_initializer
=
zeros_
)
self
.
add_parameter
(
"pos_embed"
,
self
.
pos_embed
)
self
.
dist_token
=
self
.
create_parameter
(
...
...
@@ -41,14 +59,15 @@ class DistilledVisionTransformer(VisionTransformer):
self
.
add_parameter
(
"cls_token"
,
self
.
cls_token
)
self
.
head_dist
=
nn
.
Linear
(
self
.
embed_dim
,
self
.
class_dim
)
if
self
.
class_dim
>
0
else
Identity
()
self
.
embed_dim
,
self
.
class_dim
)
if
self
.
class_dim
>
0
else
Identity
()
trunc_normal_
(
self
.
dist_token
)
trunc_normal_
(
self
.
pos_embed
)
self
.
head_dist
.
apply
(
self
.
_init_weights
)
def
forward_features
(
self
,
x
):
B
=
x
.
shape
[
0
]
B
=
paddle
.
shape
(
x
)
[
0
]
x
=
self
.
patch_embed
(
x
)
cls_tokens
=
self
.
cls_token
.
expand
((
B
,
-
1
,
-
1
))
...
...
@@ -73,55 +92,105 @@ class DistilledVisionTransformer(VisionTransformer):
def
DeiT_tiny_patch16_224
(
**
kwargs
):
model
=
VisionTransformer
(
patch_size
=
16
,
embed_dim
=
192
,
depth
=
12
,
num_heads
=
3
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
patch_size
=
16
,
embed_dim
=
192
,
depth
=
12
,
num_heads
=
3
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_small_patch16_224
(
**
kwargs
):
model
=
VisionTransformer
(
patch_size
=
16
,
embed_dim
=
384
,
depth
=
12
,
num_heads
=
6
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
patch_size
=
16
,
embed_dim
=
384
,
depth
=
12
,
num_heads
=
6
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_base_patch16_224
(
**
kwargs
):
model
=
VisionTransformer
(
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_tiny_distilled_patch16_224
(
**
kwargs
):
model
=
DistilledVisionTransformer
(
patch_size
=
16
,
embed_dim
=
192
,
depth
=
12
,
num_heads
=
3
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
patch_size
=
16
,
embed_dim
=
192
,
depth
=
12
,
num_heads
=
3
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_small_distilled_patch16_224
(
**
kwargs
):
model
=
DistilledVisionTransformer
(
patch_size
=
16
,
embed_dim
=
384
,
depth
=
12
,
num_heads
=
6
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
patch_size
=
16
,
embed_dim
=
384
,
depth
=
12
,
num_heads
=
6
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_base_distilled_patch16_224
(
**
kwargs
):
model
=
DistilledVisionTransformer
(
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_base_patch16_384
(
**
kwargs
):
model
=
VisionTransformer
(
img_size
=
384
,
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
img_size
=
384
,
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
def
DeiT_base_distilled_patch16_384
(
**
kwargs
):
model
=
DistilledVisionTransformer
(
img_size
=
384
,
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
img_size
=
384
,
patch_size
=
16
,
embed_dim
=
768
,
depth
=
12
,
num_heads
=
12
,
mlp_ratio
=
4
,
qkv_bias
=
True
,
epsilon
=
1e-6
,
**
kwargs
)
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录