Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
0eeb077e
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0eeb077e
编写于
2月 09, 2023
作者:
S
shangliang Xu
提交者:
GitHub
2月 09, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[dino] update code for inverse sigmoid (#7715)
上级
1463f210
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
30 addition
and
29 deletion
+30
-29
ppdet/modeling/transformers/dino_transformer.py
ppdet/modeling/transformers/dino_transformer.py
+29
-28
ppdet/modeling/transformers/utils.py
ppdet/modeling/transformers/utils.py
+1
-1
未找到文件。
ppdet/modeling/transformers/dino_transformer.py
浏览文件 @
0eeb077e
...
...
@@ -257,7 +257,7 @@ class DINOTransformerDecoder(nn.Layer):
def
forward
(
self
,
tgt
,
ref
erence_points
,
ref
_points_unact
,
memory
,
memory_spatial_shapes
,
memory_level_start_index
,
...
...
@@ -272,9 +272,9 @@ class DINOTransformerDecoder(nn.Layer):
output
=
tgt
intermediate
=
[]
inter_ref_bboxes
=
[]
inter_ref_bboxes
_unact
=
[]
for
i
,
layer
in
enumerate
(
self
.
layers
):
reference_points_input
=
reference_points
.
unsqueeze
(
reference_points_input
=
F
.
sigmoid
(
ref_points_unact
)
.
unsqueeze
(
2
)
*
valid_ratios
.
tile
([
1
,
1
,
2
]).
unsqueeze
(
1
)
query_pos_embed
=
get_sine_pos_embed
(
reference_points_input
[...,
0
,
:],
self
.
hidden_dim
//
2
)
...
...
@@ -284,19 +284,19 @@ class DINOTransformerDecoder(nn.Layer):
memory_spatial_shapes
,
memory_level_start_index
,
attn_mask
,
memory_mask
,
query_pos_embed
)
inter_ref_bbox
=
F
.
sigmoid
(
bbox_head
[
i
](
output
)
+
inverse_sigmoid
(
reference_points
))
inter_ref_bbox_unact
=
bbox_head
[
i
](
output
)
+
ref_points_unact
if
self
.
return_intermediate
:
intermediate
.
append
(
self
.
norm
(
output
))
inter_ref_bboxes
.
append
(
inter_ref_bbox
)
inter_ref_bboxes
_unact
.
append
(
inter_ref_bbox_unact
)
ref
erence_points
=
inter_ref_bbox
.
detach
()
ref
_points_unact
=
inter_ref_bbox_unact
.
detach
()
if
self
.
return_intermediate
:
return
paddle
.
stack
(
intermediate
),
paddle
.
stack
(
inter_ref_bboxes
)
return
paddle
.
stack
(
intermediate
),
paddle
.
stack
(
inter_ref_bboxes_unact
)
return
output
,
ref
erence_points
return
output
,
ref
_points_unact
@
register
...
...
@@ -417,6 +417,7 @@ class DINOTransformer(nn.Layer):
linear_init_
(
self
.
enc_output
[
0
])
xavier_uniform_
(
self
.
enc_output
[
0
].
weight
)
normal_
(
self
.
level_embed
.
weight
)
if
self
.
learnt_init_query
:
xavier_uniform_
(
self
.
tgt_embed
.
weight
)
xavier_uniform_
(
self
.
query_pos_head
.
layers
[
0
].
weight
)
xavier_uniform_
(
self
.
query_pos_head
.
layers
[
1
].
weight
)
...
...
@@ -523,7 +524,7 @@ class DINOTransformer(nn.Layer):
# prepare denoising training
if
self
.
training
:
denoising_class
,
denoising_bbox
,
attn_mask
,
dn_meta
=
\
denoising_class
,
denoising_bbox
_unact
,
attn_mask
,
dn_meta
=
\
get_contrastive_denoising_training_group
(
gt_meta
,
self
.
num_classes
,
self
.
num_queries
,
...
...
@@ -532,18 +533,18 @@ class DINOTransformer(nn.Layer):
self
.
label_noise_ratio
,
self
.
box_noise_scale
)
else
:
denoising_class
,
denoising_bbox
,
attn_mask
,
dn_meta
=
None
,
None
,
None
,
None
denoising_class
,
denoising_bbox
_unact
,
attn_mask
,
dn_meta
=
None
,
None
,
None
,
None
target
,
init_ref_points
,
enc_topk_bboxes
,
enc_topk_logits
=
\
target
,
init_ref_points
_unact
,
enc_topk_bboxes
,
enc_topk_logits
=
\
self
.
_get_decoder_input
(
memory
,
spatial_shapes
,
mask_flatten
,
denoising_class
,
denoising_bbox
)
denoising_bbox
_unact
)
# decoder
inter_feats
,
inter_ref_bboxes
=
self
.
decoder
(
target
,
init_ref_points
,
memory
,
spatial_shapes
,
level_start_index
,
self
.
dec_bbox_head
,
self
.
query_pos_head
,
valid_ratios
,
attn_mask
,
mask_flatten
)
inter_feats
,
inter_ref_bboxes
_unact
=
self
.
decoder
(
target
,
init_ref_points
_unact
,
memory
,
spatial_shapes
,
level_start_index
,
self
.
dec_bbox_head
,
self
.
query_pos_head
,
valid_ratios
,
attn_mask
,
mask_flatten
)
out_bboxes
=
[]
out_logits
=
[]
for
i
in
range
(
self
.
num_decoder_layers
):
...
...
@@ -551,11 +552,11 @@ class DINOTransformer(nn.Layer):
if
i
==
0
:
out_bboxes
.
append
(
F
.
sigmoid
(
self
.
dec_bbox_head
[
i
](
inter_feats
[
i
])
+
in
verse_sigmoid
(
init_ref_points
)
))
in
it_ref_points_unact
))
else
:
out_bboxes
.
append
(
F
.
sigmoid
(
self
.
dec_bbox_head
[
i
](
inter_feats
[
i
])
+
in
verse_sigmoid
(
inter_ref_bboxes
[
i
-
1
])
))
in
ter_ref_bboxes_unact
[
i
-
1
]
))
out_bboxes
=
paddle
.
stack
(
out_bboxes
)
out_logits
=
paddle
.
stack
(
out_logits
)
...
...
@@ -611,7 +612,7 @@ class DINOTransformer(nn.Layer):
spatial_shapes
,
memory_mask
=
None
,
denoising_class
=
None
,
denoising_bbox
=
None
):
denoising_bbox
_unact
=
None
):
bs
,
_
,
_
=
memory
.
shape
# prepare input for decoder
output_memory
,
output_anchors
=
self
.
_get_encoder_output_anchors
(
...
...
@@ -626,12 +627,12 @@ class DINOTransformer(nn.Layer):
batch_ind
=
paddle
.
arange
(
end
=
bs
,
dtype
=
topk_ind
.
dtype
)
batch_ind
=
batch_ind
.
unsqueeze
(
-
1
).
tile
([
1
,
self
.
num_queries
])
topk_ind
=
paddle
.
stack
([
batch_ind
,
topk_ind
],
axis
=-
1
)
topk_coord
s_unact
=
paddle
.
gather_nd
(
enc_outputs_coord_unact
,
reference_point
s_unact
=
paddle
.
gather_nd
(
enc_outputs_coord_unact
,
topk_ind
)
# unsigmoided.
reference_points
=
enc_topk_bboxes
=
F
.
sigmoid
(
topk_coord
s_unact
)
if
denoising_bbox
is
not
None
:
reference_points
=
paddle
.
concat
([
denoising_bbox
,
enc_topk_bboxes
],
1
)
enc_topk_bboxes
=
F
.
sigmoid
(
reference_point
s_unact
)
if
denoising_bbox
_unact
is
not
None
:
reference_points
_unact
=
paddle
.
concat
(
[
denoising_bbox_unact
,
reference_points_unact
],
1
)
enc_topk_logits
=
paddle
.
gather_nd
(
enc_outputs_class
,
topk_ind
)
# extract region features
...
...
@@ -642,5 +643,5 @@ class DINOTransformer(nn.Layer):
if
denoising_class
is
not
None
:
target
=
paddle
.
concat
([
denoising_class
,
target
],
1
)
return
target
,
reference_points
.
detach
(
return
target
,
reference_points
_unact
.
detach
(
),
enc_topk_bboxes
,
enc_topk_logits
ppdet/modeling/transformers/utils.py
浏览文件 @
0eeb077e
...
...
@@ -194,7 +194,7 @@ def get_contrastive_denoising_training_group(targets,
known_bbox
+=
rand_part
*
diff
known_bbox
.
clip_
(
min
=
0.0
,
max
=
1.0
)
input_query_bbox
=
bbox_xyxy_to_cxcywh
(
known_bbox
)
input_query_bbox
.
clip_
(
min
=
0.0
,
max
=
1.0
)
input_query_bbox
=
inverse_sigmoid
(
input_query_bbox
)
class_embed
=
paddle
.
concat
(
[
class_embed
,
paddle
.
zeros
([
1
,
class_embed
.
shape
[
-
1
]])])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录