# 消融实验设计流程图 ## 🎯 核心思想:统一框架下的公平对比 三种方法共享完全相同的训练框架,**唯一区别**是用于 refine DINO 相似度的外部 attention 来源。 --- ## 📊 整体流程对比 ``` ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ DeCLIP+ 训练框架 │ │ │ │ ┌──────────────┐ │ │ │ Input Image │ │ │ └──────┬───────┘ │ │ │ │ │ ▼ │ │ ┌──────────────────────────────────────────────────────────────────────┐ │ │ │ 特征提取阶段 │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │ │ │ │ │ DINOv2 │ │ EVA-CLIP │ │ External Model │ │ │ │ │ │ (Teacher) │ │ (Student) │ │ (SD / SAM / I-JEPA) │ │ │ │ │ └──────┬──────┘ └──────┬──────┘ └───────────┬─────────────┘ │ │ │ │ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ │ │ DINO Features CLIP Features External Attention │ │ │ │ (B,C,H,W) (B,C,H,W) (B,HW,HW) │ │ │ └─────────┬──────────────────┬───────────────────────┬────────────────┘ │ │ │ │ │ │ │ ▼ │ │ │ │ ┌─────────────────┐ │ │ │ │ │ DINO Correlation│ │ │ │ │ │ (B,HW,HW) │◄─────────┼───────────────────────┘ │ │ └────────┬────────┘ │ Refine │ │ │ │ │ │ ▼ │ │ │ ┌─────────────────┐ │ │ │ │ Refined DINO │ │ │ │ │ Correlation │ │ │ │ └────────┬────────┘ │ │ │ │ │ │ │ ▼ ▼ │ │ ┌───────────────────────────────────────────────────┐ │ │ │ Loss 计算 │ │ │ │ Context Loss: KL(Student_corr || Refined_DINO) │ │ │ │ Content Loss: Cosine(Student_ROI, Teacher_crop) │ │ │ │ Region Loss: KL(Student_ROI_corr || DINO_ROI) │ │ │ └───────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────────────┘ ``` --- ## 🔄 三种方法的 Attention 提取对比 ``` ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ │ │ ┌─────────────┐ │ │ │ Input Image │ │ │ └──────┬──────┘ │ │ │ │ │ ┌─────────────────────┼─────────────────────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ SD v2.1 │ │ SAM ViT-L │ │ I-JEPA ViT-H │ │ │ │ (UNet) │ │ (Image Enc) │ │ (Encoder) │ │ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Layer [-4,-6] │ │ Global Attn │ │ Layer [-4,-2] │ │ │ │ Self-Attention │ │ [5,11,17,23] │ │ Self-Attention │ │ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ SD Attention │ │ SAM Attention │ │ I-JEPA Attention│ │ │ │ (B, HW, HW) │ │ (B, HW, HW) │ │ (B, HW, HW) │ │ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ │ └─────────────────────┼─────────────────────┘ │ │ │ │ │ ▼ │ │ ┌────────────────────────┐ │ │ │ Resize to DINO size │ │ │ │ (if needed) │ │ │ └───────────┬────────────┘ │ │ │ │ │ ▼ │ │ ┌────────────────────────┐ │ │ │ External Attention │ │ │ │ (B, 256, 256) │ ◄── 统一尺寸: 16×16 patches │ │ └────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────────────┘ ``` --- ## 🧮 Refine 操作(三种方法完全一致) ``` ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ refine_dino_with_attn() │ │ │ │ 输入: │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ DINO Corr │ │ External Attn │ │ │ │ (B, 256, 256) │ │ (B, 256, 256) │ │ │ └────────┬────────┘ └────────┬────────┘ │ │ │ │ │ │ │ ┌──────────────────────┘ │ │ │ │ │ │ ▼ ▼ │ │ ┌─────────────────────────────────────┐ │ │ │ │ │ │ │ propagated = bmm(ext_attn, dino) │ ◄── 核心: Attention 作为传播矩阵 │ │ │ │ │ │ └──────────────────┬──────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────┐ │ │ │ │ │ │ │ refined = w × propagated │ │ │ │ + (1-w) × dino_corr │ ◄── 残差连接 │ │ │ │ │ │ └──────────────────┬──────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────┐ │ │ │ │ │ │ │ refined[diag] = 1.0 │ ◄── 强制自相似度为 1 │ │ │ │ │ │ └──────────────────┬──────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────┐ │ │ │ Refined DINO Correlation │ │ │ │ (B, 256, 256) │ │ │ └─────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────────────┘ ``` --- ## 📋 实验设置对比表 | 设置项 | SD-GSC (Ours) | SAM-GSC | JEPA-GSC | |-------|---------------|---------|----------| | **外部模型** | Stable Diffusion v2.1 | SAM ViT-L | I-JEPA ViT-H/14 | | **Attention 层** | UNet layer [-4, -6] | Global attn [5,11,17,23] | Encoder layer [-4, -2] | | **原始 Attn 尺寸** | 取决于输入 | 64×64 (1024px input) | 16×16 (224px input) | | **Refine Weight** | 0.3 | 0.3 | 0.3 | | **训练框架** | DeCLIP+ | DeCLIP+ | DeCLIP+ | | **DINO Teacher** | DINOv2-B | DINOv2-B | DINOv2-B | | **Student Model** | EVA-CLIP-B/16 | EVA-CLIP-B/16 | EVA-CLIP-B/16 | --- ## 🔬 为什么这样设计是公平的? ``` ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ 公平对比的保证 │ │ │ │ ✅ 相同的训练框架 (DeCLIP+) │ │ └── 相同的 loss 函数: Context + Content + Region │ │ └── 相同的训练超参数: lr, epochs, batch_size │ │ └── 相同的数据集: COCO │ │ │ │ ✅ 相同的 Teacher-Student 设置 │ │ └── Teacher: DINOv2-B + EVA-CLIP (crop features) │ │ └── Student: EVA-CLIP-B/16 │ │ │ │ ✅ 相同的 Refine 操作 │ │ └── 都使用 bmm(attn, dino_corr) + 残差连接 │ │ └── 都使用相同的 refine_weight = 0.3 │ │ │ │ ✅ 唯一变量:External Attention 的来源 │ │ └── SD: 生成式模型的语义聚合能力 │ │ └── SAM: 分割模型的边界感知能力 │ │ └── I-JEPA: 预测式模型的空间推理能力 │ │ │ └─────────────────────────────────────────────────────────────────────────────────────┘ ``` --- ## 📈 预期结果分析 ``` 预期性能排序 mIoU (语义分割) ▲ │ │ ┌─────┐ │ │ SD │ ◄── 最优:生成式先验 + 多层融合 │ │ GSC │ │ └─────┘ │ ┌─────┐ │ │ SAM │ ◄── 次优:强边界感知但语义弱 │ │ GSC │ │ └─────┘ │ ┌─────┐ │ │JEPA │ ◄── 语义一致但边界模糊 │ │ GSC │ │ └─────┘ │ ┌──────┐ │ │ DINO │ ◄── Baseline: 无 refine │ │ only │ │ └──────┘ └──────────────────────────────────────────────► Method ``` **SD-GSC 预期最优的原因**: 1. 🎨 **生成式先验**: 在大规模图文数据上学习,语义理解更丰富 2. 🔗 **去噪任务**: 迫使模型学习图像的整体结构 3. 📊 **多层融合**: 使用 [-4, -6] 两层 attention 的融合 --- ## 🛠️ 实验执行流程 ``` ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ Step-by-Step 执行 │ │ │ │ Step 1: 训练(实时计算 Attention,无需预提取) │ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ # SD-GSC (原方法) │ │ │ │ bash scripts/declip+/dist_DeCLIP+_eva_vitb16_coco.sh │ │ │ │ │ │ │ │ # SAM-GSC (实时计算 SAM attention) │ │ │ │ bash scripts/ablation_sam/dist_sam_gsc_eva_vitb16_coco.sh │ │ │ │ │ │ │ │ # JEPA-GSC (实时计算 I-JEPA attention) │ │ │ │ bash scripts/ablation_ijepa/dist_ijepa_gsc_eva_vitb16_coco.sh │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ │ │ │ │ Step 2: 评估 │ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ # 在相同的评估集上测试 │ │ │ │ - VOC 2012 语义分割 │ │ │ │ - COCO Stuff 语义分割 │ │ │ │ - ADE20K 语义分割 │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ │ │ │ │ Step 3: 分析(可选:离线预提取用于可视化) │ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ python ablation_experiments/extract_sam_attention.py --data_path /coco │ │ │ │ python ablation_experiments/extract_ijepa_attention.py --data_path /coco │ │ │ │ python ablation_experiments/visualize_ablation.py │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────────────┘ ``` --- ## 🔧 技术实现细节 ### 分辨率对齐(参考 ProxyCLIP) 参考项目: https://github.com/mc-lan/ProxyCLIP/blob/main/proxyclip_segmentor.py ``` ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ 分辨率处理策略 │ │ │ │ 模型 │ 处理方式 │ │ ─────────────┼─────────────────────────────────────────────────── │ │ SAM │ 输入 resize 到 1024×1024,内置 pos_embed 插值 │ │ I-JEPA │ 加载时预插值 pos_embed 到目标分辨率(无运行时开销) │ │ DINOv2 │ 直接支持可变分辨率 │ │ │ │ 计算公式: │ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ CLIP: patch_count = det_image_size / downsample_factor = 560/16 = 35×35 │ │ │ │ I-JEPA: target_resolution = 35 × patch_size = 35 × 14 = 490×490 │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────────────┘ ```