่งฃ่ฆ่ธ้ฆ vs ้ๆ่ธ้ฆ ๆถ่ๅฎ้ช้ช่ฏ
ๆๅๆดๆฐ: 2026-01-23
ๆฌๆๆกฃ้ช่ฏๆถ่ๅฎ้ช็ๆญฃ็กฎๆง๏ผ็กฎ่ฎค DeCLIP ๅ Integrated ็ๅฏไธๅ้ๆฏ Loss ไฝ็จไฝ็ฝฎๅๆๅไธๅฑ Block ็ๅค็ๆนๅผใ
1. ่ๆฌๅๆฐๅฏนๆฏ
| ๅๆฐ | DeCLIP (่งฃ่ฆ) | Integrated (้ๆ) | ๆฏๅฆๅฏน้ฝ |
|---|---|---|---|
mode |
csa_vfm_distill |
vanilla |
โ ๅ ณ้ฎๅ้ |
version |
declip |
integrated_grad_analysis |
โ ๅ ณ้ฎๅ้ |
loss_context_weight |
0.25 | 0.25 | โ |
loss_content_weight |
1.0 | 1.0 | โ |
loss_region_weight |
0.05 (3loss) / ๆ (2loss) | ๆ | โ (2lossๅฏน้ฝ) |
batch-size |
2 | 2 | โ |
lr |
1e-5 | 1e-5 | โ |
epochs |
6 | 6 | โ |
model |
EVA02-CLIP-B-16 | EVA02-CLIP-B-16 | โ |
det-image-size |
560 | 560 | โ |
use_vfm |
dinov2-B | dinov2-B | โ |
lock-image-unlocked-groups |
12 | 12 | โ |
็ป่ฎบ: ้คไบ mode ๅ version๏ผๆๆ่ฎญ็ปๅๆฐๅฎๅ
จ็ธๅใ
2. ไปฃ็ ้พ่ทฏ่ฟฝ่ธช
2.1 ่ฎญ็ปๅ ฅๅฃ (training/main.py)
# DeCLIP
if args.version == "declip":
method = DeCLIP()
# Integrated
elif args.version == "integrated_grad_analysis":
method = IntegratedDistillationWithGradientAnalysis(...)
2.2 ่ฎญ็ปๆนๆณๅฏนๆฏ
DeCLIP (training/declip.py):
# ่ฐ็จ encode_pseudo_boxes๏ผmode="csa_vfm_distill"
student_roi_features, context = student.encode_pseudo_boxes(
images, rois_list, normalize=True, mode=args.mode
)
Integrated (training/integrated_distill.py):
# ่ฐ็จ encode_dense๏ผmode="vanilla"
student_features = student.encode_dense(
images, normalize=False, keep_shape=True, mode="vanilla"
)
2.3 ๆจกๅๅฑ้ข (eva_vit_model.py)
encode_dense ๆนๆณ (็ฌฌ752-759่ก):
if "distill" in mode:
# DeCLIP: ๆๅไธๅฑไฝฟ็จ forward_without_rcffn
x, context = self.blocks[-1].forward_without_rcffn(x, mode)
else:
if mode == "vanilla":
# Integrated: ๆๅไธๅฑไฝฟ็จๅฎๆด forward
x = self.blocks[-1](x, rel_pos_bias=rel_pos_bias)
2.4 Block ๅค็ๆนๅผๅฏนๆฏ
ๅฎๆด forward (Integrated):
def forward(self, x, rel_pos_bias=None, attn_mask=None):
# ๆฎๅทฎ่ฟๆฅ + Attention
x = x + self.drop_path(self.attn(self.norm1(x), ...))
# ๆฎๅทฎ่ฟๆฅ + MLP
x = x + self.drop_path(self.mlp(self.norm2(x)))
return x
forward_without_rcffn (DeCLIP):
def forward_without_rcffn(self, x, mode):
# ๆฒกๆๆฎๅทฎ่ฟๆฅ๏ผๆฒกๆ MLP
x = self.drop_path(self.attn.ss_attn(self.norm1(x), mode))
return x # ่ฟๅ (attn_output, context)
2.5 Attention ่พๅบๅฏนๆฏ
ss_attn ๆนๆณ (mode="csa_vfm_distill"):
def ss_attn(self, x, mode, attn_mask=None):
# ่ฎก็ฎ Q, K, V
q, k, v = ...
# CSA: Q ่ช็ธไผผ + K ่ช็ธไผผ
q_attn = torch.bmm(q, q.transpose(1, 2))
k_attn = torch.bmm(k, k.transpose(1, 2))
attn_weights = F.softmax(q_attn, dim=-1) + F.softmax(k_attn, dim=-1)
# ่ฟๅ attention output ๅ context (Q, K)
return attn_output, (q[:,1:], k[:,1:])
3. Loss ไฝ็จไฝ็ฝฎๅฏนๆฏ
| Loss ็ฑปๅ | DeCLIP (่งฃ่ฆ) | Integrated (้ๆ) |
|---|---|---|
| Context Loss | Q/K ่ช็ธไผผๆง็ฉ้ต | ่ๅ็นๅพ็่ช็ธไผผๆง็ฉ้ต |
| Content Loss | Q ็นๅพ็ ROI Align | ่ๅ็นๅพ็ ROI Align |
| Teacher | DINOv2 ็ธๅ ณๆง็ฉ้ต | DINOv2 ็ธๅ ณๆง็ฉ้ต |
DeCLIP Context Loss ่ฎก็ฎ
# context = (q_feature, k_feature) ๆฅ่ชๆๅไธๅฑ็ Q, K
q_feature, k_feature = context
student_context_similarity = (
torch.einsum("bcm,bcn->bmn", q_feature, q_feature) +
torch.einsum("bcm,bcn->bmn", k_feature, k_feature)
) / 2.0
Integrated Context Loss ่ฎก็ฎ
# student_features ๆฏๅฎๆด forward ๅ็่ๅ็นๅพ
student_features_norm = F.normalize(student_features.flatten(-2), dim=1)
student_intra_corr = torch.einsum('bci,bcj->bij', student_features_norm, student_features_norm)
4. ๆถๆๅทฎๅผๅพ็คบ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DeCLIP (่งฃ่ฆ่ธ้ฆ) โ
โ โ
โ Block 0-10: ๆญฃๅธธ forward (ๆฎๅทฎ + Attention + MLP) โ
โ โ โ
โ Block 11: forward_without_rcffn โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ ๆ ๆฎๅทฎ่ฟๆฅ โ โ
โ โ โ ๆ MLP โ โ
โ โ ๅชๆ ss_attn โ ่ฟๅ Q, K ็นๅพ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Content Loss โ โ Context Loss โ โ
โ โ (Q ็ ROI) โ โ (Q/K ่ช็ธไผผ) โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ CLIP Teacher DINOv2 Teacher โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Integrated (้ๆ่ธ้ฆ) โ
โ โ
โ Block 0-10: ๆญฃๅธธ forward (ๆฎๅทฎ + Attention + MLP) โ
โ โ โ
โ Block 11: ๆญฃๅธธ forward (ๆฎๅทฎ + Attention + MLP) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
ๆๆฎๅทฎ่ฟๆฅ โ โ
โ โ โ
ๆ MLP โ โ
โ โ ่ฟๅ่ๅๅ็็นๅพ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโ โ
โ โ ่ๅ็นๅพ โ โ
โ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Content Loss โ โ Context Loss โ โ
โ โ (่ๅ ROI) โ โ (่ๅ่ช็ธไผผ) โ โ ๆขฏๅบฆๅฒ็ช๏ผ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ CLIP Teacher DINOv2 Teacher โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
5. ๅฎ้ช็ป่ฎบ้ช่ฏ
5.1 ๅฎ้ช่ฎพ็ฝฎๆญฃ็กฎๆง
โ ๅฏไธ็ๅ้ๆฏ Loss ไฝ็จไฝ็ฝฎๅๆๅไธๅฑ Block ๅค็ๆนๅผ
- ๆๆ่ถ ๅๆฐ๏ผlr, batch_size, epochs, loss weights๏ผๅฎๅ จๅฏน้ฝ
- ๆจกๅ็ปๆ๏ผEVA02-CLIP-B-16๏ผๅฎๅ จ็ธๅ
- Teacher ๆจกๅ๏ผDINOv2-B, CLIP๏ผๅฎๅ จ็ธๅ
- ๆฐๆฎ้ๅๆฐๆฎๅขๅผบๅฎๅ จ็ธๅ
5.2 ๅ ณ้ฎๅ็ฐ
| ๆๆ | DeCLIP | Integrated 2loss | Integrated 3loss |
|---|---|---|---|
| ๆ็ป Total Loss | 0.59 | 1.00 | 1.62 (ๅฝไธๅๅ) |
| ๆขฏๅบฆๅฒ็ชๆฏไพ | N/A | 78.0% | 63.8% |
| ๆทฑๅฑๅฒ็ช (L9-11) | N/A | 85-88% | 70%+ |
5.3 ไธบไปไน Integrated ๅญๅจๆขฏๅบฆๅฒ็ช๏ผ
ๅ ไธบ Content Loss ๅ Context Loss ้ฝไฝ็จไบๅไธไธช่ๅ็นๅพ๏ผ
- Content Loss ๅธๆ็นๅพ้ ่ฟ CLIP Teacher๏ผๅๅ่ฏญไน/็ฉไฝ่ฏๅซ๏ผ
- Context Loss ๅธๆ็นๅพ้ ่ฟ DINOv2๏ผๅๅ็ปๆ/็บน็๏ผ
- ไธค่ ็ไผๅๆนๅๅจ 78% ็ๆ ๅตไธๆฏๅฒ็ช็
5.4 ไธบไปไน DeCLIP ้ฟๅ ไบๅฒ็ช๏ผ
ๅ ไธบ DeCLIP ๅฐไธคไธช Loss ไฝ็จไบไธๅ็็นๅพ๏ผ
- Content Loss ไฝ็จไบ Q ็นๅพ
- Context Loss ไฝ็จไบ Q/K ่ช็ธไผผๆง
- ๅปๆๆฎๅทฎ่ฟๆฅๅ MLP๏ผ้ฟๅ ็นๅพๆททๅ