Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
8ed878f4
M
Models
项目概览
曾经的那一瞬间
/
Models
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8ed878f4
编写于
10月 18, 2022
作者:
C
Chaochao Yan
提交者:
A. Unique TensorFlower
10月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal change
PiperOrigin-RevId: 481938528
上级
7a78713d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
10 deletion
+9
-10
official/projects/vit/modeling/vit.py
official/projects/vit/modeling/vit.py
+9
-10
未找到文件。
official/projects/vit/modeling/vit.py
浏览文件 @
8ed878f4
...
...
@@ -26,7 +26,6 @@ from official.projects.vit.modeling.vit_specs import VIT_SPECS
from
official.vision.modeling.backbones
import
factory
from
official.vision.modeling.layers
import
nn_layers
layers
=
tf
.
keras
.
layers
...
...
@@ -67,9 +66,7 @@ class AddPositionEmbs(tf.keras.layers.Layer):
self
.
pos_embedding
=
self
.
add_weight
(
'pos_embedding'
,
pos_emb_shape
,
initializer
=
self
.
posemb_init
)
def
_interpolate
(
self
,
pos_embedding
:
tf
.
Tensor
,
from_shape
:
Tuple
[
int
,
int
],
def
_interpolate
(
self
,
pos_embedding
:
tf
.
Tensor
,
from_shape
:
Tuple
[
int
,
int
],
to_shape
:
Tuple
[
int
,
int
])
->
tf
.
Tensor
:
"""Interpolates the positional embeddings."""
logging
.
info
(
'Interpolating postional embedding from length: %d to %d'
,
...
...
@@ -84,9 +81,10 @@ class AddPositionEmbs(tf.keras.layers.Layer):
pos_embedding
=
self
.
pos_embedding
# inputs.shape is (batch_size, seq_len, emb_dim).
if
inputs
.
shape
[
1
]
!=
pos_embedding
.
shape
[
1
]:
pos_embedding
=
self
.
_interpolate
(
pos_embedding
,
from_shape
=
self
.
posemb_origin_shape
,
to_shape
=
self
.
posemb_target_shape
)
pos_embedding
=
self
.
_interpolate
(
pos_embedding
,
from_shape
=
self
.
posemb_origin_shape
,
to_shape
=
self
.
posemb_target_shape
)
pos_embedding
=
tf
.
cast
(
pos_embedding
,
inputs
.
dtype
)
return
inputs
+
pos_embedding
...
...
@@ -262,7 +260,8 @@ class VisionTransformer(tf.keras.Model):
class_name
=
'TruncatedNormal'
,
config
=
dict
(
stddev
=
.
02
)),
init_stochastic_depth_rate
=
init_stochastic_depth_rate
,
pos_embed_origin_shape
=
pos_embed_shape
,
pos_embed_target_shape
=
pos_embed_target_shape
)(
x
)
pos_embed_target_shape
=
pos_embed_target_shape
)(
x
)
if
pooler
==
'token'
:
x
=
x
[:,
0
]
...
...
@@ -303,8 +302,8 @@ def build_vit(input_specs,
del
norm_activation_config
backbone_type
=
backbone_config
.
type
backbone_cfg
=
backbone_config
.
get
()
assert
backbone_type
==
'vit'
,
(
f
'Inconsistent backbone type '
f
'
{
backbone_type
}
'
)
assert
backbone_type
==
'
legacy_
vit'
,
(
f
'Inconsistent backbone type '
f
'
{
backbone_type
}
'
)
backbone_cfg
.
override
(
VIT_SPECS
[
backbone_cfg
.
model_name
])
return
VisionTransformer
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录