DeCLIP-TPAMI / analysis /decoupling_analysis /ABLATION_VERIFICATION.md
xiaomoguhzz's picture
Add files using upload-large-folder tool
c9aee57 verified
# ่งฃ่€ฆ่’ธ้ฆ 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)
```python
# DeCLIP
if args.version == "declip":
method = DeCLIP()
# Integrated
elif args.version == "integrated_grad_analysis":
method = IntegratedDistillationWithGradientAnalysis(...)
```
### 2.2 ่ฎญ็ปƒๆ–นๆณ•ๅฏนๆฏ”
**DeCLIP** (`training/declip.py`):
```python
# ่ฐƒ็”จ 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`):
```python
# ่ฐƒ็”จ 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่กŒ)**:
```python
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)**:
```python
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)**:
```python
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"):
```python
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 ่ฎก็ฎ—
```python
# 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 ่ฎก็ฎ—
```python
# 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๏ผŒ้ฟๅ…็‰นๅพๆททๅˆ