diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/eval_attnbias_sam.py b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/eval_attnbias_sam.py
new file mode 100644
index 0000000000000000000000000000000000000000..579f182a58b7c739101e32cea8a2755697c15dc9
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/eval_attnbias_sam.py
@@ -0,0 +1,2781 @@
+"""Code for finetune_huatuo"""
+
+# ================================================================================
+# 【整体说明】本文件是医学VQA的"注意力偏置干预 + SAM视觉定位"消融实验脚本。
+#
+# 核心思路:
+# 1. 对一个样本(图像+问题),先找出"关键文本token"(医学关键词,靠scispaCy抽取)
+# 和"关键视觉token"(图像里跟问题相关的区域,靠MedSAM3分割定位)。
+# 2. 在模型做生成(generate)之前,临时替换某几层self-attention的forward函数,
+# 在softmax之前对attention score加一个"偏置"(bias):
+# - 关键token的位置加正偏置 -> 强迫模型更关注它们
+# - 非关键token的位置加负偏置 -> 强迫模型更少关注它们
+# 这是一种不需要训练、纯推理时干预的方法。
+# 3. 可选的"预算拍卖"机制(BudgetedTokenAuction):不是简单地"关键词全加偏置,
+# 非关键词全减偏置",而是给每个候选token打分(结合"是否关键"+"当前attention
+# 高低"),只挑选分数最高的一批token真正加偏置,模拟一个有预算限制的"拍卖"。
+# 4. 整个文件还内置了单模态消融对照逻辑(--intervention text/vis/both/none),
+# 用来拆分文本侧和视觉侧各自对效果的贡献。
+#
+# 阅读建议:自上而下大致是
+# 常量与scispaCy加载 -> 数据集类 -> 层选择(load_top_layers) -> attention
+# forward打补丁的底层实现(_patch_attn_forward_with_key_bias) -> 文本关键词
+# 抽取(extract_key_positions) -> SAM bbox转视觉token(_bbox_to_patch_indices)
+# -> 拍卖机制(BudgetedTokenAuction) -> 干预上下文管理器(_AttnInterventionContext)
+# -> 主流程test() -> 命令行参数定义。
+# ================================================================================
+
+import os
+import re
+import copy
+import json
+import torch
+import logging
+import argparse
+import sys
+import ast
+import hashlib
+
+from tqdm import tqdm
+import torch.distributed as dist
+from torch.utils.data import Dataset, DataLoader
+from datetime import timedelta
+from accelerate import Accelerator
+from accelerate.utils import InitProcessGroupKwargs
+from transformers import set_seed
+import shutil
+from scorer import score_mix_llava
+from cli import HuatuoChatbot
+
+os.umask(0)
+
+
+logger = logging.getLogger(__name__)
+logging.basicConfig(level='INFO')
+
+# Additional imports for attention intervention
+import math
+import types
+import numpy as np
+import torch.nn.functional as F
+from PIL import Image
+
+import matplotlib
+matplotlib.use("Agg") # non-interactive backend: avoids X11 display / forwarding prompts on remote sessions
+
+
+# ================================================================================
+# Constants
+# ================================================================================
+# HuatuoGPT-Vision把一张图编码成24x24=576个视觉token(HUATUO_PATCHES是每边的patch数)。
+# 这两个常量在"bbox坐标 -> 视觉token序号"的转换里到处用到。
+HUATUO_NUM_IMG_TOKENS = 576
+HUATUO_PATCHES = 24
+
+
+# scispaCy模型是惰性加载的全局单例,避免每个样本都重新加载一次模型。
+_sci_nlp = None
+
+def _get_sci_nlp():
+ """加载scispaCy的医学实体识别模型(en_core_sci_sm)。
+ 注意:如果spacy没装或者模型没下载,这里会捕获异常并把_sci_nlp设为None,
+ 打印的"falling back to rule filter"这句话是历史遗留的误导性提示——
+ 实际并没有真正的规则过滤兜底逻辑,加载失败时下面_get_medical_entities
+ 直接返回空集合,等价于"完全没有关键词"。如果发现消融实验里关键词总是
+ 空的,先检查这里的加载有没有报错。"""
+ global _sci_nlp
+ if _sci_nlp is None:
+ try:
+ import spacy
+ _sci_nlp = spacy.load("en_core_sci_sm")
+ print("[scispaCy] en_core_sci_sm loaded")
+ except Exception as e:
+ print(f"[scispaCy] load failed ({e}), falling back to rule filter.")
+ _sci_nlp = None
+ return _sci_nlp
+
+
+_PAREN_RE = re.compile(r"\([^)]*\)")
+
+
+def _strip_parens(text: str) -> str:
+ """去掉字符串里的括号及其内容(用于清理模型回复里的注释性括号),并把多余空格合并成一个。"""
+ return re.sub(r"\s{2,}", " ", _PAREN_RE.sub("", text)).strip()
+
+
+def _get_medical_entities(text: str) -> set:
+ """用scispaCy从一段文本(通常是问题原文)里抽取医学实体词,转小写去重返回。
+ 如果scispaCy没加载成功,返回空集合——这意味着整套"关键词偏置"机制会
+ 退化成"没有关键词可偏置",需要重点排查的地方。"""
+ nlp = _get_sci_nlp()
+ if nlp is None:
+ return set()
+ doc = nlp(text)
+ return {ent.text.lower().strip() for ent in doc.ents if len(ent.text.strip()) >= 2}
+
+
+# ================================================================================
+# TestDataset
+# 标准的VQA数据集封装:从json读题,拼成"问题+选项"的提示词模板,按batch_size=1
+# 逐条供后面的test()循环消费。跟普通eval.py的数据集类没有区别。
+# ================================================================================
+
+class TestDataset(torch.utils.data.Dataset):
+ def __init__(self, config, data_path):
+ self.config = config
+ self.dataset = {}
+ with open(data_path) as f:
+ self.dataset = json.load(f)
+ self.datas = []
+
+ test_id = 1
+ for da in self.dataset:
+ da['query'] = self.llava_prompt(da)
+ da['test_id'] = test_id
+ test_id += 1
+ self.datas.append(da)
+
+ def llava_prompt(self,da):
+ self.query_prompt = "{}\n{}\nAnswer with the option's letter from the given choices directly."
+ opt_title = ['A','B','C','D','E','F','G','H','I','J','K']
+ if isinstance(da['options'],str):
+ da['options'] = ast.literal_eval(da['options'])
+ option_str = '\n'.join(f'{opt}. {ops}' for opt,ops in zip(opt_title,da['options']))
+ return self.query_prompt.format(da['question'],option_str)
+
+ def __getitem__(self, index):
+ da = self.datas[index]
+ return {
+ 'data': da,
+ 'query': da['query'],
+ 'image': da['image']
+ }
+
+ def __len__(self):
+ return len(self.datas)
+
+ def collate_fn(self, batch):
+ out_batch = {}
+ out_batch['query'] = [x['query'] for x in batch]
+ out_batch['data'] = [x['data'] for x in batch]
+ out_batch['image'] = [x['image'] for x in batch]
+ return out_batch
+
+
+# ================================================================================
+# Top-K layer selection
+# 这部分用来自动选择"在哪几层注入偏置",是--attn_layers_text/vis不指定时的
+# 备用方案:从一个.pt文件(事先由measure_attention.py之类的脚本算好的、
+# 每一层的"divergence"分数)里,挑出分数最高的topk层。
+# 实际消融脚本里几乎都直接用--attn_layers_text/vis写死层号,这套自动选层
+# 逻辑主要是给网格搜索(run_ablation_grid.sh)之前的探索阶段用的。
+# ================================================================================
+def _load_mean_div(pt_path):
+ """读取一个.pt文件,里面存的是逐样本/逐层的divergence分数,对样本维度取平均,
+ 返回shape为[num_layers]的一维numpy数组。"""
+ data = torch.load(pt_path, map_location="cpu", weights_only=False)
+ if isinstance(data, torch.Tensor):
+ arr = data.float().numpy()
+ return arr if arr.ndim == 1 else arr.mean(axis=0)
+ stacked = np.stack([np.array(x) for x in data], axis=0)
+ return stacked.mean(axis=0)
+
+
+def load_top_layers(pt_path, topk, pt_path_random=None):
+ """从per-layer的平均divergence分数里选出最重要的topk层。
+ 如果同时给了pt_path_random(随机对照的divergence),就用"真实divergence减去
+ 随机divergence"的差值排序——挑的是"比随机扰动更显著"的层,而不是单纯
+ divergence绝对值最大的层(绝对值大也可能只是因为深层普遍divergence大)。"""
+ mean = _load_mean_div(pt_path)
+ if pt_path_random is not None:
+ rand = _load_mean_div(pt_path_random)
+ diff = mean - rand
+ idx = np.argsort(diff)[::-1][:topk]
+ layers = [int(i) for i in idx]
+ print(f"[top-layers/diff] top-{topk}: {layers}")
+ return layers
+ idx = np.argsort(mean)[::-1][:topk]
+ layers = [int(i) for i in idx]
+ print(f"[top-layers] top-{topk}: {layers}")
+ return layers
+
+
+def _parse_layer_list(s):
+ """把命令行传入的层号字符串(如"17"或"3,10,17")解析成int列表。"""
+ if s is None:
+ return None
+ if isinstance(s, int):
+ return [s]
+ return [int(x.strip()) for x in str(s).split(',') if x.strip()]
+
+
+# ================================================================================
+# Attention forward utilities (manual RoPE + attention with pre-softmax key bias)
+# 这一段是整个干预机制的"底层手术刀":完整手写了一遍Qwen2风格self-attention的
+# forward过程(RoPE位置编码 + GQA的key/value重复 + QK^T/sqrt(d) + softmax),
+# 唯一不同于原版的地方是:在softmax之前,把一个偏置向量bias_vec_fn(kv_len)
+# 加到attention score的"最后一个query token"那一行上(因为我们是在generate
+# 阶段,每次forward只有一个新token在问"该往哪些kv位置看")。
+# 这样实现的好处是不需要改模型权重、不需要训练,只在推理时临时替换某几层
+# attention模块的forward方法,跑完之后再换回原来的forward(见__exit__)。
+# ================================================================================
+def _rotate_half(x):
+ x1 = x[..., : x.shape[-1] // 2]
+ x2 = x[..., x.shape[-1] // 2 :]
+ return torch.cat((-x2, x1), dim=-1)
+
+
+def _apply_rotary_pos_emb_local(q, k, cos, sin, unsqueeze_dim=1):
+ cos = cos.unsqueeze(unsqueeze_dim)
+ sin = sin.unsqueeze(unsqueeze_dim)
+ q_embed = (q * cos) + (_rotate_half(q) * sin)
+ k_embed = (k * cos) + (_rotate_half(k) * sin)
+ return q_embed, k_embed
+
+
+def _repeat_kv_local(hidden_states, n_rep):
+ if n_rep == 1:
+ return hidden_states
+ bsz, n_kv_heads, slen, head_dim = hidden_states.shape
+ hidden_states = hidden_states[:, :, None, :, :].expand(
+ bsz, n_kv_heads, n_rep, slen, head_dim
+ )
+ return hidden_states.reshape(bsz, n_kv_heads * n_rep, slen, head_dim)
+
+
+def _patch_attn_forward_with_key_bias(
+ attn_module, tag: str = "",
+ bias_vec_fn=None):
+ """给某一个attention模块(attn_module)的forward方法打补丁,替换成下面手写的
+ _new_forward。返回的old_forward要保存起来,干预结束后用它把forward还原回去
+ (见_AttnInterventionContext.__exit__)。
+ bias_vec_fn: 一个函数,输入kv_len(当前kv序列长度),返回一个shape=[kv_len]的
+ 偏置向量,描述"每个kv位置在softmax前应该加多少分"。这个向量是上层
+ (_AttnInterventionContext.make_bias)根据"谁是关键词/谁是SAM区域"算出来的。"""
+ old_forward = attn_module.forward
+
+ def _new_forward(self, hidden_states, attention_mask=None, position_ids=None,
+ past_key_value=None, output_attentions=False, use_cache=False,
+ cache_position=None, position_embeddings=None, **kwargs):
+ bsz, q_len, _ = hidden_states.size()
+
+ num_heads = getattr(self, "num_heads",
+ getattr(self.config, "num_attention_heads", None))
+ num_kv_heads = getattr(self, "num_key_value_heads",
+ getattr(self.config, "num_key_value_heads", num_heads))
+ head_dim = getattr(self, "head_dim",
+ hidden_states.shape[-1] // num_heads)
+ num_kv_groups = getattr(self, "num_key_value_groups",
+ num_heads // num_kv_heads)
+
+ query_states = self.q_proj(hidden_states)
+ key_states = self.k_proj(hidden_states)
+ value_states = self.v_proj(hidden_states)
+
+ query_states = query_states.view(bsz, q_len, num_heads, head_dim).transpose(1, 2)
+ key_states = key_states.view(bsz, q_len, num_kv_heads, head_dim).transpose(1, 2)
+ value_states = value_states.view(bsz, q_len, num_kv_heads, head_dim).transpose(1, 2)
+
+ if position_embeddings is None:
+ if not hasattr(self, "rotary_emb"):
+ return old_forward(hidden_states, attention_mask=attention_mask,
+ position_ids=position_ids, past_key_value=past_key_value,
+ output_attentions=output_attentions, use_cache=use_cache,
+ cache_position=cache_position, **kwargs)
+ kv_seq_len = key_states.shape[-2]
+ if past_key_value is not None:
+ try:
+ kv_seq_len += past_key_value.get_usable_length(
+ kv_seq_len, getattr(self, "layer_idx", 0))
+ except Exception:
+ try:
+ kv_seq_len += past_key_value.get_seq_length(
+ getattr(self, "layer_idx", 0))
+ except Exception:
+ pass
+ try:
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
+ except TypeError:
+ cos, sin = self.rotary_emb(value_states, position_ids)
+ else:
+ cos, sin = position_embeddings
+
+ try:
+ from transformers.models.qwen2.modeling_qwen2 import apply_rotary_pos_emb
+ try:
+ query_states, key_states = apply_rotary_pos_emb(
+ query_states, key_states, cos, sin, position_ids)
+ except TypeError:
+ query_states, key_states = apply_rotary_pos_emb(
+ query_states, key_states, cos, sin)
+ except Exception:
+ if position_ids is not None and getattr(cos, "dim", lambda: 0)() == 2:
+ cos_sel = cos[position_ids].to(dtype=query_states.dtype)
+ sin_sel = sin[position_ids].to(dtype=query_states.dtype)
+ query_states, key_states = _apply_rotary_pos_emb_local(
+ query_states, key_states, cos_sel, sin_sel)
+ else:
+ query_states, key_states = _apply_rotary_pos_emb_local(
+ query_states, key_states, cos, sin)
+
+ if past_key_value is not None:
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
+ key_states, value_states = past_key_value.update(
+ key_states, value_states, getattr(self, "layer_idx", 0), cache_kwargs)
+
+ key_states = _repeat_kv_local(key_states, num_kv_groups)
+ value_states = _repeat_kv_local(value_states, num_kv_groups)
+
+ # 标准的QK^T/sqrt(d)算raw attention score
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) \
+ / math.sqrt(head_dim)
+
+ if attention_mask is not None:
+ if attention_mask.dim() == 4:
+ causal_mask = attention_mask[:, :, :, :key_states.shape[-2]]
+ attn_weights = attn_weights + causal_mask
+ else:
+ attn_weights = attn_weights + attention_mask
+
+ kv_len = attn_weights.shape[-1]
+
+ # ★★★ 核心干预点 ★★★:在因果mask加完之后、softmax之前,把bias_vec_fn
+ # 算出来的偏置向量加到"最后一个query token"对所有kv位置的score上。
+ # 只动最后一行是因为generate阶段每步forward只有1个新query token;
+ # 这一步过后再走softmax,偏置越大的位置归一化后获得的attention权重
+ # 就越大(同理负偏置会被压低),从而实现"强迫模型看/不看某些token"。
+ if bias_vec_fn is not None:
+ bv = bias_vec_fn(kv_len).to(device=attn_weights.device, dtype=attn_weights.dtype)
+ if not getattr(self, f"_bias_printed_{tag}", False):
+ nonzero_pos = bv.nonzero(as_tuple=True)[0].tolist()
+ print(f"[AttnBias-{tag}] layer={getattr(self,'layer_idx','?')} "
+ f"kv_len={kv_len} nonzero={len(nonzero_pos)} positions: "
+ + ", ".join(f"{p}:{bv[p].item():.2f}" for p in nonzero_pos[:20])
+ + (" ..." if len(nonzero_pos) > 20 else ""))
+ setattr(self, f"_bias_printed_{tag}", True)
+ attn_weights[:, :, -1:, :] = attn_weights[:, :, -1:, :] + bv.view(1, 1, 1, kv_len)
+
+ attn_weights = F.softmax(attn_weights, dim=-1,
+ dtype=torch.float32).to(query_states.dtype)
+
+ attn_weights = F.dropout(attn_weights,
+ p=getattr(self, "attention_dropout", 0.0),
+ training=self.training)
+ attn_output = torch.matmul(attn_weights, value_states)
+
+ if attn_output.size() != (bsz, num_heads, q_len, head_dim):
+ raise ValueError(
+ f"attn_output should be {(bsz, num_heads, q_len, head_dim)}, "
+ f"but is {attn_output.size()}"
+ )
+
+ attn_output = attn_output.transpose(1, 2).contiguous()
+ attn_output = attn_output.reshape(bsz, q_len, num_heads * head_dim)
+ attn_output = self.o_proj(attn_output)
+
+ if not output_attentions:
+ attn_weights = None
+ return attn_output, attn_weights, past_key_value
+
+ attn_module.forward = types.MethodType(_new_forward, attn_module)
+ return old_forward
+
+
+def _get_attn_layers(bot):
+ """拿到模型所有transformer层的self-attention子模块列表,按层号顺序排列。
+ 后面"--attn_layers_text 19"这种参数里的19,就是这个列表的下标。"""
+ try:
+ return [layer.self_attn for layer in bot.model.model.layers]
+ except AttributeError:
+ return [m for n, m in bot.model.named_modules()
+ if n.endswith(".self_attn") and hasattr(m, "q_proj")]
+
+
+# ================================================================================
+# Step A: Extract key text token positions and option token positions
+# 这一段负责"文本侧关键token"的抽取:先跑一次完整的eager attention前向,
+# 找到图像token的起始位置(img_start),再用scispaCy从问题文本里抽取医学实体词,
+# 把这些词映射回输入序列里具体的token下标(top_text_positions)。
+# ================================================================================
+def _get_attentions(output):
+ """从模型forward的输出里取出attentions(每层的attention权重元组)。
+ 要求模型forward时用的是eager attention实现(不能是flash-attn等不返回
+ 权重的实现),否则这里拿不到attentions直接报错。"""
+ att = getattr(output, "attentions", None)
+ if att is None and isinstance(output, dict):
+ att = output.get("attentions")
+ if att is None:
+ raise RuntimeError("Model did not return attentions. Make sure eager attention is forced.")
+ return att
+
+
+def _decode_token(tokenizer, token_id):
+ """把单个token id解码成纯文本(去掉特殊token、去掉sentencepiece的▁前缀、转小写),
+ 方便后面做"这个token是不是选项字母A/B/C..."之类的字符串比较。"""
+ try:
+ return tokenizer.decode([int(token_id)], skip_special_tokens=True).strip().lower().lstrip("▁").strip()
+ except Exception:
+ return ""
+
+
+def extract_key_positions(bot, prompt, image, question=None, need_keywords=True):
+ """
+ Run one eager attention forward pass and return:
+ top_text_positions : [list[int]] —global positions of scispaCy keyword tokens (wrapped in a list)
+ all_text_positions : list[int] —all text token positions in the question segment
+ img_start : int
+ seq_len : int
+ attentions : tuple —all layer attentions, reused by Step B
+
+ need_keywords=False skips the scispaCy entity extraction below (img_start/seq_len
+ are still computed —every intervention mode needs those), for use by the "none"
+ mode where keywords are never consumed.
+ """
+ text = bot.input_moderation(prompt)
+ text = bot.insert_image_placeholder(text, 1)
+ conv = bot.get_conv_without_history(text)
+ input_ids = bot.preprocess(conv, return_tensors="pt").unsqueeze(0).to(bot.device)
+ image_tensors = (torch.stack(bot.get_image_tensors([image]))
+ .to(dtype=torch.bfloat16).to(bot.device))
+
+ with torch.no_grad():
+ output = bot.model(input_ids, images=image_tensors,
+ output_attentions=True, output_hidden_states=False,
+ return_dict=True, use_cache=False)
+ attentions = _get_attentions(output)
+
+ ids_cpu = input_ids[0].cpu()
+ img_pos_list = torch.where(ids_cpu == -200)[0]
+ if img_pos_list.numel() == 0:
+ raise ValueError("Image placeholder token (-200) not found.")
+ # -200是图像占位符token的id;它在input_ids里只占1个位置,但模型实际会把它
+ # 展开成576个视觉token,所以img_start记录的是"图像区域在真实序列里的起始下标"。
+ img_start = int(img_pos_list[0].item())
+ seq_len = attentions[0].shape[-1]
+ vis_end = img_start + HUATUO_NUM_IMG_TOKENS
+
+ # 把input_ids里那一个-200占位符"摊开"成576个,跟attentions的真实seq_len对齐,
+ # 这样下面按下标索引文本/视觉token位置时才不会错位。
+ prefix = ids_cpu[:img_start]
+ img_fill = torch.full((HUATUO_NUM_IMG_TOKENS,), -200, dtype=ids_cpu.dtype)
+ suffix = ids_cpu[img_start + 1:]
+ ids_cpu = torch.cat([prefix, img_fill, suffix], dim=0)
+
+ # ── 找到第一个"选项标记"(如"A."/"B.")的位置,目的是把text_positions的范围
+ # 限制在"问题正文"内,不要延伸到选项列表里去,避免把选项字母/选项内容也
+ # 当成可以加偏置的"问题文本"。下面这段是手写的简单规则匹配,不是模型推理。──
+ first_option_pos = None
+ tokenizer = bot.tokenizer
+ text_ids = ids_cpu[vis_end:].tolist()
+ option_letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'}
+ i = 0
+ while i < len(text_ids) and first_option_pos is None:
+ w = _decode_token(tokenizer, text_ids[i])
+ w_stripped = w.strip()
+ is_option = False
+
+ # must be preceded by a newline to avoid false positives inside words
+ # use raw decode (skip_special_tokens=False) to preserve \n
+ prev_raw = tokenizer.decode([text_ids[i - 1]], skip_special_tokens=False) if i > 0 else ""
+ cur_raw = tokenizer.decode([text_ids[i]], skip_special_tokens=False)
+ preceded_by_newline = '\n' in prev_raw or '\n' in cur_raw
+
+ # case 1: token is exactly a single letter e.g. "a", then next token contains "."
+ if preceded_by_newline and w_stripped.lower() in option_letters:
+ if i + 1 < len(text_ids) and '.' in _decode_token(tokenizer, text_ids[i + 1]):
+ is_option = True
+
+ # case 2: token is "a." or "A." (letter + dot, possibly with surrounding spaces)
+ if not is_option and preceded_by_newline and len(w_stripped) >= 2:
+ if w_stripped[0].lower() in option_letters and w_stripped[1] == '.':
+ is_option = True
+
+ if is_option:
+ first_option_pos = vis_end + i
+ i += 1
+
+ # text_end之前的范围就是"问题正文token"的范围(text_positions / all_text_pos),
+ # 不包含选项、不包含图像、不包含prompt模板里的指令句。
+ text_end = first_option_pos if first_option_pos is not None else (seq_len - 1)
+ text_positions = list(range(vis_end, text_end))
+ if not text_positions:
+ text_positions = list(range(vis_end, seq_len - 1))
+
+ top_text_pos = []
+ ent_positions = {}
+ if need_keywords:
+ # ── 用scispaCy从问题原文里抽取医学实体词,再把这些词映射回token下标 ──
+ q_text = question if question else prompt
+ med_ents = _get_medical_entities(q_text)
+
+ # 把text_positions范围内的所有token重新拼成一段连续字符串full_text,
+ # 同时维护一个char_to_pos映射(每个字符对应哪个token下标),方便后面
+ # 用字符串.find()定位实体词后,反查出它覆盖了哪些token。
+ # 用保留▁的原始decode方式,是为了让词与词之间天然有空格分隔。
+ full_text = ""
+ char_to_pos = []
+ for ti in text_positions:
+ if 0 <= ti < ids_cpu.shape[0]:
+ raw = tokenizer.decode([ids_cpu[ti].item()], skip_special_tokens=True)
+ # ▁ represents a space prefix in sentencepiece tokenizers
+ w = raw.replace("▁", " ").lower()
+ else:
+ w = ""
+ for _ in w:
+ char_to_pos.append(ti)
+ full_text += w
+ full_text_lower = full_text.lower()
+
+ def _find_entity_positions(ent):
+ """在full_text里找实体词ent第一次出现的位置,再通过char_to_pos映射
+ 回这段字符跨越了哪些token下标(去重保序)。找不到就返回空列表。"""
+ ent_lower = ent.lower().strip()
+ idx = full_text_lower.find(ent_lower)
+ if idx == -1:
+ return []
+ end = idx + len(ent_lower)
+ # 收集这个字符跨度覆盖到的、去重后的token位置
+ positions = []
+ seen_pos = set()
+ for ci in range(idx, min(end, len(char_to_pos))):
+ p = char_to_pos[ci]
+ if p not in seen_pos:
+ seen_pos.add(p)
+ positions.append(p)
+ return positions
+
+ # 给每一个scispaCy识别出的实体词都找token位置;不再按attention排序截断
+ # top-k——所有识别出的实体词都进入关键词候选集合,"哪个更重要"这件事
+ # 交给后面BudgetedTokenAuction统一用attention打分来决定,避免在这里
+ # 和拍卖阶段对"重要性"做了两次互相矛盾的判断。
+ for ent in sorted(med_ents):
+ positions = _find_entity_positions(ent)
+ if positions:
+ ent_positions[ent] = positions
+
+ for positions in ent_positions.values():
+ top_text_pos.extend(positions)
+
+ # 额外保证问题里的疑问词(what/where/...)也被纳入关键位置——这类词
+ # 虽然不是scispaCy的医学实体,但对"问题在问什么"同样重要。只看
+ # 问题最前面几个token,找到第一个命中就加进去并停止。
+ # 暂时注释掉:怀疑这一步往关键词集合里混入了非医学的通用疑问词,
+ # 可能是"both(文本+视觉同时加偏置)比单模态还差"的干扰因素之一,
+ # 先关掉观察有没有影响,方便对比。
+ # Temporarily disabled: suspect this step mixes a generic (non-medical)
+ # question word into the keyword set, which may be contributing to
+ # "both" underperforming single-modality -- disabled to isolate whether
+ # it matters.
+ # wh_words = {'what', 'where', 'when', 'which', 'who', 'how'}
+ # seen_pos = set(top_text_pos)
+ # for ti in text_positions[:5]: # only look at the first few question tokens
+ # if 0 <= ti < ids_cpu.shape[0]:
+ # w = _decode_token(tokenizer, ids_cpu[ti].item())
+ # if w.lower() in wh_words and ti not in seen_pos:
+ # top_text_pos.append(ti)
+ # seen_pos.add(ti)
+ # print(f"[WH] added '{w}' at pos={ti}")
+ # break
+
+ # 返回值说明:
+ # top_text_positions: [[关键词token位置...]] —— 外层包一层list是历史接口习惯
+ # text_positions(=all_text_pos): 问题正文里全部token的位置(不止关键词)
+ # img_start/seq_len: 图像起始位置/总序列长度
+ # attentions: 这次forward的全部attention权重(Step B/B.5会复用,不用再跑一次)
+ # keywords: 实际识别出的关键词字符串列表(纯打印调试用)
+ top_text_positions = [top_text_pos] if top_text_pos else [[]]
+ keywords = list(ent_positions.keys())
+ return top_text_positions, text_positions, img_start, seq_len, attentions, keywords
+
+
+# ================================================================================
+# Step B: MedSAM3 visual localization
+# 这一段负责"视觉侧关键token"的抽取:把SAM分割出来的bbox坐标(原图像素坐标)
+# 转换成HuatuoGPT-Vision的24x24视觉token网格里对应的patch下标。
+# ================================================================================
+def _bbox_to_patch_indices(bbox_xyxy, orig_size, img_pos, margin=2):
+ """把一个bbox(原图像素坐标[x1,y1,x2,y2])转换成该bbox覆盖到的视觉token下标列表。
+ margin: 在bbox四周多扩margin个patch的余量,防止分割框刚好卡在边缘漏掉token。"""
+ # cli.py里get_image_tensors()会先把图像expand2square(短边补黑边垫成正方形)
+ # 再resize成模型输入网格,所以bbox坐标(基于原始未补边的图像)要先平移到
+ # "补边后的正方形坐标系"里,才能正确按比例换算成patch下标。
+ W, H = orig_size
+ side = max(W, H)
+ off_x = (side - W) // 2
+ off_y = (side - H) // 2
+ x1, y1, x2, y2 = bbox_xyxy
+ x1, x2 = x1 + off_x, x2 + off_x
+ y1, y2 = y1 + off_y, y2 + off_y
+ c1 = max(0, int(x1 / side * HUATUO_PATCHES) - margin)
+ r1 = max(0, int(y1 / side * HUATUO_PATCHES) - margin)
+ c2 = min(HUATUO_PATCHES - 1, int(x2 / side * HUATUO_PATCHES) + margin)
+ r2 = min(HUATUO_PATCHES - 1, int(y2 / side * HUATUO_PATCHES) + margin)
+ indices = []
+ for r in range(r1, r2 + 1):
+ for c in range(c1, c2 + 1):
+ indices.append(img_pos + r * HUATUO_PATCHES + c)
+ return indices
+
+
+def _multi_bbox_to_patch_indices(bbox_list, orig_size, img_pos, margin=2):
+ """对多个bbox分别转换成patch下标,再去重合并成一个列表(保留首次出现的顺序)。"""
+ seen, merged = set(), []
+ for bbox in bbox_list:
+ for idx in _bbox_to_patch_indices(bbox, orig_size, img_pos, margin):
+ if idx not in seen:
+ seen.add(idx)
+ merged.append(idx)
+ return merged
+
+
+_vis_save_count = 0
+_vis_save_dir = "vis_debug"
+
+# 抽查可视化(默认开启,--no_vis_mask关闭)的独立计数器/输出目录,跟上面SAM
+# 调试图(_vis_save_count/_vis_save_dir,画Stage1+SAM原始输出)是两套东西:
+# 这里画的是Pass 1生成循环里"这次真正生效的偏置对象",命名区分开以免混淆。
+_vis_mask_save_count = 0
+_vis_mask_dir = "vis_mask_debug"
+
+
+# ================================================================================
+# Sanity-check visualization: mask region / mask text
+# 抽查可视化:这几个函数不参与干预逻辑本身,只是把"最终真正被偏置的位置"画出来,
+# 供人工确认——跟MedEvalKit/measure_attention.py里的visualize_masked_tokens/
+# render_masked_text_image是同一目的、同一红色高亮约定,只是适配
+# 了本文件"img_pos + row*24 + col"的绝对索引寻址方式(没有token_shape/frame_size
+# 这类二维网格抽象,直接用HUATUO_PATCHES=24做行列换算)。
+# ================================================================================
+def _save_or_show(fig, save_path):
+ """matplotlib图像的统一出口:传了save_path就存文件(自动建父目录),否则
+ 交互式展示。最后都要plt.close(fig)释放内存,避免在样本循环里反复画图时
+ figure对象堆积。"""
+ import matplotlib.pyplot as plt
+ if save_path:
+ os.makedirs(os.path.dirname(save_path), exist_ok=True)
+ fig.savefig(save_path, dpi=150, bbox_inches="tight")
+ else:
+ plt.show()
+ plt.close(fig)
+
+
+def visualize_masked_region(image_path, orig_size, img_pos, primary_patches,
+ negative_patches=None, save_path=None,
+ num_patches=HUATUO_PATCHES):
+ """
+ 把真正被偏置的视觉patch画在原图上:primary_patches(真实SAM区域/关键词对应
+ 的patch,--intervention vis/both时的正向偏置对象)用半透明红色高亮,
+ negative_patches(拍卖选中的负向/干扰patch,会被加负偏置压制)如果给了,
+ 用半透明青色高亮。
+ 方便人眼确认:
+ 1. 红色区域是否真的落在SAM分割出的目标结构上;
+ 2. 红色和青色是否互不重叠、且形状规整(每个bbox一整块矩形,而不是散点);
+ 3. 青色(负向偏置)是不是真的落在"不该关注"的区域上,而不是跟红色犯冲。
+
+ 绝对patch索引(img_pos + row*24 + col)先还原成24x24网格坐标,再用跟
+ _bbox_to_patch_indices完全相同的pad-square反变换(乘以side/24再减去
+ off_x/off_y)把网格坐标映射回原图像素坐标——因为HuatuoGPT-Vision的cli.py
+ 会先把非方形原图expand2square再resize进这个网格,不做这一步反变换,
+ 高亮区域会跟原图错位。用NEAREST插值,因为这是离散的0/1/2分类掩码,
+ 不是连续数值,不应该做任何插值平滑。
+ """
+ import matplotlib.pyplot as plt
+
+ W, H = orig_size
+ side = max(W, H)
+ off_x = (side - W) // 2
+ off_y = (side - H) // 2
+
+ mask_grid = np.zeros((num_patches, num_patches), dtype=np.uint8)
+ for p in (primary_patches or []):
+ rel = p - img_pos
+ row, col = divmod(rel, num_patches)
+ if 0 <= row < num_patches and 0 <= col < num_patches:
+ mask_grid[row, col] = 1
+ for p in (negative_patches or []):
+ rel = p - img_pos
+ row, col = divmod(rel, num_patches)
+ if 0 <= row < num_patches and 0 <= col < num_patches:
+ mask_grid[row, col] = 2
+
+ # 网格(side x side的正方形坐标系) -> 裁掉padding -> resize回原图(W,H)
+ mask_img = Image.fromarray(mask_grid, mode="L")
+ mask_img = mask_img.resize((side, side), resample=Image.NEAREST)
+ crop_box = (off_x, off_y, off_x + W, off_y + H)
+ mask_img = mask_img.crop(crop_box)
+ mask_img = mask_img.resize((W, H), resample=Image.NEAREST)
+ mask_resampled = np.array(mask_img)
+
+ src = Image.open(image_path).convert("RGB")
+ fig, ax = plt.subplots(figsize=(4, 4 * H / W))
+ ax.imshow(src)
+ overlay = np.zeros((H, W, 4))
+ overlay[mask_resampled == 1] = [1.0, 0.0, 0.0, 0.45]
+ overlay[mask_resampled == 2] = [0.0, 0.85, 0.85, 0.45]
+ ax.imshow(overlay)
+ ax.axis("off")
+ _save_or_show(fig, save_path)
+
+
+def render_masked_text_image(ids_list, tokenizer, primary_indices,
+ negative_indices=None,
+ img_start=None, img_end=None, wrap_chars=70, save_path=None):
+ """
+ 把完整input_ids解码回可读文本渲染成图片:primary_indices(真实scispaCy
+ 关键词token,--intervention text/both时的正向偏置对象)用红色背景高亮,
+ negative_indices(拍卖选中的负向/干扰token,会被加负偏置压制)如果给了,
+ 用青色背景高亮——跟visualize_masked_region的红/青配色约定一致,方便人
+ 读一遍原文确认:mask的确实是关键词本身,负向偏置压制的确实是"不该关注"
+ 的词而不是跟关键词犯冲。
+
+ [img_start, img_end)标记图像token在input_ids里的展开区间(即img_start加上
+ HUATUO_NUM_IMG_TOKENS个-200占位符展开后的范围):如果给了,这一整段会被
+ 折叠显示成一个"
"灰色占位符,而不是把576个图像token逐个解码渲染
+ (那样图片会被撑得极长)。注意ids_list这里应该是extract_key_positions内部
+ "摊开"过的版本(-200占位符已展开成HUATUO_NUM_IMG_TOKENS个),跟primary_
+ indices/negative_indices的下标是同一套坐标系。
+
+ 排版实现:跟MedEvalKit的render_masked_text_image一样,先在x=0创建所有
+ Text对象强制渲染一次拿真实像素宽度(get_window_extent),再按真实宽度
+ 重新定位——按字符数估算宽度会让"<|vision_start|>"这类长特殊token的估算
+ 误差累积,导致相邻片段视觉上粘在一起。
+ """
+ import matplotlib.pyplot as plt
+
+ primary_set = set(primary_indices or [])
+ negative_set = set(negative_indices or [])
+ fragments = []
+ i = 0
+ n = len(ids_list)
+ while i < n:
+ if img_start is not None and img_end is not None and img_start <= i < img_end:
+ fragments.append(("
", "img"))
+ i = img_end
+ continue
+ tid = ids_list[i]
+ try:
+ frag = tokenizer.decode([int(tid)])
+ except Exception:
+ frag = ""
+ if i in primary_set:
+ kind = "label"
+ elif i in negative_set:
+ kind = "negative"
+ else:
+ kind = "normal"
+ fragments.append((frag, kind))
+ i += 1
+
+ color_map = {
+ "label": (1.0, 0.3, 0.3, 0.55),
+ "negative": (0.2, 0.75, 0.75, 0.55),
+ "img": (0.6, 0.6, 0.6, 0.5),
+ }
+
+ lines = [[]]
+ cur_len = 0
+ for frag, kind in fragments:
+ if cur_len + len(frag) > wrap_chars and cur_len > 0:
+ lines.append([])
+ cur_len = 0
+ lines[-1].append((frag, kind))
+ cur_len += len(frag)
+
+ fontsize = 11
+ fig_w = 9.0
+ line_height_in = fontsize / 72 * 1.9
+ fig_h = line_height_in * (len(lines) + 1)
+ fig, ax = plt.subplots(figsize=(fig_w, fig_h))
+ ax.axis("off")
+ ax.set_xlim(0, 1)
+ ax.set_ylim(0, 1)
+
+ text_rows = []
+ for li, line in enumerate(lines):
+ y = 1 - (li + 1) / (len(lines) + 1)
+ row = []
+ for frag, kind in line:
+ color = color_map.get(kind)
+ bbox = dict(facecolor=color, edgecolor="none", pad=2.5) if color else None
+ t = ax.text(
+ 0, y, frag, fontsize=fontsize, family="monospace",
+ va="center", ha="left", bbox=bbox, transform=ax.transAxes,
+ )
+ row.append(t)
+ text_rows.append(row)
+
+ fig.canvas.draw()
+ renderer = fig.canvas.get_renderer()
+ axes_width_px = ax.get_window_extent(renderer=renderer).width
+
+ gap_frac = 0.004
+ for row in text_rows:
+ x = 0.01
+ for t in row:
+ t.set_x(x)
+ width_px = t.get_window_extent(renderer=renderer).width
+ x += width_px / axes_width_px + gap_frac
+
+ _save_or_show(fig, save_path)
+
+
+# ================================================================================
+# Sanity-check visualization: attention BEFORE vs AFTER the bias intervention
+# 对比可视化:同一个样本在"不打补丁"和"打了补丁"两种状态下各跑一次单步forward,
+# 把最后一个query token(generate即将预测下一个词的位置)对图像/文本token的
+# attention分布画出来对比,直观展示"加偏置到底有没有真的把注意力从别处
+# 拉到了关键词/关键区域上",而不是只看最终divergence数值。
+# ================================================================================
+def _get_last_token_attn_to_positions(attentions, layer_indices, positions, seq_len):
+ """从某次forward的attentions里,取"最后一个query token对指定几层(取平均)
+ 、对positions里每个位置"的attention权重。跟BudgetedTokenAuction的
+ _rollout_attn_to_positions不同:这里不做跨层rollout传播,只是简单平均
+ 干预层本身的attention——因为这个函数的目的是"直接展示被真正打了偏置补丁
+ 的那几层,注意力具体是什么样子",不是估算"全局重要性",两者要回答的
+ 问题不一样,所以刻意选用更直接、更贴近干预点本身的口径(--attn_layers_
+ text/vis传入的层号),而不是拍卖打分那种更宽的全层rollout口径。
+ attentions[layer] shape: [1, num_heads, q_len, kv_len]。
+ 返回一个numpy一维数组,长度等于len(positions),取不到的位置补0。"""
+ valid_layers = sorted({l for l in layer_indices if 0 <= l < len(attentions)})
+ if not valid_layers or not positions:
+ return np.zeros(len(positions))
+ stacked = []
+ for layer in valid_layers:
+ a = attentions[layer][0].float().mean(dim=0).cpu() # [q_len, kv_len], averaged over heads
+ stacked.append(a[-1]) # last query token's attention row: [kv_len]
+ last_row = torch.stack(stacked, dim=0).mean(dim=0) # average across the selected layers
+ out = np.zeros(len(positions))
+ for i, p in enumerate(positions):
+ if 0 <= p < last_row.shape[0]:
+ out[i] = last_row[p].item()
+ return out
+
+
+def visualize_attn_before_after_region(image_path, orig_size, img_pos,
+ attn_before, attn_after, save_path=None,
+ num_patches=HUATUO_PATCHES):
+ """
+ 把偏置干预前(attn_before)/后(attn_after)的视觉attention各自reshape成
+ 24x24网格、resize叠加回原图,左右并排画成两张热力图(同一个颜色刻度,
+ 方便直接比较深浅),直观展示"加了偏置之后,模型对图像各区域的关注度
+ 到底有没有像预期那样发生变化"(关键区域应该变亮,非关键区域应该变暗)。
+
+ attn_before/attn_after: 长度为HUATUO_NUM_IMG_TOKENS的一维数组/tensor,
+ _get_last_token_attn_to_positions对range(img_pos, img_pos+576)算出来的
+ attention值(按patch顺序,即行优先展开的24x24网格)。
+
+ 坐标转换沿用visualize_masked_region同一套pad-square反变换。
+ """
+ import matplotlib.pyplot as plt
+
+ W, H = orig_size
+ side = max(W, H)
+ off_x = (side - W) // 2
+ off_y = (side - H) // 2
+
+ def _to_heatmap(attn_vec):
+ grid = np.asarray(attn_vec, dtype=np.float32).reshape(num_patches, num_patches)
+ img = Image.fromarray(grid, mode="F")
+ img = img.resize((side, side), resample=Image.BILINEAR)
+ crop_box = (off_x, off_y, off_x + W, off_y + H)
+ img = img.crop(crop_box)
+ img = img.resize((W, H), resample=Image.BILINEAR)
+ return np.array(img)
+
+ heat_before = _to_heatmap(attn_before)
+ heat_after = _to_heatmap(attn_after)
+ vmax = max(heat_before.max(), heat_after.max(), 1e-12)
+
+ src = Image.open(image_path).convert("RGB")
+ fig, axes = plt.subplots(1, 2, figsize=(8, 4 * H / W))
+ for ax, heat, title in zip(axes, [heat_before, heat_after], ["before bias", "after bias"]):
+ ax.imshow(src)
+ ax.imshow(heat, cmap="jet", alpha=0.5, vmin=0, vmax=vmax)
+ ax.set_title(title, fontsize=9)
+ ax.axis("off")
+ _save_or_show(fig, save_path)
+
+
+def render_attn_before_after_text(ids_list, tokenizer, attn_before, attn_after,
+ positions, img_start=None, img_end=None,
+ wrap_chars=70, save_path=None):
+ """
+ 把偏置干预前/后的文本token attention渲染成颜色深浅的高亮文字图(两行,
+ 上面一行是干预前,下面一行是干预后):每个token的背景色深浅按它在
+ positions里对应的attention值(相对于这次forward里positions内的最大值
+ 归一化)决定,深红=attention权重高,浅色/无背景=权重低,直接对比同一句
+ 文本在两种状态下,模型的注意力具体分配发生了什么变化。
+
+ attn_before/attn_after: 长度为len(positions)的一维数组,
+ _get_last_token_attn_to_positions对positions算出来的attention值,
+ positions通常是all_text_pos(问题正文里全部token),覆盖完整句子而不是
+ 只有关键词,这样才能看出"非关键词的attention是不是真的被压下去了"。
+
+ 其余排版逻辑(图像token折叠成
、两遍渲染量真实像素宽度)跟
+ render_masked_text_image完全一致。
+ """
+ import matplotlib.pyplot as plt
+
+ def _normalize(vec):
+ vec = np.asarray(vec, dtype=np.float32)
+ if vec.size == 0:
+ return vec
+ vmax = vec.max()
+ return vec / vmax if vmax > 1e-12 else vec
+
+ before_norm = _normalize(attn_before)
+ after_norm = _normalize(attn_after)
+ pos_to_idx = {p: i for i, p in enumerate(positions)}
+
+ def _build_fragments(attn_norm):
+ fragments = []
+ i = 0
+ n = len(ids_list)
+ while i < n:
+ if img_start is not None and img_end is not None and img_start <= i < img_end:
+ fragments.append(("
", None))
+ i = img_end
+ continue
+ tid = ids_list[i]
+ try:
+ frag = tokenizer.decode([int(tid)])
+ except Exception:
+ frag = ""
+ weight = attn_norm[pos_to_idx[i]] if i in pos_to_idx else None
+ fragments.append((frag, weight))
+ i += 1
+ return fragments
+
+ def _wrap(fragments):
+ lines = [[]]
+ cur_len = 0
+ for frag, weight in fragments:
+ if cur_len + len(frag) > wrap_chars and cur_len > 0:
+ lines.append([])
+ cur_len = 0
+ lines[-1].append((frag, weight))
+ cur_len += len(frag)
+ return lines
+
+ before_lines = _wrap(_build_fragments(before_norm))
+ after_lines = _wrap(_build_fragments(after_norm))
+
+ fontsize = 11
+ fig_w = 9.0
+ line_height_in = fontsize / 72 * 1.9
+ section_gap = 1 # blank lines between "before" and "after" sections
+ total_lines = len(before_lines) + len(after_lines) + section_gap + 2 # +2 for section labels
+ fig_h = line_height_in * (total_lines + 1)
+ fig, ax = plt.subplots(figsize=(fig_w, fig_h))
+ ax.axis("off")
+ ax.set_xlim(0, 1)
+ ax.set_ylim(0, 1)
+
+ all_rows = [] # list of (list_of_Text_objects, is_label_row)
+
+ def _emit_label(label_text, li):
+ y = 1 - (li + 1) / (total_lines + 1)
+ t = ax.text(0.01, y, label_text, fontsize=fontsize, family="monospace",
+ va="center", ha="left", fontweight="bold", transform=ax.transAxes)
+ return t
+
+ li = 0
+ _emit_label("[before bias]", li)
+ li += 1
+ li += len(before_lines)
+ li += section_gap
+ _emit_label("[after bias]", li)
+
+ # 第一遍:所有片段(跳过纯label行)先摆在x=0,创建Text对象。
+ li = 1 # row 0 is the "[before bias]" label, already emitted above
+ for line in before_lines:
+ y = 1 - (li + 1) / (total_lines + 1)
+ row = []
+ for frag, weight in line:
+ color = (1.0, 0.15, 0.15, 0.15 + 0.65 * weight) if weight is not None and weight > 0 else None
+ bbox = dict(facecolor=color, edgecolor="none", pad=2.5) if color else None
+ t = ax.text(0, y, frag, fontsize=fontsize, family="monospace",
+ va="center", ha="left", bbox=bbox, transform=ax.transAxes)
+ row.append(t)
+ all_rows.append(row)
+ li += 1
+ li += 1 + section_gap # skip "[after bias]" label row
+ for line in after_lines:
+ y = 1 - (li + 1) / (total_lines + 1)
+ row = []
+ for frag, weight in line:
+ color = (1.0, 0.15, 0.15, 0.15 + 0.65 * weight) if weight is not None and weight > 0 else None
+ bbox = dict(facecolor=color, edgecolor="none", pad=2.5) if color else None
+ t = ax.text(0, y, frag, fontsize=fontsize, family="monospace",
+ va="center", ha="left", bbox=bbox, transform=ax.transAxes)
+ row.append(t)
+ all_rows.append(row)
+ li += 1
+
+ fig.canvas.draw()
+ renderer = fig.canvas.get_renderer()
+ axes_width_px = ax.get_window_extent(renderer=renderer).width
+
+ gap_frac = 0.004
+ for row in all_rows:
+ x = 0.01
+ for t in row:
+ t.set_x(x)
+ width_px = t.get_window_extent(renderer=renderer).width
+ x += width_px / axes_width_px + gap_frac
+
+ _save_or_show(fig, save_path)
+
+
+# ================================================================================
+# Step B.5: Budgeted Token Auction (training-free, inference-time token selection)
+# ================================================================================
+#
+# 【中文总览】不开拍卖(--auction_enable不传)时,干预逻辑很朴素:"关键词/SAM区域
+# 全部加正偏置,其余全部加负偏置"。这套拍卖机制要解决的问题是:这种"全有全无"
+# 式的偏置太粗暴——比如某个关键词本来attention就已经很高了,再给它加正偏置,
+# 边际效果有限;而某个本来attention很低的非关键词patch,给它加负偏置也没有
+# 太大意义(它本来就没被关注)。拍卖机制让每个候选token按"打分"竞争一个有限的
+# "偏置名额预算",把预算花在真正"有改变空间"的token上:
+#
+# - 正向候选(关键词文本 + SAM视觉patch):打分 = 1-归一化attention,
+# 即"原始attention越低"分越高——这是模型"该关注但目前没怎么关注"的token,
+# 给它加正偏置才有意义去拉高它的权重;已经被关注很多的关键词,加了也提升有限。
+# (原来这里还有一个alpha*1的固定身份项和beta权重,但池子内所有候选的
+# 身份恒为1、beta又只是整体正数缩放,对select_topk_pooled的排序结果
+# 完全不影响,纯属死代码,已去掉。)
+# - 负向候选(非关键词文本 / 非SAM视觉,且原始attention高):打分 = 归一化attention,
+# 即"原始attention越高"分越高——这是模型"不该关注但目前关注很多"的干扰项,
+# 专门挑这些来压制,而不是无差别压制所有非关键token。
+#
+# 打分只用到本文件里已经算好的东西(attention权重、关键词/SAM成员身份),
+# 不涉及梯度、不需要标准答案、不需要训练——是纯推理时的token选择机制。
+#
+# Replaces "all SAM patches get +bias, all non-SAM patches get -bias" with a
+# scored, budget-limited selection:
+# - positive candidates (scispaCy keyword text + SAM visual patches) compete
+# for total_budget; among equally-flagged candidates, LOW original attention
+# wins -- these are the "important but currently under-attended" tokens a
+# correction can actually move, not the ones the model already attends to.
+# - negative candidates (non-keyword text / non-SAM visual with HIGH original
+# attention) compete for a single neg_total_budget pool -- these are the
+# "unimportant but currently over-attended" distractors to suppress.
+#
+# Bids use only quantities already computed elsewhere in this file (attention
+# scores, SAM/keyword membership) -- no gradients, no ground truth, no training.
+
+class BudgetedTokenAuction:
+ """Training-free token selection: each text/visual token "bids" for a slot in a
+ fixed attention-bias budget, using a membership indicator (scispaCy keyword /
+ SAM bbox) plus an attention term that rewards being under-attended (for
+ positive candidates) or over-attended (for negative candidates) -- amplifying
+ a token the model already attends to strongly has little room left to change
+ the output, so the budget is spent on tokens a correction can actually move.
+ Selection is a simple top-k per category, not a real economic clearing
+ mechanism -- "auction" here names the scoring-then-budget-limited-selection
+ pattern, not a market solver.
+ """
+
+ def __init__(self, total_ratio=0.1, neg_ratio=0.05):
+ """total_ratio: 正向预算占候选池大小的比例(如0.1=候选池的10%)。
+ neg_ratio: 负向预算占候选池大小的比例。
+ (原来这里还有alpha/beta两个打分公式权重,但两者都只是对同一个混池里
+ 全部候选做统一的常数加成/正数缩放,不改变select_topk_pooled的排序
+ 结果,对最终选择没有任何实际影响,已去掉,见score_text_tokens等函数。)
+ total_ratio / neg_ratio: budgets are computed per-sample as a fraction
+ of that sample's candidate pool size (len(all_text_positions) +
+ len(all_visual_positions)), rather than a fixed token count -- a fixed
+ budget like 64 makes no sense across samples with wildly different
+ question lengths, while a ratio scales with however many tokens are
+ actually in play for this sample."""
+ self.total_ratio = total_ratio
+ self.neg_ratio = neg_ratio
+
+ @staticmethod
+ def normalize(x):
+ """把一维tensor做min-max归一化到[0,1]区间。如果所有值都相等(常数输入),
+ 防止除0,直接返回全0。"""
+ if x.numel() == 0:
+ return x
+ lo, hi = x.min(), x.max()
+ if (hi - lo).abs().item() < 1e-12:
+ return torch.zeros_like(x)
+ return (x - lo) / (hi - lo)
+
+ @staticmethod
+ def _rollout_attn_to_positions(attentions, attn_layer_indices, positions, seq_len):
+ """中文说明:计算"attention rollout"分数——衡量从指定的几个position出发的
+ 信息,经过多层attention传播后,最终能流到"最后一个query token"(generate
+ 阶段即将生成下一个词时所在的位置)多少。
+ 为什么不直接对多层attention求平均?因为第l层的attention是基于第l层
+ "已经被前面层混合过的"隐藏状态算出来的,不是基于最原始的输入token,
+ 简单平均会忽略"这层的信号已经被之前层稀释/重塑过多少"这个事实。
+ Rollout的做法是把每层的(头平均后的)attention矩阵当成一个"转移矩阵",
+ 逐层相乘(矩阵乘法),这样能正确模拟"信息一步步经过多层传播"的过程。
+ 另外每层加了一个单位矩阵(残差项),因为transformer的残差连接允许信息
+ 完全跳过该层的attention操作直接往后传,所以每个位置始终保留一部分
+ "传给自己"的权重。
+ Attention-rollout score from the last query token to each of `positions`,
+ per Abnar & Zuidema 2020: each layer's head-averaged attention matrix is
+ treated as a transition matrix for how much information flows from each
+ earlier position into each later one. Matrices are composed (with a
+ residual +I term, since transformer residual connections let information
+ skip the attention op entirely) across layers in order, instead of being
+ averaged -- a plain average treats every layer's attention as directly
+ comparable evidence about "global importance," but layer l's attention
+ is computed over layer l's *already-mixed* hidden states, not the
+ original input tokens, so naively averaging raw per-layer attention
+ ignores how much each layer's signal has already been diluted/reshaped
+ by everything before it. Rollout instead asks "how much does information
+ originating at position p actually reach the final query position,
+ after propagating through every selected layer in sequence."
+ attentions[layer] shape: [1, num_heads, q_len, kv_len].
+ Returns a 1D tensor of shape [len(positions)] (CPU, float32)."""
+ if not positions or not attn_layer_indices:
+ return torch.zeros(len(positions))
+ valid_layers = sorted({l for l in attn_layer_indices if 0 <= l < len(attentions)})
+ if not valid_layers:
+ return torch.zeros(len(positions))
+
+ rollout = None
+ for layer in valid_layers:
+ # [1, heads, q_len, kv_len] -> [q_len, kv_len], averaged over heads
+ a = attentions[layer][0].float().mean(dim=0).cpu()
+ q_len, kv_len = a.shape
+ # residual connection: information can skip this layer's attention
+ # entirely, so each position always retains some weight on itself
+ a = a + torch.eye(q_len, kv_len)
+ a = a / a.sum(dim=-1, keepdim=True).clamp_min(1e-12)
+ rollout = a if rollout is None else a @ rollout
+
+ last_row = rollout[-1] # [kv_len]: rollout score from every position into the last query position
+ pos_t = torch.tensor([p for p in positions if p < seq_len], dtype=torch.long)
+ if pos_t.numel() == 0:
+ return torch.zeros(len(positions))
+ scores = last_row[pos_t]
+ if pos_t.numel() != len(positions):
+ # some positions were >= seq_len and got dropped; pad them back as 0
+ out = torch.zeros(len(positions))
+ valid_set = set(pos_t.tolist())
+ j = 0
+ for i, p in enumerate(positions):
+ if p in valid_set:
+ out[i] = scores[j]
+ j += 1
+ return out
+ return scores
+
+ def score_text_tokens(self, keyword_positions,
+ attentions, attn_layer_indices, seq_len):
+ """文本侧正向候选打分:候选池就是scispaCy关键词本身(keyword_positions),
+ 不是全部问题文本——这一点跟score_visual_tokens"只在SAM筛过的patch里打分"
+ 是对称的,保证文本侧和视觉侧拍卖时面对的候选池规模是同一量级的预筛选
+ 结果,而不是文本侧用全部问题token的大池子、视觉侧只用SAM命中的小池子
+ 这种不对称比较。
+ bid = 1 - normalized_attention, scored over the scispaCy keyword
+ candidates themselves -- mirrors score_visual_tokens' "score only the
+ pre-filtered SAM candidates" rule on the text side, so both sides
+ compete over an equally pre-filtered candidate pool (keywords / SAM
+ patches) rather than text getting the much larger "every question
+ token" pool while vis is restricted to SAM hits.
+ The attention term rewards LOW original attention: a keyword the model is
+ already attending to strongly has little room left for a correction to
+ change; the ones worth amplifying are keywords currently under-attended."""
+ if not keyword_positions:
+ return [], torch.zeros(0)
+ attn = self._rollout_attn_to_positions(attentions, attn_layer_indices,
+ keyword_positions, seq_len)
+ attn_norm = self.normalize(attn)
+ bid = 1.0 - attn_norm
+ return keyword_positions, bid
+
+ def score_negative_text_tokens(self, all_text_positions, keyword_positions,
+ attentions, attn_layer_indices, seq_len):
+ """文本侧负向候选打分:候选池是"问题正文里所有不属于关键词的token",
+ 打分=归一化后的原始attention(attention越高分越高)——挑的是"模型本不该
+ 关注、但实际关注很多"的非关键文本,作为压制对象。
+ Candidates are question-text positions NOT in the keyword set; bid =
+ normalized original attention (high attention + not a scispaCy keyword =
+ the model is dwelling on text that isn't flagged as clinically relevant --
+ mirrors score_negative_visual_tokens' "high attention, not in the key set"
+ rule on the text side)."""
+ kw_set = set(keyword_positions or [])
+ candidates = [p for p in (all_text_positions or []) if p not in kw_set]
+ if not candidates:
+ return [], torch.zeros(0)
+ attn = self._rollout_attn_to_positions(attentions, attn_layer_indices, candidates, seq_len)
+ bid = self.normalize(attn)
+ return candidates, bid
+
+ def score_visual_tokens(self, sam_visual_positions, attentions, attn_layer_indices, seq_len):
+ """视觉侧正向候选打分:候选池是SAM预测出的bbox对应的patch本身,逻辑跟
+ score_text_tokens完全对称。
+ bid = 1 - normalized_attention, scored over the SAM candidates
+ themselves. The attention term rewards LOW original attention, same
+ rationale as score_text_tokens: a SAM patch the model is already
+ attending to strongly has little room left for a correction to
+ change; the ones worth amplifying are SAM-relevant patches the model
+ is currently under-attending to."""
+ if not sam_visual_positions:
+ return [], torch.zeros(0)
+ attn = self._rollout_attn_to_positions(attentions, attn_layer_indices,
+ sam_visual_positions, seq_len)
+ attn_norm = self.normalize(attn)
+ bid = 1.0 - attn_norm
+ return sam_visual_positions, bid
+
+ def score_negative_visual_tokens(self, all_visual_positions, sam_visual_positions,
+ attentions, attn_layer_indices, seq_len):
+ """视觉侧负向候选打分:候选池是576个视觉patch里不属于SAM区域的那些,
+ 打分=归一化attention,逻辑跟score_negative_text_tokens完全对称。
+ Candidates are visual patches NOT in the SAM set; bid = normalized original
+ attention (high original attention + not SAM-relevant = likely distractor)."""
+ sam_set = set(sam_visual_positions or [])
+ candidates = [p for p in all_visual_positions if p not in sam_set]
+ if not candidates:
+ return [], torch.zeros(0)
+ attn = self._rollout_attn_to_positions(attentions, attn_layer_indices,
+ candidates, seq_len)
+ bid = self.normalize(attn)
+ return candidates, bid
+
+ @staticmethod
+ def select_topk_pooled(groups, k):
+ """统一池子里选top-k:groups是[(候选位置列表, 打分, 类别标签), ...],
+ 比如文本类和视觉类各自的候选+打分。这里把所有类别的候选混到一个池子
+ 一起排序,取总分前k个——这样"k个名额里文本占几个、视觉占几个"是由
+ 这个样本实际的打分结果决定的,不是事先写死"8个文本+32个视觉"这种
+ 固定配比,更能适应不同样本里文本/视觉哪边更值得偏置的情况不同。
+ Unified-pool top-k: groups is [(positions, bid, label), ...] for two or
+ more categories (e.g. text and vis). All candidates are merged into one
+ ranked pool and the top k overall are taken, so the split between
+ categories is decided by this sample's actual bid scores rather than
+ being fixed in advance (e.g. "8 text + 32 vis" regardless of content).
+ Returns dict {label: [selected positions for that label]}.
+ """
+ pool = []
+ for positions, bid, label in groups:
+ for p, b in zip(positions, bid.tolist() if hasattr(bid, "tolist") else bid):
+ pool.append((p, b, label))
+ result = {label: [] for _, _, label in groups}
+ if k <= 0 or not pool:
+ return result
+ pool.sort(key=lambda x: x[1], reverse=True)
+ for p, b, label in pool[:k]:
+ result[label].append(p)
+ return result
+
+ def clear_market(self, top_text_positions, all_text_positions, vis_patches,
+ img_start, seq_len, attentions,
+ attn_layer_indices_text, attn_layer_indices_vis,
+ text_enabled=True, vis_enabled=True):
+ """中文总览:这是拍卖机制的总入口,每个样本调用一次,完成"打分->按预算
+ 选出最终要加偏置的token集合"全过程。流程:
+ 1. 根据text_enabled/vis_enabled,决定候选池范围(见下面对这两个参数的
+ 详细说明,这是修复"消融模式下候选池没被正确清零"问题的关键)。
+ 2. 算total_budget(正向预算)和neg_total_budget(负向预算):分别是
+ "各自候选池自身大小 × 对应ratio"——正向预算相对关键区域大小
+ (key_region_size)算,负向预算相对负向候选池大小(negative_pool_
+ size = 全池子减去关键区域)算,而不是固定数字或者共用同一个
+ 分母——这样两个ratio各自表示"在自己那个候选池里选多大比例",
+ 不会因为关键区域/背景区域谁大谁小而互相干扰。
+ 3. 文本侧、视觉侧各自调用score_text_tokens/score_visual_tokens打分
+ (正向候选打分),混进同一个池子用select_topk_pooled选出
+ selected_text/selected_vis。
+ 4. 文本侧、视觉侧各自调用score_negative_text_tokens/
+ score_negative_visual_tokens打分(负向候选打分),同样混池选出
+ selected_neg_text/selected_neg。
+ 5. 防御性去重:确保正向选中的token不会同时出现在负向选中集合里
+ (理论上score_negative_*已经从候选池排除了正向集合,这里是双重保险)。
+ 返回(selected_text, selected_vis, selected_neg, selected_neg_text),
+ 分别对应"最终要加正偏置的文本位置/视觉位置"和"最终要加负偏置的视觉
+ 位置/文本位置",会被传给_AttnInterventionContext去真正构造偏置向量。
+ Budget clearing: positive candidates (text keywords + SAM-visual patches)
+ compete for a total_budget pool sized total_ratio * key_region_size,
+ where key_region_size = len(top_text_positions) + len(vis_patches) --
+ the size of the KEY region itself. Negative candidates (non-keyword
+ text + non-SAM visual, both with high original attention) compete for a
+ separate pool sized neg_ratio * negative_pool_size, where
+ negative_pool_size = full_pool_size - key_region_size (full_pool_size =
+ len(all_text_positions) + len(all_visual_positions)) -- the size of the
+ actual negative CANDIDATE pool (score_negative_text_tokens/
+ score_negative_visual_tokens draw their candidates from exactly this
+ set: all positions minus the key region).
+ Both denominators were previously computed as the same quantity --
+ full_pool_size -- for BOTH budgets. That was wrong on the positive side:
+ positive candidates only ever compete within key_region_size (a few
+ dozen SAM patches/keywords), so at total_ratio=0.7 with a ~600-token
+ full pool, the resulting budget (~420) vastly exceeded the actual
+ candidate pool, and select_topk_pooled's `pool[:k]` silently degenerated
+ into "select everything" (see visualize_rollout_region output:
+ near-total red/cyan coverage instead of a sparse, selective highlight).
+ Scaling total_budget off key_region_size instead means total_ratio
+ consistently means "select this fraction OF THE KEY REGION," comparable
+ across samples with wildly different image sizes/question lengths.
+ The negative side's own candidate pool is genuinely the large
+ background/distractor region, so neg_ratio correctly means "select this
+ fraction OF THE BACKGROUND/DISTRACTOR POOL" when scaled by
+ negative_pool_size -- unlike the positive side, this was never a
+ denominator bug; a high neg_ratio like 0.7 is instead a hyperparameter
+ choice that should usually be much smaller (e.g. 0.05) if a sparse
+ suppression pattern is desired.
+ Within each pool, the split between text and vis is decided by the bid
+ scores themselves, not fixed in advance.
+ Note: the *positive* candidate pool itself is pre-filtered symmetrically on
+ both sides -- text bids only over top_text_positions (scispaCy keywords),
+ vis bids only over vis_patches (SAM patches), not over the full
+ all_text_positions/576-patch pools. The *negative* pool draws from the
+ full pools (all_visual_positions/all_text_positions minus the key
+ region) -- suppressing distractors is inherently a "look across the
+ whole background" operation, and its budget now correctly scales with
+ that background's own size, not the (much smaller, unrelated) key
+ region's size.
+ top_text_positions: flat list of scispaCy keyword text positions (the
+ same list _AttnInterventionContext already merges into self._kw_positions;
+ also the positive-side candidate pool for the text bid, and part of
+ the key_region_size denominator).
+ all_text_positions: all question-text positions (the negative-side
+ candidate pool after excluding top_text_positions, and part of the
+ full_pool_size/negative_pool_size denominators).
+ vis_patches: SAM-derived visual patch indices (positive-side candidate
+ pool for the vis bid, and part of the key_region_size denominator).
+ img_start: first visual-token position; the full visual range is
+ [img_start, img_start + HUATUO_NUM_IMG_TOKENS).
+ attn_layer_indices_text/vis: which layers' attention to average for
+ bidding -- intentionally the full set of model layers (not just the
+ layer(s) the bias is injected at), since a single layer's attention
+ can be a noisy proxy for "is this token globally important."
+ text_enabled/vis_enabled: whether that modality actually participates in
+ this run (False for the disabled side under --intervention text/vis).
+ key_region_size/negative_pool_size -- and therefore both budgets --
+ are computed only over the enabled side(s); otherwise the disabled
+ side's vis_patches/all_visual_positions (or top_text_positions/
+ all_text_positions) would inflate the denominators even though they
+ contribute zero candidates.
+ Returns (selected_text_positions, selected_vis_patches,
+ selected_negative_vis_patches, selected_negative_text_positions).
+ """
+ # ── 关键修复点:text_enabled/vis_enabled必须能让"对应模态彻底参与不进
+ # 拍卖",不能只影响候选池大小的分母。如果vis_enabled=False只是把
+ # all_visual_positions清空,但vis_patches(正向候选池本身)没清空,
+ # score_visual_tokens依然会在vis_patches上打分、依然可能被选中——
+ # 等于"分母被排除了,但分子(候选)没被排除",--intervention text模式
+ # 下视觉侧理应完全不参与,这里把vis_patches/top_text_positions也
+ # 一起清空,让禁用侧从源头上不产生任何候选,而不依赖"上游传进来的
+ # 就是空值"这种隐性假设。──────────────────────────────────────
+ if img_start is not None and vis_enabled:
+ all_visual_positions = list(range(img_start, img_start + HUATUO_NUM_IMG_TOKENS))
+ else:
+ all_visual_positions = []
+ vis_patches = []
+ if not text_enabled:
+ all_text_positions = []
+ top_text_positions = []
+ # ── 正向预算分母改用"关键区域自身大小"(len(top_text_positions)+
+ # len(vis_patches)),不再用"全池子大小"(len(all_text_positions)+
+ # len(all_visual_positions))。原因:正向候选本来就已经被限定在关键
+ # 区域内部竞争(score_text_tokens/score_visual_tokens只在
+ # top_text_positions/vis_patches上打分),但旧代码预算却按576+文本
+ # 长度的全池子比例算——当ratio设得较大(比如0.7)、而关键区域本身很小
+ # (只有几十个SAM patch/关键词)时,算出来的预算数字远超候选池大小,
+ # select_topk_pooled的`pool[:k]`会退化成"全部选中",完全失去"择优"
+ # 的意义(这正是0.7配置下rollout可视化里出现"几乎整张图铺满红框"的
+ # 真正原因)。
+ #
+ # 负向预算分母则是"负向候选池自身的大小",即"全池子减去关键区域"
+ # (full_pool_size - key_region_size)——因为score_negative_text_tokens/
+ # score_negative_visual_tokens的候选池定义本来就是"all_positions里
+ # 排除掉key_set之后剩下的部分",负向预算必须按这个负向候选池自己的
+ # 规模来算比例,而不是套用正向区域的规模(那样会让neg_ratio实际选中
+ # 的数量被压缩成远小于负向候选池的一小撮,跟neg_ratio这个名字本身
+ # 想表达的"负向候选池里选多大比例"完全对不上)。
+ #
+ # 两者分母不同、但各自都是"对应候选池自己的大小",这才是一致的设计:
+ # total_ratio表示"关键区域里选多大比例",neg_ratio表示"背景/干扰区域
+ # 里选多大比例",两个比例各自独立、各自相对自己的候选池,不会因为
+ # 关键区域大小的变化而互相干扰。
+ # 如果被禁用的一侧仍然计入这两个分母,会被禁用侧的候选虚高,导致
+ # 预算实际上远超启用侧候选数量,变成"几乎全选"而不是真正的按比例
+ # 限额,所以这里跟all_visual_positions/all_text_positions一样,也要
+ # 用"清零后"的top_text_positions/vis_patches。
+ key_region_size = len(top_text_positions) + len(vis_patches)
+ full_pool_size = len(all_text_positions) + len(all_visual_positions)
+ negative_pool_size = full_pool_size - key_region_size
+ total_budget = math.ceil(self.total_ratio * key_region_size)
+ neg_total_budget = math.ceil(self.neg_ratio * negative_pool_size)
+
+ # ── 第一轮拍卖:正向候选(关键词文本 + SAM视觉patch),混池竞争total_budget个名额 ──
+ text_positions, text_bid = self.score_text_tokens(
+ top_text_positions, attentions, attn_layer_indices_text, seq_len)
+ vis_positions, vis_bid = self.score_visual_tokens(
+ vis_patches, attentions, attn_layer_indices_vis, seq_len)
+
+ positive_pool = self.select_topk_pooled(
+ [(text_positions, text_bid, "text"), (vis_positions, vis_bid, "vis")],
+ total_budget)
+ selected_text = positive_pool["text"]
+ selected_vis = positive_pool["vis"]
+
+ # ── 第二轮拍卖:负向候选(非关键词文本 + 非SAM视觉,原始attention高),
+ # 混池竞争neg_total_budget个名额 ──────────────────────────────
+ neg_positions, neg_bid = self.score_negative_visual_tokens(
+ all_visual_positions, vis_patches, attentions, attn_layer_indices_vis, seq_len)
+ neg_text_positions, neg_text_bid = self.score_negative_text_tokens(
+ all_text_positions, top_text_positions, attentions, attn_layer_indices_text, seq_len)
+
+ negative_pool = self.select_topk_pooled(
+ [(neg_positions, neg_bid, "vis"), (neg_text_positions, neg_text_bid, "text")],
+ neg_total_budget)
+ selected_neg = negative_pool["vis"]
+ selected_neg_text = negative_pool["text"]
+
+ # selected_vis/selected_neg 以及 selected_text/selected_neg_text 理论上
+ # 不会重叠(score_negative_*在构造候选池时已经排除了正向集合成员),这里
+ # 只是双重防御性校验,防止两边候选池算出来的结果有边界情况重叠。
+ selected_vis_set = set(selected_vis)
+ selected_neg = [p for p in selected_neg if p not in selected_vis_set]
+ selected_text_set = set(selected_text)
+ selected_neg_text = [p for p in selected_neg_text if p not in selected_text_set]
+
+ return selected_text, selected_vis, selected_neg, selected_neg_text
+
+
+# ================================================================================
+# Sanity-check visualization: rollout attention (the auction's own bidding signal)
+# 抽查可视化:把BudgetedTokenAuction真正用来打分/选择的rollout attention分数本身
+# 画出来,并叠加拍卖选中结果——跟visualize_attn_before_after_region/
+# render_attn_before_after_text(用的是_get_last_token_attn_to_positions,即
+# --attn_layers_text/vis指定的、真正注入偏置的那几层的原始attention平均)是
+# 两套不同的数值:那两个函数展示的是"干预层本身的attention有没有变化",这里
+# 展示的是"拍卖决策依据(全层rollout分数)长什么样、拍卖到底选中了谁",两者
+# 回答的问题不同,不能互相替代。
+# ================================================================================
+def visualize_rollout_region(image_path, orig_size, img_pos, rollout_scores,
+ selected_positive=None, selected_negative=None,
+ save_path=None, num_patches=HUATUO_PATCHES):
+ """
+ 把576个视觉patch的rollout attention分数(BudgetedTokenAuction.
+ _rollout_attn_to_positions对全部视觉token算出来的原始打分依据,取值范围
+ 未归一化)画成热力图叠加在原图上,同时用红色/蓝色边框分别标出被拍卖选中
+ 的正向(selected_positive,会被加正偏置)/负向(selected_negative,会被加
+ 负偏置压制)patch——这样能直接看出"拍卖选中的到底是rollout分数高的还是
+ 低的patch",验证Step B.5文档里"正向候选选rollout低的、负向候选选rollout
+ 高的"这条设计是否在真实样本上如实生效。
+
+ rollout_scores: 长度为HUATUO_NUM_IMG_TOKENS的一维数组,按patch顺序
+ (行优先展开的24x24网格),未归一化的原始rollout分数。
+ selected_positive/selected_negative: 绝对token位置列表(img_pos+patch_idx
+ 形式,跟vis_patches_for_ctx/negative_vis_patches是同一套坐标系)。
+
+ 坐标转换沿用visualize_masked_region/visualize_attn_before_after_region
+ 同一套pad-square反变换。
+ """
+ import matplotlib.pyplot as plt
+ import matplotlib.patches as mpatches
+
+ W, H = orig_size
+ side = max(W, H)
+ off_x = (side - W) // 2
+ off_y = (side - H) // 2
+ scale = max(W, H) / num_patches # patch size in original-image pixels
+
+ grid = np.asarray(rollout_scores, dtype=np.float32).reshape(num_patches, num_patches)
+ img = Image.fromarray(grid, mode="F")
+ img = img.resize((side, side), resample=Image.BILINEAR)
+ crop_box = (off_x, off_y, off_x + W, off_y + H)
+ img = img.crop(crop_box)
+ img = img.resize((W, H), resample=Image.BILINEAR)
+ heat = np.array(img)
+
+ src = Image.open(image_path).convert("RGB")
+ fig, ax = plt.subplots(figsize=(5, 5 * H / W))
+ ax.imshow(src)
+ ax.imshow(heat, cmap="jet", alpha=0.5, vmin=0, vmax=max(heat.max(), 1e-12))
+
+ # 把选中的patch下标(绝对位置)转回(row, col)网格坐标,再转成pad-square坐标系
+ # 下的像素矩形,画一个无填充色的描边框(红=正向选中,蓝=负向选中)。
+ def _draw_boxes(positions, color):
+ for p in (positions or []):
+ rel = p - img_pos
+ if not (0 <= rel < num_patches * num_patches):
+ continue
+ row, col = divmod(rel, num_patches)
+ px1 = col * scale - off_x
+ py1 = row * scale - off_y
+ rect = mpatches.Rectangle(
+ (px1, py1), scale, scale,
+ linewidth=1.2, edgecolor=color, facecolor="none",
+ )
+ ax.add_patch(rect)
+
+ _draw_boxes(selected_positive, "red")
+ _draw_boxes(selected_negative, "cyan")
+ ax.set_xlim(0, W)
+ ax.set_ylim(H, 0)
+ ax.axis("off")
+ _save_or_show(fig, save_path)
+
+
+def render_rollout_text(ids_list, tokenizer, rollout_scores, positions,
+ selected_positive=None, selected_negative=None,
+ img_start=None, img_end=None, wrap_chars=70, save_path=None):
+ """
+ 把问题文本每个token的rollout attention分数(BudgetedTokenAuction用来打分的
+ 同一套依据)渲染成颜色深浅的高亮文字图,同时给被拍卖选中的正向词(红色实心
+ 背景)/负向词(蓝色实心背景)加粗高亮,其余token按rollout分数深浅显示灰度
+ 背景——这样能直接读出"这句话里rollout分数最高/最低的分别是哪些词,拍卖
+ 实际选中的词是不是真的对应了'该关注但没被关注'(正向,通常rollout较低)
+ 或'不该关注但被关注很多'(负向,通常rollout较高)这两类"。
+
+ rollout_scores: 长度为len(positions)的一维数组,跟positions一一对应,
+ 未归一化的原始rollout分数(函数内部会自己做min-max归一化用于配色)。
+ selected_positive/selected_negative: 绝对token位置列表。
+ """
+ import matplotlib.pyplot as plt
+
+ def _normalize(vec):
+ vec = np.asarray(vec, dtype=np.float32)
+ if vec.size == 0:
+ return vec
+ lo, hi = vec.min(), vec.max()
+ return (vec - lo) / (hi - lo) if (hi - lo) > 1e-12 else np.zeros_like(vec)
+
+ norm_scores = _normalize(rollout_scores)
+ pos_to_idx = {p: i for i, p in enumerate(positions)}
+ positive_set = set(selected_positive or [])
+ negative_set = set(selected_negative or [])
+
+ fragments = []
+ i = 0
+ n = len(ids_list)
+ while i < n:
+ if img_start is not None and img_end is not None and img_start <= i < img_end:
+ fragments.append(("
", None, "img"))
+ i = img_end
+ continue
+ tid = ids_list[i]
+ try:
+ frag = tokenizer.decode([int(tid)])
+ except Exception:
+ frag = ""
+ weight = norm_scores[pos_to_idx[i]] if i in pos_to_idx else None
+ kind = "positive" if i in positive_set else ("negative" if i in negative_set else "normal")
+ fragments.append((frag, weight, kind))
+ i += 1
+
+ lines = [[]]
+ cur_len = 0
+ for frag, weight, kind in fragments:
+ if cur_len + len(frag) > wrap_chars and cur_len > 0:
+ lines.append([])
+ cur_len = 0
+ lines[-1].append((frag, weight, kind))
+ cur_len += len(frag)
+
+ fontsize = 11
+ fig_w = 9.0
+ line_height_in = fontsize / 72 * 1.9
+ fig_h = line_height_in * (len(lines) + 1)
+ fig, ax = plt.subplots(figsize=(fig_w, fig_h))
+ ax.axis("off")
+ ax.set_xlim(0, 1)
+ ax.set_ylim(0, 1)
+
+ text_rows = []
+ for li, line in enumerate(lines):
+ y = 1 - (li + 1) / (len(lines) + 1)
+ row = []
+ for frag, weight, kind in line:
+ if kind == "positive":
+ color = (1.0, 0.2, 0.2, 0.75) # solid-ish red: auction-selected positive
+ elif kind == "negative":
+ color = (0.2, 0.75, 0.95, 0.75) # solid-ish cyan: auction-selected negative
+ elif kind == "img":
+ color = (0.6, 0.6, 0.6, 0.5)
+ elif weight is not None and weight > 0:
+ color = (0.3, 0.3, 0.3, 0.12 + 0.35 * weight) # grayscale by raw rollout score
+ else:
+ color = None
+ bbox = dict(facecolor=color, edgecolor="none", pad=2.5) if color else None
+ t = ax.text(
+ 0, y, frag, fontsize=fontsize, family="monospace",
+ va="center", ha="left", bbox=bbox, transform=ax.transAxes,
+ )
+ row.append(t)
+ text_rows.append(row)
+
+ fig.canvas.draw()
+ renderer = fig.canvas.get_renderer()
+ axes_width_px = ax.get_window_extent(renderer=renderer).width
+
+ gap_frac = 0.004
+ for row in text_rows:
+ x = 0.01
+ for t in row:
+ t.set_x(x)
+ width_px = t.get_window_extent(renderer=renderer).width
+ x += width_px / axes_width_px + gap_frac
+
+ _save_or_show(fig, save_path)
+
+
+# ================================================================================
+# Step C: Attention intervention context manager
+# 这是一个Python上下文管理器(with语句配套类):进入with块时,把指定层的
+# self-attention forward替换成带偏置的版本(调用上面的_patch_attn_forward_
+# with_key_bias);退出with块时,把forward还原。在__init__阶段只是记录参数,
+# 真正构造偏置向量、打补丁是在__enter__里完成的。
+# ================================================================================
+class _AttnInterventionContext:
+ """
+ Within the with block, replaces attention forward of specified layers with a
+ pre-softmax key-bias intervention version.
+ both mode: key text tokens + salient visual patches (union) get a positive
+ bias; all other positions get the non-key bias.
+ """
+ def __init__(self, bot, intervention,
+ top_text_positions=None,
+ all_text_positions=None,
+ attn_layer_indices_text=None,
+ key_bias_text=3.0, nonkey_bias_text=0.0,
+ img_pos=None, seq_len=None,
+ attn_layer_indices_vis=None,
+ key_bias_vis=3.0, nonkey_bias_vis=0.0,
+ vis_key_patches=None,
+ negative_vis_patches=None,
+ negative_text_positions=None):
+ self._patched = []
+ self.intervention = intervention
+ self._img_pos = img_pos
+ all_layers = _get_attn_layers(bot)
+
+ # ── 文本侧关键位置:把top_text_positions(可能是嵌套list)拍平去重,
+ # 得到self._kw_positions——这些位置后面会被加正偏置(key_bias_text)。
+ seen, merged = set(), []
+ for ep in (top_text_positions or []):
+ for p in ep:
+ if p not in seen:
+ seen.add(p)
+ merged.append(p)
+ self._kw_positions = merged
+ self._all_text_positions = list(all_text_positions or [])
+ self._key_bias_text = float(key_bias_text)
+ self._nonkey_bias_text = float(nonkey_bias_text)
+ text_indices = [int(i) for i in (attn_layer_indices_text or []) if i is not None]
+ self._text_layers = [all_layers[i] for i in text_indices if 0 <= i < len(all_layers)]
+
+ # ── 视觉侧关键位置:SAM bbox对应的patch,后面加正偏置(key_bias_vis)。
+ vis_seen, vis_merged = set(), []
+ for p in (vis_key_patches or []):
+ if p not in vis_seen:
+ vis_seen.add(p)
+ vis_merged.append(p)
+ self._vis_key_positions = vis_merged
+ self._key_bias_vis = float(key_bias_vis)
+ self._nonkey_bias_vis = float(nonkey_bias_vis)
+ vis_indices = [int(i) for i in (attn_layer_indices_vis or []) if i is not None]
+ self._vis_layers = [all_layers[i] for i in vis_indices if 0 <= i < len(all_layers)]
+
+ # ── 拍卖模式(可选):如果传入了显式的negative_vis_patches/
+ # negative_text_positions(由BudgetedTokenAuction.clear_market算出来),
+ # 就只对这些被选中的"负向候选"加负偏置;如果没传(即不开拍卖的朴素模式),
+ # 下面__enter__里nonkey_img_set/nonkw_text_set会退化成"全部非关键位置"——
+ # 也就是最初朴素的"关键词/SAM区域加正偏置,其余全部加负偏置"逻辑。
+ self._negative_vis_patches = (list(dict.fromkeys(negative_vis_patches))
+ if negative_vis_patches is not None else None)
+ self._negative_text_positions = (list(dict.fromkeys(negative_text_positions))
+ if negative_text_positions is not None else None)
+
+ def __enter__(self):
+ # intervention=="none"时不做任何替换,直接原样返回(用于消融对照的
+ # "完全不干预"基线)。
+ if self.intervention == "none":
+ return self
+
+ img_pos = self._img_pos
+ img_set = set(range(img_pos, img_pos + HUATUO_NUM_IMG_TOKENS)) if img_pos is not None else set()
+ kw_set = set(self._kw_positions)
+ vis_set = set(self._vis_key_positions)
+ if self._negative_vis_patches is not None:
+ # 拍卖模式:只压制拍卖选中的"视觉干扰项",图像里其余位置保持中性(偏置0),
+ # 而不是压制全部非关键patch。
+ # Budgeted auction selected an explicit set of negative (distractor)
+ # patches -- only those get nonkey_bias_vis; everything else in the
+ # image stays at 0 (neutral), instead of suppressing all non-key patches.
+ nonkey_img_set = set(self._negative_vis_patches) - vis_set
+ else:
+ # 朴素模式:图像里除了关键patch之外的全部位置都加负偏置。
+ nonkey_img_set = img_set - vis_set
+
+ kbt = self._key_bias_text; nbt = self._nonkey_bias_text
+ kbv = self._key_bias_vis; nbv = self._nonkey_bias_vis
+
+ # 预先把各类位置集合转成tensor索引,供下面make_bias里做批量赋值
+ all_text_set = set(self._all_text_positions)
+ if self._negative_text_positions is not None:
+ # 拍卖模式:只压制拍卖选中的"文本干扰项"(原始attention高但非关键词),
+ # 问题文本里其余位置保持中性(偏置0),跟视觉侧逻辑对称。
+ # Budgeted auction selected an explicit set of negative (high-attention,
+ # non-keyword) text positions -- only those get nonkey_bias_text;
+ # everything else in the question text stays at 0 (neutral), instead of
+ # suppressing all non-keyword text (mirrors the visual side above).
+ nonkw_text_set = set(self._negative_text_positions) - kw_set
+ else:
+ # 朴素模式:问题文本里除了关键词之外的全部token都加负偏置。
+ nonkw_text_set = all_text_set - kw_set
+ kw_idx = torch.tensor(sorted(kw_set), dtype=torch.long) if kw_set else None
+ vis_idx = torch.tensor(sorted(vis_set), dtype=torch.long) if vis_set else None
+ nonkey_img_idx = torch.tensor(sorted(nonkey_img_set), dtype=torch.long) if nonkey_img_set else None
+ nonkw_text_idx = torch.tensor(sorted(nonkw_text_set), dtype=torch.long) if nonkw_text_set else None
+
+ # 构造最终偏置向量的函数,会被传给_patch_attn_forward_with_key_bias
+ # 当作bias_vec_fn,在每次attention forward时被调用一次。
+ # 默认偏置是0:图像/文本之外的prefix/suffix/prompt模板token不受影响。
+ # 问题文本里:非关键词部分加nbt(负偏置),关键词部分加kbt(正偏置)。
+ # 图像里:非关键patch加nbv(负偏置),关键patch加kbv(正偏置)。
+ # 注意赋值顺序:先写非关键(nbt/nbv)再写关键(kbt/kbv),这样如果某个
+ # 位置因为边界情况同时落入两个集合,关键偏置会覆盖非关键偏置生效。
+ def make_bias(kv_len):
+ b = torch.zeros(kv_len)
+ if nonkw_text_idx is not None:
+ b[nonkw_text_idx[nonkw_text_idx < kv_len]] = nbt # non-keyword question text
+ if nonkey_img_idx is not None:
+ b[nonkey_img_idx[nonkey_img_idx < kv_len]] = nbv # non-key patches
+ if vis_idx is not None:
+ b[vis_idx[vis_idx < kv_len]] = kbv # key patches
+ if kw_idx is not None:
+ b[kw_idx[kw_idx < kv_len]] = kbt # keyword text
+ return b
+ all_tgt_layers = {id(l): l for l in set(self._text_layers + self._vis_layers)}
+ for _, layer in all_tgt_layers.items():
+ old_fwd = _patch_attn_forward_with_key_bias(
+ layer, tag="both", bias_vec_fn=make_bias)
+ self._patched.append((layer, old_fwd))
+
+ return self
+
+ def __exit__(self, *args):
+ for layer, old_fwd in self._patched:
+ layer.forward = old_fwd
+ if hasattr(layer, "_bias_printed_both"):
+ delattr(layer, "_bias_printed_both")
+ self._patched = []
+
+
+# ================================================================================
+# SAM bbox lookup helper
+# ================================================================================
+def _set_attn_impl(model, impl):
+ """切换模型的attention实现方式("eager"/原本的flash等)。需要拿attention权重
+ (抽取关键词位置、auction打分)时必须切到"eager",因为只有eager实现会真正
+ 把attention权重作为输出返回;用完之后切回原来的实现以保证正常生成时的速度。"""
+ for m in model.modules():
+ if hasattr(m, "_attn_implementation"):
+ m._attn_implementation = impl
+ if hasattr(m, "config") and hasattr(m.config, "_attn_implementation"):
+ m.config._attn_implementation = impl
+ model.config._attn_implementation = impl
+
+
+def _get_sam_bbox_text(obj_name: str, pil_image, medsam3, max_bbox=1):
+ """对一张图调用MedSAM3,针对obj_name(物体名字符串)做分割定位,最多返回
+ max_bbox个"obj_name: [x1,y1,x2,y2]"格式的bbox字符串,以及合并后的分割
+ 掩码(numpy数组;SAM没找到东西时返回None)。
+ Run SAM on a PIL image for obj_name, return at most max_bbox 'obj_name: [x1,y1,x2,y2]'
+ strings plus the combined segmentation mask (numpy array, or None if SAM produced no mask)."""
+ try:
+ bbox_list, mask, info = medsam3.predict_bbox(pil_image, obj_name)
+ if not bbox_list:
+ return [], None
+ lines = [f"{obj_name}: [{x1},{y1},{x2},{y2}]" for x1, y1, x2, y2 in bbox_list[:max_bbox]]
+ return lines, mask
+ except Exception as e:
+ print(f"[SAM] failed for '{obj_name}': {e}")
+ return [], None
+
+
+def _build_objects_prompt(question: str, scispacy_keywords=None) -> str:
+ """构造"Stage1"提示词:让模型(不是SAM本身)先列出图里"可以被SAM分割的物体
+ 名字"列表,给后面真正调用SAM时用作查询词。这是一个两阶段流程:
+ Stage1(这里): 模型根据问题猜"应该关注图里哪些结构" -> 输出物体名字符串列表
+ Stage2(_get_sam_bbox_text): 拿这些物体名字依次喂给MedSAM3,得到具体bbox
+ Stage1 prompt: ask the model for SAM-segmentable objects only (no image caption).
+
+ scispacy_keywords are offered as candidates the model should prefer when they are
+ genuine segmentable structures; if none qualify (or more are needed), the model
+ fills the rest itself, up to 5 objects total.
+
+ "这道题有没有具体可分割目标"这个判断,现在由Stage0(_build_global_local_prompt,
+ 贪婪解码、结果稳定)在调用这个函数之前就做完了——is_global=True的样本根本不会
+ 走到这里。所以这里不再需要"问的是成像模态就回复NONE"这条指令:能走到这个
+ 函数,就已经确定是局部问题、有具体目标,不用再让模型自己二次判断一遍。
+ Whether this question has a segmentable target at all is now decided by Stage0
+ (_build_global_local_prompt, forced greedy decoding, reproducible) before this
+ function is ever called -- GLOBAL-classified samples never reach here. So this
+ prompt no longer needs the "reply NONE for modality questions" instruction:
+ reaching this function already implies Stage0 decided there IS a specific
+ target, no need to have the model re-derive that itself.
+
+ exclusion_note不列举任何具体模态类别(不提放射/皮肤镜/显微/眼底这类名词),
+ 只用完全通用的"可分割区域"描述,跟数据集分析彻底无关。
+ exclusion_note does not enumerate any specific modality categories (no
+ radiology/dermoscopy/microscopy/fundus wording) -- only a fully generic
+ description of what counts as a segmentable region, entirely independent
+ of any dataset analysis.
+ """
+ exclusion_note = (
+ "A candidate only qualifies if SAM could draw a bounding box around it as a "
+ "distinct visual region -- a physical structure, lesion, or finding that is "
+ "concretely visible in the image. If the image is a labeled diagram or "
+ "illustration rather than an actual medical image, or nothing in it visually "
+ "corresponds to a distinct, boxable region, do not force an answer -- list "
+ "fewer objects, or none. Reject any candidate that is not itself a "
+ "segmentable region: directional/positional words (left, right, upper, lower, "
+ "anterior, posterior, proximal, distal, etc.), modifiers or descriptors "
+ "(normal, abnormal, mild, severe, etc.), symptoms, diagnoses, measurements, or "
+ "image/modality properties are NOT valid objects on their own, even if they "
+ "appear in the question.\n"
+ )
+ if scispacy_keywords:
+ candidates_block = (
+ f"From the following candidate terms extracted from the question, "
+ f"select ONLY the ones that are themselves concrete structures or "
+ f"findings visually present and segmentable in this image:\n"
+ f"Candidates: {', '.join(scispacy_keywords)}\n"
+ f"{exclusion_note}"
+ f"If none of the candidates qualify, or more relevant structures exist, "
+ f"you may add additional ones. List up to 5 total.\n"
+ )
+ else:
+ candidates_block = (
+ "Identify up to 5 structures or findings most relevant to the question "
+ "that are visually present and physically segmentable in the image.\n"
+ f"{exclusion_note}"
+ )
+ return (
+ f"{candidates_block}"
+ f"Question: {question}\n"
+ "Reply with ONLY the object names, comma-separated, on a single line. "
+ "Use plain object names with no parentheses, no explanations, no extra text. "
+ "Format: Objects: , , ..."
+ )
+
+
+def _parse_objects_response(response: str) -> list:
+ """从Stage1的模型回复文本里解析出物体名字列表,去掉括号注释。如果模型回复
+ "NONE"(比如问的是成像模态而非具体解剖结构,见_build_objects_prompt里的
+ 说明),返回空列表——调用处会因此完全跳过SAM调用。
+ Extract the object list from the Stage1 response, stripping any parenthetical asides.
+ Returns [] if the model replied NONE (e.g. modality/scan-type questions with no
+ segmentable target) -- the caller skips SAM entirely in that case."""
+ objects = []
+ for line in response.splitlines():
+ line = line.strip()
+ if line.lower().startswith("objects:"):
+ raw = line[len("objects:"):].strip()
+ if raw.strip().upper() == "NONE":
+ return []
+ objects = [_strip_parens(o) for o in raw.split(",") if _strip_parens(o)]
+ break
+ if not objects:
+ if response.strip().upper() == "NONE":
+ return []
+ objects = [o for o in (_strip_parens(o) for o in response.split(",")) if o]
+ return objects
+
+
+def _build_global_local_prompt(question: str) -> str:
+ """构造"全局/局部"判断提示词:在真正跑Stage1(列物体)+SAM之前,先问模型
+ 这道题问的是整张图/全局性质的东西(成像模态、扫描类型、图像整体质量等),
+ 还是某个具体的、可以被框出来的局部解剖结构/病灶。如果是全局问题,SAM
+ 根本不该被调用(没有具体目标可分割),直接退化到"全图前景"兜底更省时间、
+ 也更准确地反映"这道题该关注整张图"这件事,不用先让模型硬凑一个物体名字
+ 再指望SAM/_build_objects_prompt里的"NONE"分支去补救。
+
+ 不放few-shot例子:例子只能从评测数据集(medical_multimodel_evaluation_data.json)
+ 里挑,这样会把评测集的具体问法/表述模式写死进提示词里,等于评测阶段
+ "看过"了测试集内容,构成数据泄露,不能这么做。只靠对两个类别的抽象描述
+ 做判断,不依赖任何具体样例。
+ Ask the model to classify the question as GLOBAL (about the whole image --
+ modality, scan type, overall image quality -- nothing specific to segment)
+ or LOCAL (about a specific anatomical structure/lesion that SAM could draw
+ a box around), before Stage1/SAM ever run. This is a separate, single-purpose
+ judgment call so it doesn't get entangled with Stage1's own object-listing
+ task the way the "reply NONE" instruction inside _build_objects_prompt does.
+
+ No few-shot examples here: any example would have to come from the eval
+ dataset itself (medical_multimodel_evaluation_data.json), which would bake
+ that dataset's specific question phrasings into the prompt -- effectively
+ leaking test-set content into the evaluation pipeline. The prompt relies
+ only on an abstract description of the two categories, not on any concrete
+ sample question."""
+ return (
+ "Classify the following question as either GLOBAL or LOCAL:\n"
+ "- GLOBAL: the question is about the image's acquisition itself -- "
+ "imaging modality/technique (CT vs MRI vs X-ray vs ultrasound, etc.), "
+ "scan type, view/plane (axial, sagittal, coronal, etc.), or other "
+ "whole-image properties. No single structure in the image \"is\" the "
+ "answer.\n"
+ "- LOCAL: the question is about a specific anatomical structure, organ, "
+ "bone, lesion, or abnormality/finding that is visually present in the "
+ "image and could be pointed at / boxed -- including questions asking "
+ "what TYPE of abnormality or lesion is present, since the answer still "
+ "corresponds to one specific visible finding, not the whole image.\n"
+ f"Question: {question}\n"
+ "Reply with exactly one word: GLOBAL or LOCAL. No other text."
+ )
+
+
+def _parse_global_local_response(response: str) -> bool:
+ """解析全局/局部判断的回复,返回True表示"全局问题"(应该跳过Stage1+SAM,
+ 直接走全图前景兜底)。解析不出GLOBAL/LOCAL时默认按LOCAL处理(退回到原来
+ "跑SAM"的行为),因为误判成LOCAL的代价只是多跑一次可能没必要的SAM调用,
+ 而误判成GLOBAL的代价是本该被精确定位的问题被直接跳过,风险更高,所以
+ 解析失败时保守地选风险更低的一边。
+ Returns True if the model classified the question as GLOBAL (skip Stage1+SAM
+ entirely, go straight to the whole-foreground fallback). Defaults to False
+ (LOCAL, i.e. run Stage1+SAM as before) when the response can't be parsed --
+ misclassifying as LOCAL only costs one possibly-unnecessary SAM call,
+ while misclassifying as GLOBAL would skip real SAM localization outright,
+ so an unparseable response falls back to the lower-risk side."""
+ text = response.strip().upper()
+ if "GLOBAL" in text and "LOCAL" not in text:
+ return True
+ if "LOCAL" in text:
+ return False
+ return False
+
+
+# ================================================================================
+# test() —same structure as eval.py, only the inference call is replaced
+# 主流程,整体分这几个阶段:
+# 0. 初始化模型/数据集/accelerator(分布式多卡支持)。
+# 1. 决定干预层号(attn_layer_indices_text/vis)。
+# 2. Pass 0:对所有样本批量做"关键词抽取 + Stage1物体列表 + SAM bbox",
+# 这部分跟具体的偏置强度/层号无关,可以缓存复用(见下面的_cache_path)。
+# 3. (可选)初始化拍卖器BudgetedTokenAuction。
+# 4. Pass 1:真正的推理循环——对每个样本,(可选)先跑一次拍卖打分选出最终
+# 偏置位置,再用_AttnInterventionContext包裹generate()完成"带偏置的生成"。
+# 5. 汇总多卡结果、打分、写文件(文件名编码了全部超参,避免覆盖)。
+# ================================================================================
+def test(args):
+ # ── NCCL集合通信超时时间从accelerate/torch默认的10分钟(600秒)拉长到2小时。
+ # 原因:Pass0阶段(Stage1模型生成+SAM分割)每个样本耗时因图像复杂度/物体
+ # 数量差异很大,两张卡各自处理完自己那一半样本后要在
+ # accelerator.wait_for_everyone()/dist.all_gather_object这些集合点同步,
+ # 如果一张卡处理的样本恰好更耗时,另一张卡在同步点空等超过默认600秒,
+ # NCCL的watchdog线程就会判定为"集合操作超时",直接把整个进程组拆掉
+ # (报错为ProcessGroupNCCL.cpp的"Watchdog caught collective operation
+ # timeout",随后rank 0 SIGABRT、其余rank被连带SIGTERM——这曾被误认为是
+ # 外部环境杀掉了进程,实际上是NCCL自己的超时保护机制触发的)。
+ # 用accelerate官方文档推荐的InitProcessGroupKwargs(timeout=...)显式指定
+ # 更长的超时,而不是环境变量(不同torch/accelerate版本对NCCL相关环境
+ # 变量的支持不一致,不保证生效)。
+ _pg_kwargs = InitProcessGroupKwargs(timeout=timedelta(hours=2))
+ accelerator = Accelerator(kwargs_handlers=[_pg_kwargs])
+ global _vis_save_dir, _vis_mask_dir
+ torch.cuda.set_device(accelerator.process_index)
+ accelerator.print(f'args:\n{args}')
+ _vis_save_dir = os.path.join(args.output_path, "vis_debug")
+ _vis_mask_dir = os.path.join(args.output_path, "vis_mask_debug")
+
+ bot = HuatuoChatbot(args.model_path)
+ accelerator.print(f'load_finish')
+
+ bot.gen_kwargs['max_new_tokens'] = args.max_new_tokens
+
+ dataset = TestDataset(args, args.data_path)
+
+ if args.max_samples is not None:
+ dataset.datas = dataset.datas[:args.max_samples]
+
+ val_dataloader = DataLoader(dataset, batch_size=1, shuffle=False, drop_last=False, collate_fn=dataset.collate_fn)
+
+ val_dataloader = accelerator.prepare(val_dataloader)
+ accelerator.wait_for_everyone()
+
+ # 保存这次运行用到的代码快照(本文件+相关sh脚本),方便事后追溯"这个结果
+ # 到底是用哪个版本的代码跑出来的"。
+ if accelerator.is_main_process:
+ import shutil, glob as _glob
+ os.makedirs(args.output_path, exist_ok=True)
+ _snapshot_dir = os.path.join(args.output_path, '_snapshot')
+ os.makedirs(_snapshot_dir, exist_ok=True)
+ shutil.copy2(__file__, os.path.join(_snapshot_dir, os.path.basename(__file__)))
+ _sh_patterns = ('run_eval_attnbias_sam_*.sh', 'run_eval.sh', 'run_all_attnbias_sam.sh', 'run_ablation_grid*.sh')
+ for _pattern in _sh_patterns:
+ for _sh in _glob.glob(os.path.join(os.path.dirname(__file__), _pattern)):
+ shutil.copy2(_sh, os.path.join(_snapshot_dir, os.path.basename(_sh)))
+ accelerator.print(f'[Snapshot] code snapshot saved to {_snapshot_dir}')
+
+ # ── 确定文本侧/视觉侧分别在哪几层注入偏置:优先用--attn_layers_text/vis
+ # 直接指定的层号;如果没指定,就走load_top_layers自动从.pt文件选层。
+ attn_layer_indices_text = _parse_layer_list(args.attn_layers_text)
+ if attn_layer_indices_text is None:
+ pt_path_text = args.pt_path_text or args.pt_path
+ if pt_path_text is None:
+ raise ValueError("Provide --attn_layers_text, or --pt_path/--pt_path_text to auto-select layers.")
+ attn_layer_indices_text = load_top_layers(
+ pt_path_text, args.attn_topk_text,
+ pt_path_random=args.pt_path_text_random or args.pt_path_random)
+
+ attn_layer_indices_vis = _parse_layer_list(args.attn_layers_vis)
+ if attn_layer_indices_vis is None:
+ if args.pt_path is None:
+ raise ValueError("Provide --attn_layers_vis, or --pt_path to auto-select layers.")
+ attn_layer_indices_vis = load_top_layers(
+ args.pt_path, args.attn_topk_vis, pt_path_random=args.pt_path_random)
+
+ accelerator.print(f'[layers] text={attn_layer_indices_text} vis={attn_layer_indices_vis}')
+
+ # 拍卖打分时用全部层的attention平均,跟"偏置真正注入在哪几层"是两件独立的
+ # 事——单一层的attention作为"这个token全局是否重要"的信号噪声较大,所以
+ # 拍卖打分信号故意取得比(可能更窄的)干预层选择更宽。
+ # Auction bidding always averages attention over every layer of the model,
+ # independent of which layer(s) the bias is actually injected at above --
+ # a single layer's attention can be a noisy proxy for "is this token
+ # globally important," so the bidding signal is deliberately broader than
+ # the (possibly narrower) intervention layer selection.
+ attn_layer_indices_all = list(range(len(_get_attn_layers(bot))))
+
+ # 只有--intervention是both或vis时才需要MedSAM3(text模式视觉侧整体不参与,
+ # 不需要初始化SAM,节省显存和初始化时间)。
+ _needs_sam = args.intervention in ("both", "vis")
+ medsam3 = None
+ if _needs_sam and args.medsam3_config:
+ try:
+ from medsam3_wrapper import MedSAM3Wrapper
+ except ImportError:
+ accelerator.print(
+ "[AttnBias] medsam3_wrapper.MedSAM3Wrapper not found; "
+ "continuing with medsam3=None (SAM bbox lookup degrades to the "
+ "full-image fallback in Stage2 below)."
+ )
+ MedSAM3Wrapper = None
+ if MedSAM3Wrapper is not None:
+ medsam3 = MedSAM3Wrapper(
+ config_path=args.medsam3_config,
+ device=args.medsam3_device or f"cuda:{accelerator.process_index}",
+ threshold=args.medsam3_threshold,
+ nms_iou=args.medsam3_nms_iou,
+ medsam3_dir=args.medsam3_dir,
+ )
+
+ # ── Pass 0: 对全部样本提前做"关键词抽取 + Stage1物体列表 + SAM bbox",
+ # 这个阶段完全不依赖偏置强度/层号/拍卖参数等超参,只依赖数据本身,所以
+ # 用(data_path, model_path, seed)算个md5作为缓存key,命中缓存就直接跳过
+ # Stage1模型生成和SAM调用(这两步是整个流程里最慢的部分),网格搜索/消融
+ # 脚本反复跑几十次同一批数据时能省下大量重复计算。──────────────────
+ # None of this depends on the bias strength/layer/auction args -- only on
+ # data_path/model_path/seed (same question + image + prompt -> same Stage1
+ # objects + SAM bboxes). Ablation scripts re-run this file dozens of times
+ # varying only the bias hyperparameters, so cache the per-sample Pass 0
+ # output keyed on (data_path, model_path, seed) and skip Stage1/SAM entirely
+ # on a cache hit -- those two steps (one model generation + one SAM call per
+ # object) are the expensive part of this loop.
+ _cache_key = hashlib.md5(
+ f"{os.path.abspath(args.data_path)}|{args.model_path}|{args.seed}".encode()
+ ).hexdigest()
+ _cache_dir = os.path.join(os.path.dirname(__file__), "cache", "sam_stage1_cache")
+ _cache_path = os.path.join(_cache_dir, f"{_cache_key}.json")
+ _pass0_cache = None
+ if _needs_sam and os.path.exists(_cache_path):
+ try:
+ with open(_cache_path) as f:
+ _pass0_cache = json.load(f)
+ accelerator.print(f"[Pass0Cache] loaded {len(_pass0_cache)} cached samples from {_cache_path}")
+ except Exception as e:
+ accelerator.print(f"[Pass0Cache] failed to load {_cache_path}: {e}, recomputing")
+ _pass0_cache = None
+ _pass0_cache_out = {}
+
+ sample_list = []
+ with torch.no_grad():
+ dataloader_iterator = tqdm(val_dataloader, total=len(val_dataloader), desc="Stage1+SAM") if accelerator.is_main_process else val_dataloader
+ for batch in dataloader_iterator:
+ for da, query, image in zip(batch["data"], batch['query'], batch['image']):
+ image_paths = [os.path.join(os.path.dirname(args.data_path), x) for x in image]
+ for img in image_paths:
+ assert os.path.exists(img), f'{img} not exists'
+ img_path = image_paths[0] if image_paths else None
+ pil_img = Image.open(img_path).convert("RGB") if img_path else None
+
+ # 第一步:跑一次eager attention前向,拿到img_start(图像起始位置)
+ # 和文本关键词位置(extract_key_positions,即前面的Step A)。
+ # need_keywords=(intervention!="none"):none模式完全不干预,
+ # 没必要浪费时间跑scispaCy。
+ orig_impl = bot.model.config._attn_implementation
+ _set_attn_impl(bot.model, "eager")
+ top_text_pos, all_text_pos = [[]], []
+ keywords = []
+ img_start, seq_len = None, None
+ try:
+ top_text_pos, all_text_pos, img_start, seq_len, _, keywords = \
+ extract_key_positions(bot, query, img_path, question=da.get('question', ''),
+ need_keywords=(args.intervention != "none"))
+ except Exception as e:
+ print(f"[AttnBias] img_start extraction failed: {e}, using full-image fallback")
+ finally:
+ _set_attn_impl(bot.model, orig_impl)
+
+ print(f"[scispaCy] keywords: {keywords}")
+
+ # 查缓存:如果这个样本之前已经跑过Stage1+SAM(用test_id索引),
+ # 直接复用objects/raw_bboxes,跳过下面两步耗时操作。
+ _cache_entry = _pass0_cache.get(str(da['test_id'])) if _pass0_cache is not None else None
+
+ # Stage0:全局/局部判断——在真正跑Stage1(列物体)+SAM之前,先问
+ # 模型这道题是不是"全局性质"(成像模态/扫描类型等,没有具体目标
+ # 可分割)。是全局就直接跳过Stage1+SAM,退化到后面Stage2汇总时
+ # 的"全图前景"兜底(objects/all_bboxes保持空即可触发);不是全局
+ # 才继续走Stage1+SAM。这一步必须用贪婪解码(do_sample=False),
+ # 不能沿用bot.gen_kwargs默认的采样模式——否则同一道题在不同次
+ # 运行里可能被判成不同的全局/局部结果,导致"要不要跑SAM"这个
+ # 决策本身变得不可复现,污染后续所有基于这个决策做的比较。
+ # Stage0: ask the model whether this question is GLOBAL (no
+ # specific segmentable target -- modality/scan-type questions)
+ # before running Stage1/SAM at all. GLOBAL skips Stage1+SAM
+ # entirely and falls through to Stage2's existing "empty
+ # raw_bboxes -> whole-foreground fallback" path. This call is
+ # forced to greedy decoding (do_sample=False) -- reusing
+ # bot.gen_kwargs' default sampling here would make the global/
+ # local decision itself non-reproducible run-to-run, which
+ # would silently change which samples get SAM'd across
+ # otherwise-identical reruns.
+ is_global = False
+ if _cache_entry is None and _needs_sam and medsam3 is not None and pil_img is not None:
+ _orig_do_sample = bot.gen_kwargs.get("do_sample", True)
+ _orig_max_new_tokens_gl = bot.gen_kwargs.get("max_new_tokens", 32)
+ bot.gen_kwargs["do_sample"] = False
+ bot.gen_kwargs["max_new_tokens"] = 8
+ # try/finally: 保证不管bot.inference()这次调用是否报错(比如OOM),
+ # gen_kwargs都一定会被改回原状,不会因为这次调用异常就把
+ # do_sample=False泄漏给后面Stage1/Pass1的正常生成——异常本身
+ # 仍然会在finally执行完之后正常往外抛,不吞掉,只是保证清理
+ # 动作不会因为异常而被跳过。
+ # try/finally: guarantees gen_kwargs is restored regardless of
+ # whether this bot.inference() call raises (e.g. OOM) -- without
+ # it, an exception here would skip the restore lines entirely,
+ # silently leaking do_sample=False into every later Stage1/Pass1
+ # generation call for the rest of the process. The exception
+ # still propagates normally after finally runs; this only
+ # guarantees cleanup isn't skipped.
+ try:
+ global_local_response = bot.inference(
+ _build_global_local_prompt(da.get('question', '') or query),
+ image_paths)
+ finally:
+ bot.gen_kwargs["do_sample"] = _orig_do_sample
+ bot.gen_kwargs["max_new_tokens"] = _orig_max_new_tokens_gl
+ is_global = _parse_global_local_response(
+ global_local_response[0] if global_local_response else "")
+ print(f"[Stage0] global={is_global}")
+
+ # Stage1:让模型(不是SAM)先列出"图里有哪些可分割的物体",
+ # scispaCy关键词作为候选提示传进去。只有需要SAM(both/vis模式)、
+ # 没命中缓存、且Stage0判断不是全局问题时才跑这一步。
+ objects = []
+ if _cache_entry is not None:
+ objects = _cache_entry["objects"]
+ elif _needs_sam and medsam3 is not None and pil_img is not None and not is_global:
+ _orig_max_new_tokens = bot.gen_kwargs.get("max_new_tokens", 32)
+ bot.gen_kwargs["max_new_tokens"] = 32
+ # try/finally同Stage0:防止bot.inference()中途报错时,
+ # max_new_tokens=32这个临时值漏改回去,污染后面所有生成调用。
+ # try/finally, same reason as Stage0: prevents the temporary
+ # max_new_tokens=32 override from leaking into every later
+ # generation call if bot.inference() raises mid-call.
+ try:
+ stage1_response = bot.inference(
+ _build_objects_prompt(da.get('question', '') or query, scispacy_keywords=keywords),
+ image_paths)
+ finally:
+ bot.gen_kwargs["max_new_tokens"] = _orig_max_new_tokens
+ stage1_text = stage1_response[0] if stage1_response else ""
+ objects = _parse_objects_response(stage1_text)
+ print(f"[Stage1] objects: {objects}")
+
+ # Stage2:拿Stage1列出的每个物体名字依次喂给MedSAM3,得到具体
+ # bbox坐标和分割掩码。
+ all_bboxes = []
+ obj_masks = [] # [(obj_name, mask_ndarray), ...] -- one combined mask per object
+ if _cache_entry is None and _needs_sam and medsam3 is not None and pil_img is not None:
+ for obj in objects[:10]:
+ lines, mask = _get_sam_bbox_text(obj, pil_img, medsam3, max_bbox=2)
+ for line in lines:
+ try:
+ coords = [int(v) for v in line.split("[")[1].rstrip("]").split(",")]
+ all_bboxes.append((obj, *coords))
+ except Exception:
+ pass
+ if mask is not None:
+ obj_masks.append((obj, mask))
+
+ # Visualization + mask persistence (only meaningful when SAM actually ran this
+ # time -- skipped on a cache hit, since obj_masks/all_bboxes are raw SAM output
+ # we deliberately don't cache, only the derived raw_bboxes below)
+ # 调试可视化:把SAM分割掩码和bbox画在原图上存成png(最多存2000张),
+ # 方便人工检查SAM定位是否合理。只在SAM真正跑了的时候才画(缓存
+ # 命中时跳过,因为obj_masks/all_bboxes是SAM原始输出,没有被缓存)。
+ global _vis_save_count
+ if _cache_entry is None and _needs_sam and pil_img is not None and _vis_save_count < 2000:
+ import matplotlib.pyplot as plt
+ import matplotlib.patches as mpatches
+ import matplotlib.colors as mcolors
+ os.makedirs(_vis_save_dir, exist_ok=True)
+
+ # save each object's raw mask array, plus a combined mask across all objects
+ for obj_name, mask in obj_masks:
+ safe_name = re.sub(r"[^a-zA-Z0-9_-]+", "_", obj_name)[:40]
+ np.save(os.path.join(_vis_save_dir,
+ f"sam_{_vis_save_count:03d}_mask_{safe_name}.npy"), mask)
+ if obj_masks:
+ combined = obj_masks[0][1].astype(np.float32)
+ for _, m in obj_masks[1:]:
+ combined = np.maximum(combined, m.astype(np.float32))
+ np.save(os.path.join(_vis_save_dir,
+ f"sam_{_vis_save_count:03d}_mask_combined.npy"), combined)
+
+ fig, ax = plt.subplots(1, 1, figsize=(7, 7))
+ ax.imshow(np.array(pil_img))
+ colors = ["red", "lime", "cyan", "yellow", "magenta", "orange", "white", "blue"]
+ # overlay each object's mask (semi-transparent) before drawing bbox/label
+ for ci, (obj_name, mask) in enumerate(obj_masks):
+ color = colors[ci % len(colors)]
+ rgba = np.zeros((*mask.shape, 4))
+ rgb = mcolors.to_rgb(color)
+ rgba[..., :3] = rgb
+ rgba[..., 3] = (mask > 0).astype(np.float32) * 0.45
+ ax.imshow(rgba)
+ for ci, entry in enumerate(all_bboxes):
+ obj_name, x1, y1, x2, y2 = entry
+ color = colors[ci % len(colors)]
+ ax.add_patch(mpatches.Rectangle((x1, y1), x2-x1, y2-y1, linewidth=2, edgecolor=color, facecolor="none"))
+ ax.text(x1, y1-4, obj_name, color=color, fontsize=7, bbox=dict(facecolor="black", alpha=0.4, pad=1))
+ ax.set_title(f"objects: {objects}", fontsize=7, wrap=True)
+ ax.axis("off")
+ fig.savefig(os.path.join(_vis_save_dir, f"sam_{_vis_save_count:03d}.png"), dpi=120, bbox_inches="tight")
+ plt.close(fig)
+ _vis_save_count += 1
+
+ orig_size = pil_img.size if pil_img is not None else (1, 1)
+ if _cache_entry is not None:
+ raw_bboxes = _cache_entry["raw_bboxes"]
+ else:
+ raw_bboxes = [[x1, y1, x2, y2] for (_, x1, y1, x2, y2) in all_bboxes]
+ if not raw_bboxes and pil_img is not None:
+ # SAM没找到任何结果(可能是SAM确实没分割出东西,也可能是这题问的
+ # 是成像模态、没有具体可分割目标,见_build_objects_prompt)。
+ # 退化方案:用图像里非黑色(实际内容)像素的外接框,而不是整张画布,
+ # 避免医学影像常见的黑色letterbox填充区域被误当成"关键区域"。
+ W, H = orig_size
+ img_arr = np.array(pil_img.convert("L"))
+ ys, xs = np.where(img_arr > 0)
+ if len(xs) > 0:
+ raw_bboxes = [[int(xs.min()), int(ys.min()), int(xs.max()) + 1, int(ys.max()) + 1]]
+ else:
+ raw_bboxes = [[0, 0, W, H]]
+ vis_patches = _multi_bbox_to_patch_indices(raw_bboxes, orig_size, img_start, margin=2) if img_start is not None else []
+ print(f"[AttnBias] vis_patches={len(vis_patches)} from {len(raw_bboxes)} bboxes"
+ + (" [cached]" if _cache_entry is not None else ""))
+
+ if _needs_sam and _cache_entry is None:
+ _pass0_cache_out[str(da['test_id'])] = {"objects": objects, "raw_bboxes": raw_bboxes}
+
+ sample_list.append(dict(
+ da=da, query=query, image_paths=image_paths, img_path=img_path,
+ img_start=img_start, seq_len=seq_len,
+ vis_patches=vis_patches, orig_size=orig_size,
+ top_text_pos=top_text_pos, all_text_pos=all_text_pos,
+ keywords=keywords, objects=objects,
+ ))
+
+ # 多卡情况下,把每个进程(rank)新算出的缓存条目all_gather汇总到主进程,
+ # 跟已有缓存合并后写回磁盘(只有当确实有新条目时才写,避免重复IO)。
+ # Merge newly-computed cache entries across ranks and persist (only if this
+ # process actually ran Stage1/SAM for at least one sample, i.e. cache was
+ # absent or only partially covered this dataset).
+ if _needs_sam:
+ accelerator.wait_for_everyone()
+ if accelerator.num_processes > 1:
+ all_new_entries = [None] * accelerator.num_processes
+ dist.all_gather_object(all_new_entries, _pass0_cache_out)
+ else:
+ # single-process run (accelerate launch --num_processes=1): torch.distributed's
+ # default process group is never initialized in this mode, so dist.all_gather_object
+ # would raise "Default process group has not been initialized" -- there is only one
+ # rank's data to begin with, so just use it directly instead of gathering.
+ all_new_entries = [_pass0_cache_out]
+ if accelerator.is_main_process:
+ merged = dict(_pass0_cache) if _pass0_cache else {}
+ for rank_entries in all_new_entries:
+ merged.update(rank_entries)
+ if len(merged) > (len(_pass0_cache) if _pass0_cache else 0):
+ os.makedirs(_cache_dir, exist_ok=True)
+ with open(_cache_path, 'w') as f:
+ json.dump(merged, f)
+ accelerator.print(f"[Pass0Cache] saved {len(merged)} samples to {_cache_path}")
+
+ # ── 拍卖器初始化(可选)。--auction_enable不传时auction保持None,下面Pass1
+ # 循环里就完全跳过拍卖逻辑,直接用Stage1+SAM/scispaCy给出的原始候选集合,
+ # 即朴素的"关键词/SAM区域全加偏置"模式——拍卖是一个开关,不影响其他逻辑。
+ auction = None
+ if getattr(args, "auction_enable", False):
+ auction = BudgetedTokenAuction(
+ total_ratio=args.auction_total_ratio,
+ neg_ratio=args.auction_neg_ratio,
+ )
+
+ # ── 辅助函数:根据当前样本构造_AttnInterventionContext。
+ # negative_vis_patches只有在拍卖选出了显式干扰项集合时才会被设置;否则是
+ # None,_AttnInterventionContext会退化成原本"压制全部非关键patch"的行为
+ # (拍卖功能本身不影响这条回退路径)。
+ #
+ # 模态消融的实现方式:intervention=="text"时把视觉侧的偏置/关键集合
+ # 全部清零(只生效文本侧偏置),"vis"时反过来清零文本侧——
+ # _AttnInterventionContext内部始终走同一套"both"代码路径(文本侧和视觉侧
+ # 本来就是独立处理的),所以消融只需要在构造它之前,把要禁用的那一侧输入
+ # 清成"中性值"(空列表/0偏置),不需要改动那个类本身。
+ _text_only = args.intervention == "text"
+ _vis_only = args.intervention == "vis"
+
+ def _make_attn_ctx(img_start, seq_len, vis_patches, top_text_pos=None, all_text_pos=None,
+ negative_vis_patches=None, negative_text_positions=None):
+ # _vis_only(--intervention vis)时,文本侧关键词/全部文本位置都清空,
+ # 偏置强度强制为0——等价于"这次推理只生效视觉侧偏置"。
+ # _text_only(--intervention text)时反过来清空视觉侧。
+ # intervention=="none"时ctx_mode="none",_AttnInterventionContext.__enter__
+ # 直接跳过,不做任何替换。
+ ctx_mode = "none" if args.intervention == "none" else "both"
+ eff_top_text = [[]] if _vis_only else (top_text_pos or [[]])
+ eff_all_text = [] if _vis_only else (all_text_pos or [])
+ eff_vis = [] if _text_only else vis_patches
+ eff_neg_vis = None if _text_only else negative_vis_patches
+ eff_neg_text = None if _vis_only else negative_text_positions
+ return _AttnInterventionContext(
+ bot, ctx_mode,
+ top_text_positions=eff_top_text,
+ all_text_positions=eff_all_text,
+ attn_layer_indices_text=attn_layer_indices_text,
+ key_bias_text=(0.0 if _vis_only else args.attn_key_bias_text),
+ nonkey_bias_text=(0.0 if _vis_only else args.attn_nonkey_bias_text),
+ img_pos=img_start, seq_len=seq_len,
+ attn_layer_indices_vis=attn_layer_indices_vis,
+ key_bias_vis=(0.0 if _text_only else args.attn_key_bias_vis),
+ nonkey_bias_vis=(0.0 if _text_only else args.attn_nonkey_bias_vis),
+ vis_key_patches=eff_vis,
+ negative_vis_patches=eff_neg_vis,
+ negative_text_positions=eff_neg_text,
+ )
+
+ def _make_inputs(q, img_path):
+ """把问题文本+图像路径,重新走一遍预处理流程,转成模型generate()需要的
+ input_ids / image tensor。之所以要重新构造(而不是复用Pass0时的),是
+ 因为Pass0那次forward只是为了拿attentions,没有走generate的KV cache流程。"""
+ t = bot.input_moderation(q)
+ t = bot.insert_image_placeholder(t, 1)
+ cv = bot.get_conv_without_history(t)
+ ids = bot.preprocess(cv, return_tensors="pt").unsqueeze(0).to(bot.device)
+ imgs = (torch.stack(bot.get_image_tensors([img_path]))
+ .to(dtype=torch.bfloat16).to(bot.device))
+ return ids, imgs
+
+ orig_impl = bot.model.config._attn_implementation
+
+ # ── Pass 1:真正生成答案的主循环。"none"模式或者Pass0时img_start抽取失败
+ # 的样本,直接走普通推理(bot.inference),不构造任何偏置上下文;其余情况
+ # (text/vis/both且抽取成功)都进入下面的偏置干预分支。
+ # Pass 1+3: plain inference is only ever needed for "none" mode, or as a
+ # fallback when img_start extraction failed for a sample -- for text/vis/both
+ # with a successful extraction, the intervention pass below fully overwrites
+ # it, so running it unconditionally for every sample would be wasted compute. ──
+ set_seed(args.seed)
+ with torch.no_grad():
+ for s in tqdm(sample_list, desc="generate") if accelerator.is_main_process else sample_list:
+ # none模式,或者这个样本Pass0时img_start没抽取成功:走普通推理,不偏置。
+ if args.intervention == "none" or s['img_start'] is None:
+ s['da']['model_output'] = bot.inference(s['query'], s['image_paths'])[0]
+ continue
+ aug_ids, aug_imgs = _make_inputs(s['query'], s['img_path'])
+ _set_attn_impl(bot.model, "eager")
+ try:
+ # 默认(不开拍卖):直接用Pass0算好的全部关键词/SAM patch作为偏置对象,
+ # 没有显式负向集合(下面_make_attn_ctx传None会让负向偏置覆盖"全部非关键位置")。
+ vis_patches_for_ctx = s['vis_patches']
+ top_text_pos_for_ctx = s['top_text_pos']
+ negative_vis_patches = None
+ negative_text_positions = None
+ # rollout分数(拍卖真正打分依据)只在开了拍卖时才有意义,供后面
+ # --no_rollout_vis/--no_rollout_text可视化复用,避免为了画图
+ # 再重新调一次_rollout_attn_to_positions(打分口径必须跟这次
+ # 拍卖实际用的完全一致,不能是另一次forward算出来的attention)。
+ rollout_vis_scores = None
+ rollout_text_scores = None
+ if auction is not None:
+ # 开了拍卖:先重新跑一次"无偏置"的eager前向,专门为这次拍卖
+ # 打分获取attentions——不能复用Pass0缓存的attentions,因为
+ # Pass0那次forward跟这里输入构造方式不完全一样(参见
+ # BudgetedTokenAuction模块开头的说明)。
+ with torch.no_grad():
+ auction_out = bot.model(aug_ids, images=aug_imgs,
+ output_attentions=True, output_hidden_states=False,
+ return_dict=True, use_cache=False)
+ auction_attentions = _get_attentions(auction_out)
+ flat_keywords = [p for ep in (s['top_text_pos'] or []) for p in ep]
+ # 调用拍卖:text_enabled/vis_enabled跟随当前消融模式(_text_only/
+ # _vis_only),保证被禁用的一侧从候选池层面就完全不参与拍卖。
+ sel_text, sel_vis, sel_neg, sel_neg_text = auction.clear_market(
+ top_text_positions=flat_keywords,
+ all_text_positions=s['all_text_pos'],
+ vis_patches=s['vis_patches'],
+ img_start=s['img_start'], seq_len=s['seq_len'],
+ attentions=auction_attentions,
+ attn_layer_indices_text=attn_layer_indices_all,
+ attn_layer_indices_vis=attn_layer_indices_all,
+ text_enabled=not _vis_only,
+ vis_enabled=not _text_only,
+ )
+ # 拍卖选出的结果覆盖掉原始的Pass0候选集合,作为这次generate真正
+ # 使用的关键/负向位置集合。auction_out/auction_attentions不在
+ # 这里释放——如果下面--attn_before_after开着会直接复用
+ # auction_out当"偏置前"的forward结果,真正的释放统一收口在
+ # 那段逻辑之后的集中处理代码块里,见_auction_out_consumed。
+ top_text_pos_for_ctx = [sel_text]
+ vis_patches_for_ctx = sel_vis
+ negative_vis_patches = sel_neg
+ negative_text_positions = sel_neg_text
+
+ # ── 路由/拍卖可视化专用:对全部576个视觉patch、全部问题文本
+ # token各算一次rollout分数(不局限于候选池,覆盖全体位置才能
+ # 看出"拍卖选中的到底是分数分布里的哪个位置"),用的是跟上面
+ # clear_market完全相同的attn_layer_indices_all全层rollout口径。
+ if not args.no_rollout_vis or not args.no_rollout_text:
+ if not args.no_rollout_vis:
+ all_vis_positions_full = list(
+ range(s['img_start'], s['img_start'] + HUATUO_NUM_IMG_TOKENS))
+ rollout_vis_scores = auction._rollout_attn_to_positions(
+ auction_attentions, attn_layer_indices_all,
+ all_vis_positions_full, s['seq_len']).numpy()
+ if not args.no_rollout_text:
+ rollout_text_scores = auction._rollout_attn_to_positions(
+ auction_attentions, attn_layer_indices_all,
+ s['all_text_pos'], s['seq_len']).numpy()
+
+ # ── 抽查可视化:mask区域/mask文本(--no_vis_mask控制)和偏置前后
+ # attention对比(--no_attn_before_after控制)是两个独立开关,都受
+ # 同一个_vis_mask_save_count/--vis_mask_limit样本数上限约束,但
+ # 谁开谁关互不影响——比如只想看attention对比、不想要mask高亮图,
+ # 应该能只传--no_vis_mask而attn_before_after依然生效,反之亦然。
+ # auction_out的释放责任统一交给下面一处集中处理的代码块,不在
+ # 两段可视化逻辑内部各自del,避免"先删后用"或"该删的分支没跑到
+ # 导致漏删"这两类错误。────────────────────────────────
+ global _vis_mask_save_count
+ _do_vis = _vis_mask_save_count < args.vis_mask_limit
+ _auction_out_consumed = False
+ if _do_vis:
+ _tag = f"{s['da']['test_id']}"
+ # aug_ids里的-200图像占位符只占1个位置,需要摊开成
+ # HUATUO_NUM_IMG_TOKENS个,才能跟img_start/vis_patches
+ # (在extract_key_positions里已摊开过)用同一套坐标系——
+ # 否则关键词/attention位置在渲染时会全部错位。两个可视化
+ # 分支(mask_text和attn_before_after)都要用,提到外层算一次。
+ raw_ids = aug_ids[0].cpu().tolist()
+ img_at = s['img_start']
+ expanded_ids = (raw_ids[:img_at]
+ + [-200] * HUATUO_NUM_IMG_TOKENS
+ + raw_ids[img_at + 1:])
+
+ if not args.no_vis_mask:
+ if vis_patches_for_ctx and not _text_only:
+ visualize_masked_region(
+ s['img_path'], s['orig_size'], s['img_start'], vis_patches_for_ctx,
+ negative_patches=negative_vis_patches,
+ save_path=os.path.join(_vis_mask_dir, f"mask_region_{_tag}.png"))
+ flat_top_text = [p for ep in (top_text_pos_for_ctx or []) for p in ep]
+ if flat_top_text and not _vis_only:
+ render_masked_text_image(
+ expanded_ids, bot.tokenizer, flat_top_text,
+ negative_indices=negative_text_positions,
+ img_start=img_at, img_end=img_at + HUATUO_NUM_IMG_TOKENS,
+ save_path=os.path.join(_vis_mask_dir, f"mask_text_{_tag}.png"))
+
+ # ── 偏置前/后attention对比:分别在"不打补丁"和"打了补丁"两种
+ # 状态下各跑一次单步forward(不是完整generate,只看第一步预测
+ # 时的attention就足够展示干预效果,避免多token生成的额外开销),
+ # 用_get_last_token_attn_to_positions取真正被注入偏置的那几层
+ # (attn_layer_indices_text/vis)的attention,画成before/after
+ # 对比图。"偏置前"的forward如果拍卖已经跑过(auction_out)就直接
+ # 复用,不重复跑一次同样的前向——但只借用它的数值算出
+ # attn_before(不在这里del它,统一交给下面的释放代码块处理)。
+ if not args.no_attn_before_after:
+ attn_before_out = auction_out if auction is not None else bot.model(
+ aug_ids, images=aug_imgs, output_attentions=True,
+ output_hidden_states=False, return_dict=True, use_cache=False)
+ _auction_out_consumed = auction is not None
+ attn_before_attentions = _get_attentions(attn_before_out)
+ all_vis_positions = list(range(s['img_start'], s['img_start'] + HUATUO_NUM_IMG_TOKENS))
+ vis_attn_before = _get_last_token_attn_to_positions(
+ attn_before_attentions, attn_layer_indices_vis, all_vis_positions, s['seq_len'])
+ text_attn_before = _get_last_token_attn_to_positions(
+ attn_before_attentions, attn_layer_indices_text, s['all_text_pos'], s['seq_len'])
+ # 这里立即把auction_out/auction_attentions连同attn_before_*
+ # 一并释放(不管是否复用过auction_out):数值已经提取到
+ # vis_attn_before/text_attn_before这两个numpy数组里,原始
+ # tensor不再需要。之所以不留到后面的"统一清理"代码块,是
+ # 因为_auction_out_consumed=True时那个代码块的判断条件
+ # (not _auction_out_consumed)会短路,实测会漏删——见
+ # verify_lifecycle模拟:这是最常见的默认路径(拍卖开+
+ # attn_before_after默认开),必须在这里就地处理,不能依赖
+ # 后面那个只覆盖"未消费"分支的清理代码。
+ if _auction_out_consumed:
+ del auction_out, auction_attentions
+ else:
+ del attn_before_out
+ del attn_before_attentions
+
+ with _make_attn_ctx(s['img_start'], s['seq_len'], vis_patches_for_ctx,
+ top_text_pos=top_text_pos_for_ctx, all_text_pos=s['all_text_pos'],
+ negative_vis_patches=negative_vis_patches,
+ negative_text_positions=negative_text_positions):
+ attn_after_out = bot.model(
+ aug_ids, images=aug_imgs, output_attentions=True,
+ output_hidden_states=False, return_dict=True, use_cache=False)
+ attn_after_attentions = _get_attentions(attn_after_out)
+ vis_attn_after = _get_last_token_attn_to_positions(
+ attn_after_attentions, attn_layer_indices_vis, all_vis_positions, s['seq_len'])
+ text_attn_after = _get_last_token_attn_to_positions(
+ attn_after_attentions, attn_layer_indices_text, s['all_text_pos'], s['seq_len'])
+ del attn_after_out, attn_after_attentions
+
+ visualize_attn_before_after_region(
+ s['img_path'], s['orig_size'], s['img_start'],
+ vis_attn_before, vis_attn_after,
+ save_path=os.path.join(_vis_mask_dir, f"attn_region_{_tag}.png"))
+ render_attn_before_after_text(
+ expanded_ids, bot.tokenizer, text_attn_before, text_attn_after,
+ s['all_text_pos'], img_start=img_at, img_end=img_at + HUATUO_NUM_IMG_TOKENS,
+ save_path=os.path.join(_vis_mask_dir, f"attn_text_{_tag}.png"))
+
+ # ── 路由/拍卖可视化:把rollout_vis_scores/rollout_text_scores
+ # (拍卖真正打分依据,在上面拍卖分支里已经算好)画成热力图/高亮图,
+ # 叠加拍卖选中的正向(红)/负向(蓝)标记,跟mask/attn_before_after
+ # 是完全独立的第三组开关(--no_rollout_vis/--no_rollout_text),
+ # 只在auction is not None(开了拍卖)时才有意义——没开拍卖时
+ # rollout_vis_scores/rollout_text_scores在上面就没被计算,
+ # 保持None,这里直接跳过。
+ if rollout_vis_scores is not None:
+ visualize_rollout_region(
+ s['img_path'], s['orig_size'], s['img_start'], rollout_vis_scores,
+ selected_positive=vis_patches_for_ctx, selected_negative=negative_vis_patches,
+ save_path=os.path.join(_vis_mask_dir, f"rollout_region_{_tag}.png"))
+ if rollout_text_scores is not None:
+ flat_top_text_for_rollout = [p for ep in (top_text_pos_for_ctx or []) for p in ep]
+ render_rollout_text(
+ expanded_ids, bot.tokenizer, rollout_text_scores, s['all_text_pos'],
+ selected_positive=flat_top_text_for_rollout, selected_negative=negative_text_positions,
+ img_start=img_at, img_end=img_at + HUATUO_NUM_IMG_TOKENS,
+ save_path=os.path.join(_vis_mask_dir, f"rollout_text_{_tag}.png"))
+
+ # 这几个可视化分支(attn_before_after/rollout)每个样本最多
+ # 额外多跑2-3次output_attentions=True的完整前向——这种前向
+ # 会把每层每个head的完整attention矩阵materialize到显存里,
+ # 比普通generate(不要attention)占用大得多。虽然上面已经
+ # 逐个del掉了对应的tensor变量,但PyTorch的CUDA缓存分配器
+ # 默认不会把释放的显存立即还给系统,只在本进程内部留着复用
+ # ——只在受--vis_mask_limit约束的前若干个样本上主动调用
+ # empty_cache,把这次额外产生的大块显存及时归还,降低峰值
+ # 显存占用累积/碎片化的风险(怀疑是长跑数小时后进程被外部
+ # 信号杀掉的诱因之一)。不在主循环每个样本都调用,因为
+ # empty_cache本身有同步开销,会拖慢正常样本的generate速度。
+ torch.cuda.empty_cache()
+
+ _vis_mask_save_count += 1
+
+ # ── 统一释放auction_out/auction_attentions:不管上面attn_before_
+ # after逻辑有没有跑(_do_vis=False/--no_attn_before_after都会让它
+ # 跳过)、跑了有没有复用到auction_out,只要拍卖本身跑过
+ # (auction is not None)且这次的auction_out还没被上面的逻辑处理
+ # 掉(_auction_out_consumed=False),就必须在这里显式删除——否则
+ # auction_out包含完整的attention权重张量,会一直占着显存直到
+ # 下次循环重新赋值才被覆盖,是一个真实的显存泄漏点。
+ if auction is not None and not _auction_out_consumed:
+ del auction_out, auction_attentions
+
+ # 真正的"带偏置生成":with块内,指定层的attention forward被替换成
+ # 带bias的版本(见_AttnInterventionContext.__enter__),generate()
+ # 结束后with块自动退出,attention forward还原回正常版本。
+ with torch.inference_mode():
+ with _make_attn_ctx(s['img_start'], s['seq_len'], vis_patches_for_ctx,
+ top_text_pos=top_text_pos_for_ctx, all_text_pos=s['all_text_pos'],
+ negative_vis_patches=negative_vis_patches,
+ negative_text_positions=negative_text_positions):
+ out_ids = bot.model.generate(aug_ids, images=aug_imgs, use_cache=True, **bot.gen_kwargs)
+ finally:
+ _set_attn_impl(bot.model, orig_impl)
+ s['da']['model_output'] = bot.tokenizer.decode(out_ids[0], skip_special_tokens=True).strip()
+
+ torch.cuda.empty_cache()
+ accelerator.wait_for_everyone()
+
+ # 多卡情况下,把各进程算出的结果all_gather汇总到一份完整列表。
+ cache_data = [s['da'] for s in sample_list]
+ if accelerator.num_processes > 1:
+ all_data = [None] * accelerator.num_processes
+ dist.all_gather_object(all_data, cache_data)
+ all_data = [item for sublist in all_data for item in sublist]
+ else:
+ # single-process run: no process group is initialized, and there is only
+ # one rank's data anyway -- see the matching Pass 0 cache-gather comment above.
+ all_data = cache_data
+
+ ress = all_data
+
+ if accelerator.is_main_process:
+ import copy
+ # ── 把这次运行实际生效的超参编码进输出文件名(hparam_tag)。原因:
+ # 网格搜索/消融脚本会用不同的--attn_layers_text/--attn_key_bias_text/
+ # --auction_*等参数反复跑同一个OUTPUT_PATH,如果文件名不带超参信息,
+ # 后一次运行的result.json会静默覆盖前一次的结果。编码后每种超参组合
+ # 都有自己独立的文件,之后扫描同一个OUTPUT_PATH就能把每种组合的分数
+ # 都读回来对比。
+ #
+ # 这里特意使用"实际生效值"(经过_text_only/_vis_only清零之后的值),
+ # 而不是原始的--attn_key_bias_vis等命令行参数值——比如
+ # run_eval_attnbias_sam_text.sh从来不传--attn_key_bias_vis,它会退回
+ # argparse的默认值(3.0),但_make_attn_ctx在运行时把它强制改成了0.0;
+ # 如果文件名里标注的是"没被使用的默认值3.0"而不是"真正生效的0.0",
+ # 之后回读文件名时会产生误导。
+ # Encode the hyperparameters that actually vary across ablation/grid-search
+ # runs into the output filename, so re-running the same script with
+ # different --attn_layers_text/--attn_key_bias_text/etc (or --auction_*)
+ # doesn't silently overwrite a previous run's result.json under the same
+ # OUTPUT_PATH -- each combination gets its own file, and a later sweep
+ # over this OUTPUT_PATH can read every combination's score back out.
+ _eff_key_bias_text = 0.0 if _vis_only else args.attn_key_bias_text
+ _eff_nonkey_bias_text = 0.0 if _vis_only else args.attn_nonkey_bias_text
+ _eff_key_bias_vis = 0.0 if _text_only else args.attn_key_bias_vis
+ _eff_nonkey_bias_vis = 0.0 if _text_only else args.attn_nonkey_bias_vis
+ hparam_tag = (
+ f"Lt{args.attn_layers_text}_kt{_eff_key_bias_text}_nt{_eff_nonkey_bias_text}"
+ f"_Lv{args.attn_layers_vis}_kv{_eff_key_bias_vis}_nv{_eff_nonkey_bias_vis}"
+ )
+ if args.auction_enable:
+ hparam_tag += f"_auc_tr{args.auction_total_ratio}_nr{args.auction_neg_ratio}"
+ hparam_tag = re.sub(r"[,\s]", "", hparam_tag)
+ task_name = (os.path.basename(args.model_path)
+ + f'_{os.path.split(args.data_path)[-1].replace(".json","")}'
+ + f'_{args.intervention}_{hparam_tag}')
+
+ def _save_and_score(ress_input, key, suffix):
+ """把结果列表写成{task_name}{suffix}.json,再调用score_mix_llava算分,
+ 分数单独写一份{task_name}{suffix}_result.json。"""
+ ress_copy = []
+ for d in ress_input:
+ dc = copy.deepcopy(d)
+ dc['model_output'] = d.get(key, d['model_output'])
+ ress_copy.append(dc)
+ out_f = os.path.join(args.output_path, f'{task_name}{suffix}.json')
+ with open(out_f, 'w') as fw:
+ json.dump(ress_copy, fw, ensure_ascii=False, indent=2)
+ val = score_mix_llava(ress_copy)
+ accelerator.print(f'[{suffix}] {json.dumps(val, ensure_ascii=False, indent=2)}')
+ with open(os.path.join(args.output_path, f'{task_name}{suffix}_result.json'), 'w') as fw:
+ json.dump(val, fw, ensure_ascii=False, indent=2)
+ print(f'{suffix} results: {out_f}')
+
+ print(f'question num: {len(ress)}')
+ _save_and_score(ress, 'model_output', '')
+
+
+# ================================================================================
+# Arguments —original eval.py args unchanged, intervention args added
+# 命令行参数定义。下面按模块分组标注每组参数的作用,对照sh脚本里传的值更容易理解。
+# ================================================================================
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Args of sft')
+
+ # ── 模型/数据基础参数:跟普通eval.py一致 ──
+ parser.add_argument('--data_path', default='medical_multimodel_evaluation_data.json', type=str)
+ parser.add_argument('--model_path', default='HuatuoGPT-Vision-7B', type=str)
+ parser.add_argument('--max_new_tokens', default=256, type=int)
+ parser.add_argument('--batch_size', default=2, type=int)
+
+ # Other Args
+ parser.add_argument('--seed', default=42, type=int)
+
+ # ── 注意力干预相关参数 ──
+ # pt_path*: 自动选层(load_top_layers)用的.pt文件路径,跟--attn_layers_text/vis
+ # 是二选一的关系,写死层号时这几个参数不需要。
+ parser.add_argument('--pt_path', type=str, default=None)
+ parser.add_argument('--pt_path_random', type=str, default=None)
+ parser.add_argument('--pt_path_text', type=str, default=None)
+ parser.add_argument('--pt_path_text_random', type=str, default=None)
+ # attn_layers_text/vis: 文本侧/视觉侧分别在哪几层注入偏置(逗号分隔多层)。
+ parser.add_argument('--attn_layers_text', type=str, default=17)
+ parser.add_argument('--attn_topk_text', type=int, default=1)
+ parser.add_argument('--attn_layers_vis', type=str, default=17)
+ parser.add_argument('--attn_topk_vis', type=int, default=1)
+ # attn_key_bias_*: 关键token(关键词/SAM patch)加的正偏置强度。
+ # attn_nonkey_bias_*: 非关键token加的负偏置强度(通常是负数)。
+ parser.add_argument('--attn_key_bias_text', type=float, default=3.0)
+ parser.add_argument('--attn_nonkey_bias_text', type=float, default=-3.0)
+ parser.add_argument('--attn_key_bias_vis', type=float, default=3.0)
+ parser.add_argument('--attn_nonkey_bias_vis', type=float, default=-3.0)
+ # intervention: 干预模式总开关——both(文本+视觉都偏置)/text(只偏置文本)/
+ # vis(只偏置视觉)/none(完全不干预,纯基线)。
+ parser.add_argument('--intervention', type=str, default='both', choices=['both', 'text', 'vis', 'none'])
+ # medsam3_*: MedSAM3的配置路径/设备/分割阈值/NMS参数,only intervention
+ # 是both/vis时才会真正用到(见test()里的_needs_sam判断)。
+ parser.add_argument('--medsam3_config', type=str, default=None)
+ parser.add_argument('--medsam3_dir', type=str, default=None)
+ parser.add_argument('--medsam3_device', type=str, default=None)
+ parser.add_argument('--medsam3_threshold', type=float, default=0.3)
+ parser.add_argument('--medsam3_nms_iou', type=float, default=0.5)
+ parser.add_argument('--output_path', type=str, default='results_attnbias')
+ parser.add_argument('--max_samples', type=int, default=None)
+
+ # ── 预算拍卖参数(可选;训练-free的token选择机制,详见BudgetedTokenAuction类)。
+ # 默认不开(auction_enable=False),不传这个参数时,原有的text/vis/both/none
+ # 干预行为完全不受影响——拍卖是纯加法功能,不会改变没开拍卖时的逻辑。──
+ parser.add_argument('--auction_enable', action='store_true', default=False)
+ # auction_total_ratio/neg_ratio: 正向/负向预算占候选池大小的比例,而不是
+ # 固定token数量(详见BudgetedTokenAuction文档字符串)。0.1/0.05大致对应旧版
+ # 固定预算(64/30)在~600 token候选池下的水平,但现在会随问题长度自动缩放。
+ parser.add_argument('--auction_total_ratio', type=float, default=0.1)
+ parser.add_argument('--auction_neg_ratio', type=float, default=0.05)
+
+ # ── 抽查可视化:默认开启,把Pass 1生成循环里"这次真正生效的偏置对象"画出来
+ # 存到{output_path}/vis_mask_debug/下(视觉区域画在原图上,文本渲染成图片,
+ # 见visualize_masked_region/render_masked_text_image),供人工确认mask的
+ # 坐标/位置算对了没有。--no_vis_mask关闭这个功能(大规模跑批、不需要人工
+ # 抽查时可以关掉省一点IO/绘图开销);--vis_mask_limit控制最多存多少个样本
+ # 的图(不是每个样本都需要留证据,默认50张足够人工抽查判断趋势)。──────
+ parser.add_argument('--no_vis_mask', action='store_true', default=False)
+ parser.add_argument('--vis_mask_limit', type=int, default=50)
+
+ # ── 偏置前/后attention对比:默认开启,但受--vis_mask_limit(默认50)约束,
+ # 跟mask可视化共用同一个计数器_vis_mask_save_count,只对前若干个样本
+ # 生效,不会对整个数据集都多跑这2次单步forward——每个样本这个功能会
+ # 额外多跑1-2次完整前向(比纯画图的mask可视化开销明显更大),如果不加这个
+ # 数量上限,默认对所有样本打开会显著拖慢大规模跑批。开启后对每个受限的
+ # 可视化样本额外产出attn_region_{id}.png(视觉侧偏置前/后热力图对比)和
+ # attn_text_{id}.png(文本侧偏置前/后attention高亮对比),见
+ # visualize_attn_before_after_region/render_attn_before_after_text。
+ # --no_attn_before_after可以单独关掉这一项(同时保留mask可视化)。────
+ parser.add_argument('--no_attn_before_after', action='store_true', default=False)
+
+ # ── 路由/拍卖可视化:只在--auction_enable开启时才有意义(rollout分数是
+ # BudgetedTokenAuction内部专用的打分依据,没开拍卖时压根不会被算出来)。
+ # 默认开启,同样受--vis_mask_limit约束,跟上面两组可视化是完全独立的
+ # 第三组开关——把rollout分数本身画成热力图/高亮图,并叠加拍卖选中的
+ # 正向(红)/负向(蓝)标记,用来验证"拍卖选中的到底是rollout分数高的还是
+ # 低的位置",回答的是"拍卖为什么选中这些token",跟上面attn_before_after
+ # (回答"偏置生效前后attention变化多少")是两件不同的事,见
+ # visualize_rollout_region/render_rollout_text。
+ parser.add_argument('--no_rollout_vis', action='store_true', default=False)
+ parser.add_argument('--no_rollout_text', action='store_true', default=False)
+
+ args = parser.parse_args()
+
+ set_seed(args.seed)
+ test(args)
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid.sh
new file mode 100644
index 0000000000000000000000000000000000000000..9681f413fc7912f4657d615dc07584d7a576baca
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+# Full grid search over (strength_text, strength_vis) for the "both"
+# intervention mode WITH Budgeted Token Auction enabled, split across GPU 2
+# and GPU 3 and run concurrently via run_ablation_grid_worker.sh (GPU 0/1 are
+# left free for other jobs on this workstation, so 2/3 are used instead of
+# the usual 0/1 -- see run_eval.sh for the same reasoning). The bias
+# layer is fixed at 17 for both modalities; text and vis each get their own
+# strength sweep and every (strength_text, strength_vis) combination is run --
+# kbt=nbt=-s_text, kbv=nbv=-s_vis for s_text in STRENGTHS_TEXT, s_vis in
+# STRENGTHS_VIS. Stage1/SAM results are cached in eval_attnbias_sam.py (keyed
+# on data_path/model_path/seed, see HuatuoGPT-Vision/cache/sam_stage1_cache/)
+# and are independent of the bias layer/strength/auction args, so re-running
+# a combo only re-pays the much cheaper bias-intervention generation pass.
+# Auction budgets/alpha/beta are fixed at their defaults here -- this script
+# only sweeps bias strength, not the auction hyperparameters themselves.
+# Each combo writes to its own output dir under results_attnbias_ablation/, so
+# this never touches results_attnbias/HuatuoGPT-Vision-7B/sam_both or any other
+# previously saved result.
+#
+# NOTE: picking the best (s_text, s_vis) and syncing it into every
+# run_eval_attnbias_sam_*.sh needs the WHOLE grid scored first, so it is
+# NOT done here -- run ./run_ablation_grid_pick.sh by hand once this script
+# (both GPU workers) finishes. STRENGTHS_TEXT/STRENGTHS_VIS/LAYER are defined
+# independently in run_ablation_grid_worker.sh and run_ablation_grid_pick.sh;
+# keep all three in sync if you change the grid.
+#
+# Pass 0 (keyword/Stage1/SAM extraction) in eval_attnbias_sam.py caches its
+# output keyed only on (data_path, model_path, seed) -- every combo in this
+# grid shares the exact same key, so both GPU workers would hit the *same*
+# cache file. accelerator.wait_for_everyone() only synchronizes ranks within
+# one `accelerate launch` process group; GPU2's and GPU3's workers are two
+# fully independent processes with no cross-process coordination, so if both
+# ran Pass 0 concurrently on a cold cache they'd race to read-modify-write the
+# same JSON file (worst case: interleaved writes corrupt it; typical case:
+# whichever finishes last silently clobbers the other's freshly-computed
+# entries with the stale snapshot it read at startup) and both would
+# redundantly re-run the expensive Stage1+SAM pass over the whole dataset.
+# Fix: run ONE combo alone first (GPU 2, combo index 0) to fully populate the
+# cache -- Pass 0 always covers the whole dataset regardless of which combo is
+# running, so after this single warmup run every subsequent Pass 0 (on either
+# GPU) is a pure cache hit and never writes to the file, making the parallel
+# phase below race-free.
+set -e
+
+echo "[ablation-grid] warmup: running combo 0 alone on GPU 2 to populate the Pass0 cache before parallelizing"
+./run_ablation_grid_worker.sh 2 0 1 > ablation_grid_warmup.log 2>&1
+echo "[ablation-grid] warmup done (log: ablation_grid_warmup.log)"
+
+TOTAL=25 # len(STRENGTHS_TEXT) * len(STRENGTHS_VIS), see run_ablation_grid_worker.sh
+SPLIT=13 # combos [1, SPLIT) -> GPU 2, combos [SPLIT, TOTAL) -> GPU 3
+# combo 0 already ran during warmup above -- GPU2's parallel slice starts at
+# index 1 (not 0) so it isn't touched again at all, not even via the
+# OUTPUT_PATH-exists skip check.
+
+echo "[ablation-grid] launching GPU 2 on combos [1, $SPLIT) and GPU 3 on combos [$SPLIT, $TOTAL) in parallel"
+
+./run_ablation_grid_worker.sh 2 1 $((SPLIT - 1)) > ablation_grid_gpu2.log 2>&1 &
+PID0=$!
+./run_ablation_grid_worker.sh 3 "$SPLIT" $((TOTAL - SPLIT)) > ablation_grid_gpu3.log 2>&1 &
+PID1=$!
+
+echo "[ablation-grid] gpu2 worker pid=$PID0 (log: ablation_grid_gpu2.log), gpu3 worker pid=$PID1 (log: ablation_grid_gpu3.log)"
+
+wait "$PID0"
+STATUS0=$?
+wait "$PID1"
+STATUS1=$?
+
+if [ "$STATUS0" -ne 0 ] || [ "$STATUS1" -ne 0 ]; then
+ echo "[ablation-grid] a worker failed (gpu2 exit=$STATUS0, gpu3 exit=$STATUS1) -- check ablation_grid_gpu{2,3}.log before running run_ablation_grid_pick.sh" >&2
+ exit 1
+fi
+
+echo "[ablation-grid] both workers finished, all $TOTAL combinations done"
+echo "[ablation-grid] now run: ./run_ablation_grid_pick.sh"
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_layer.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_layer.sh
new file mode 100644
index 0000000000000000000000000000000000000000..7dedc5baa327169508f1862edbd425d194093c0a
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_layer.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+# Stage 2 of the two-stage greedy ablation search: run_ablation_grid.sh (+
+# optionally run_ablation_grid_pick.sh) already found the best (s_text, s_vis)
+# with the bias layer fixed at 17, and a first pass already tested
+# LAYERS=(3 10 17 24 27) serially. This script covers the remaining 23 layers
+# (the model has 28 total, indices 0-27, confirmed via
+# PretrainedConfig.get_config_dict(...)['num_hidden_layers'] == 28) by
+# splitting them across GPU 0 and GPU 2 via run_ablation_grid_layer_worker.sh
+# (GPU 1/3 are occupied by other people's jobs on this workstation, so 0/2 are
+# used instead of the usual 0/1), running concurrently -- no cache-warmup step first (see
+# run_ablation_grid_layer_worker.sh's header for why that's safe here: the
+# Pass0 cache should already be fully warm from every prior run in this repo
+# sharing the same data_path/model_path/seed).
+#
+# After both workers finish, this script picks the best layer across ALL 28
+# (the original 5 + these 23), fixed at the same winning (s_text, s_vis), and
+# syncs the final (layer, s_text, s_vis) into every run_eval_attnbias_sam_*.sh.
+#
+# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias is
+# pinned at 0 (amplify_only) and the auction mechanism is OFF for this whole
+# search, matching run_ablation_grid_worker.sh/run_ablation_grid_layer_worker.sh.
+set -e
+
+TOTAL=23 # len(LAYERS_REMAINING), see run_ablation_grid_layer_worker.sh
+SPLIT=12 # indices [0, SPLIT) -> GPU 0, indices [SPLIT, TOTAL) -> GPU 2
+
+echo "[ablation-grid-layer] launching GPU 0 on layer-indices [0, $SPLIT) and GPU 2 on [$SPLIT, $TOTAL) in parallel (no warmup)"
+
+./run_ablation_grid_layer_worker.sh 0 0 "$SPLIT" > ablation_grid_layer_gpu0.log 2>&1 &
+PID0=$!
+./run_ablation_grid_layer_worker.sh 2 "$SPLIT" $((TOTAL - SPLIT)) > ablation_grid_layer_gpu2.log 2>&1 &
+PID1=$!
+
+echo "[ablation-grid-layer] gpu0 worker pid=$PID0 (log: ablation_grid_layer_gpu0.log), gpu2 worker pid=$PID1 (log: ablation_grid_layer_gpu2.log)"
+
+wait "$PID0"
+STATUS0=$?
+wait "$PID1"
+STATUS1=$?
+
+if [ "$STATUS0" -ne 0 ] || [ "$STATUS1" -ne 0 ]; then
+ echo "[ablation-grid-layer] a worker failed (gpu0 exit=$STATUS0, gpu2 exit=$STATUS1) -- check ablation_grid_layer_gpu{0,2}.log" >&2
+ exit 1
+fi
+
+echo "[ablation-grid-layer] both workers finished, all $TOTAL remaining layers done"
+
+source /home/jinhua/miniconda3/etc/profile.d/conda.sh
+conda activate huatuovision
+
+STAGE1_LAYER=17
+STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
+STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
+# every layer the model has been tested at: the original 5-point sweep plus
+# the 23 "remaining" layers this script just ran.
+LAYERS_ALL=(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27)
+
+# ── re-derive the winning (s_text, s_vis) directly from the strength grid's
+# result files, same scan-and-compare as run_ablation_grid_pick.sh.
+echo "[ablation-grid-layer] re-scanning the strength grid's results to find the winning (s_text, s_vis)..."
+S_TEXT=""
+S_VIS=""
+STAGE1_BEST_SCORE=""
+for ST in "${STRENGTHS_TEXT[@]}"; do
+ for SV in "${STRENGTHS_VIS[@]}"; do
+ STAGE1_OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${STAGE1_LAYER}_stext${ST}_svis${SV}"
+ STAGE1_RESULT_F=$(ls "$STAGE1_OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
+ if [ -z "$STAGE1_RESULT_F" ]; then
+ echo "[ablation-grid-layer] missing *_result.json under $STAGE1_OUTPUT_PATH -- has the strength grid finished?" >&2
+ exit 1
+ fi
+ STAGE1_SCORE=$(python -c "
+import json
+with open('$STAGE1_RESULT_F') as f:
+ d = json.load(f)
+print(d['The total score for multiple-choice questions'])
+")
+ if [ -z "$STAGE1_BEST_SCORE" ] || python -c "exit(0 if $STAGE1_SCORE > $STAGE1_BEST_SCORE else 1)"; then
+ STAGE1_BEST_SCORE="$STAGE1_SCORE"
+ S_TEXT="$ST"
+ S_VIS="$SV"
+ fi
+ done
+done
+echo "[ablation-grid-layer] strength winner: s_text=$S_TEXT s_vis=$S_VIS (score=$STAGE1_BEST_SCORE)"
+
+# ── pick the best layer across all 28, strength fixed at (S_TEXT, S_VIS).
+BEST_LAYER=""
+BEST_SCORE=""
+for LAYER in "${LAYERS_ALL[@]}"; do
+ OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
+ RESULT_F=$(ls "$OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
+ if [ -z "$RESULT_F" ]; then
+ echo "[ablation-grid-layer] missing *_result.json under $OUTPUT_PATH -- cannot pick best layer (layer=$LAYER not yet run)" >&2
+ exit 1
+ fi
+ SCORE=$(python -c "
+import json
+with open('$RESULT_F') as f:
+ d = json.load(f)
+print(d['The total score for multiple-choice questions'])
+")
+ echo "[ablation-grid-layer] layer=$LAYER score=$SCORE"
+ if [ -z "$BEST_SCORE" ] || python -c "exit(0 if $SCORE > $BEST_SCORE else 1)"; then
+ BEST_SCORE="$SCORE"
+ BEST_LAYER="$LAYER"
+ fi
+done
+
+echo "[ablation-grid-layer] best overall across all 28 layers: layer=$BEST_LAYER s_text=$S_TEXT s_vis=$S_VIS (score=$BEST_SCORE)"
+echo "[ablation-grid-layer] syncing into every run_eval_attnbias_sam_*.sh via sync_attn_params.py"
+
+python sync_attn_params.py \
+ --layers_text "$BEST_LAYER" --key_bias_text "$S_TEXT" --nonkey_bias_text "0" \
+ --layers_vis "$BEST_LAYER" --key_bias_vis "$S_VIS" --nonkey_bias_vis "0"
+
+echo "[ablation-grid-layer] done. All run_eval_attnbias_sam_*.sh now use the ablation-selected layer/strength (nonkey_bias=0, amplify_only style)"
+echo "[ablation-grid-layer] (amplify_only keeps its pinned-zero side; text.sh/vis.sh keep their single-modality side -- see sync_attn_params.py)."
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_layer_worker.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_layer_worker.sh
new file mode 100644
index 0000000000000000000000000000000000000000..97a9a71a2309d36aa1ebc4a1bc720507e4e1b784
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_layer_worker.sh
@@ -0,0 +1,144 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+# Runs a contiguous slice of the "remaining layers" sweep (the 23 layers NOT
+# already covered by the original LAYERS=(3 10 17 24 27) test) on a single
+# GPU, so the full sweep can be split across GPU 0 and GPU 2 and run
+# concurrently (GPU 1/3 are occupied by other jobs on this workstation) --
+# same pattern as run_ablation_grid_worker.sh for the strength grid, but for
+# layers.
+#
+# NO cache-warmup step here (unlike run_ablation_grid.sh's stage 1): by the
+# time this runs, the Pass0 cache (keyed on data_path/model_path/seed, shared
+# across every combo/script in this repo) has already been fully populated by
+# the earlier strength grid + original 5-layer sweep + run_all_attnbias_sam.sh
+# runs, so both GPU workers should hit pure cache reads with nothing new to
+# write -- eliminating the write-race risk without needing a serialized
+# warmup run first. This assumption only breaks if the cache is somehow still
+# incomplete (e.g. an earlier run was interrupted before finishing Pass 0);
+# if you're not confident the cache is fully warm, warm it manually first
+# (run any single combo alone) before launching this in parallel.
+#
+# S_TEXT/S_VIS are re-derived from the strength grid's results (same as
+# run_ablation_grid_layer.sh), not hand-filled.
+#
+# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias_text/vis
+# are pinned at 0 (amplify_only) AND the auction mechanism is OFF, matching
+# run_ablation_grid_worker.sh's strength grid exactly. Output dirs use the
+# "sam_both_amplify_noauction_..." tag to match.
+#
+# Usage:
+# ./run_ablation_grid_layer_worker.sh
+# Example (23 combos split 12/11 across 2 GPUs):
+# ./run_ablation_grid_layer_worker.sh 0 0 12 &
+# ./run_ablation_grid_layer_worker.sh 2 12 11 &
+# wait
+set -e
+
+GPU_ID="$1"
+START="$2"
+COUNT="$3"
+if [ -z "$GPU_ID" ] || [ -z "$START" ] || [ -z "$COUNT" ]; then
+ echo "usage: $0 " >&2
+ exit 1
+fi
+export CUDA_VISIBLE_DEVICES="$GPU_ID"
+
+source /home/jinhua/miniconda3/etc/profile.d/conda.sh
+conda activate huatuovision
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+INTERVENTION="both"
+# the 23 layers NOT in the original LAYERS=(3 10 17 24 27) test -- model has
+# 28 layers total (indices 0-27), confirmed via
+# PretrainedConfig.get_config_dict('FreedomIntelligence/HuatuoGPT-Vision-7B')['num_hidden_layers'] == 28.
+# run_ablation_grid_layer.sh (the driver) does NOT keep its own copy of this
+# array -- it only needs the total count (TOTAL=23) to split indices across
+# GPU 0/1, plus a separate LAYERS_ALL (all 28) for the final "pick best
+# layer" scan. If you change this array's length, update TOTAL/SPLIT in
+# run_ablation_grid_layer.sh to match.
+LAYERS_REMAINING=(0 1 2 4 5 6 7 8 9 11 12 13 14 15 16 18 19 20 21 22 23 25 26)
+STAGE1_LAYER=17
+STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
+STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
+
+MAX_SAMPLES=""
+
+# ── re-derive stage 1's winning (s_text, s_vis) directly from the strength
+# grid's result files -- same scan-and-compare as run_ablation_grid_pick.sh.
+echo "[ablation-grid-layer-worker gpu=$GPU_ID] re-scanning stage 1's results to find the winning (s_text, s_vis)..."
+S_TEXT=""
+S_VIS=""
+STAGE1_BEST_SCORE=""
+for ST in "${STRENGTHS_TEXT[@]}"; do
+ for SV in "${STRENGTHS_VIS[@]}"; do
+ STAGE1_OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${STAGE1_LAYER}_stext${ST}_svis${SV}"
+ STAGE1_RESULT_F=$(ls "$STAGE1_OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
+ if [ -z "$STAGE1_RESULT_F" ]; then
+ echo "[ablation-grid-layer-worker gpu=$GPU_ID] missing *_result.json under $STAGE1_OUTPUT_PATH -- has the strength grid finished?" >&2
+ exit 1
+ fi
+ STAGE1_SCORE=$(python -c "
+import json
+with open('$STAGE1_RESULT_F') as f:
+ d = json.load(f)
+print(d['The total score for multiple-choice questions'])
+")
+ if [ -z "$STAGE1_BEST_SCORE" ] || python -c "exit(0 if $STAGE1_SCORE > $STAGE1_BEST_SCORE else 1)"; then
+ STAGE1_BEST_SCORE="$STAGE1_SCORE"
+ S_TEXT="$ST"
+ S_VIS="$SV"
+ fi
+ done
+done
+echo "[ablation-grid-layer-worker gpu=$GPU_ID] strength winner: s_text=$S_TEXT s_vis=$S_VIS (score=$STAGE1_BEST_SCORE) -- fixing strength at this combo for the layer sweep"
+
+TOTAL=${#LAYERS_REMAINING[@]}
+END=$((START + COUNT))
+if [ "$END" -gt "$TOTAL" ]; then
+ END="$TOTAL"
+fi
+
+echo "[ablation-grid-layer-worker gpu=$GPU_ID] running layers [$START, $END) of $TOTAL total"
+
+for ((i = START; i < END; i++)); do
+ LAYER="${LAYERS_REMAINING[$i]}"
+ OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
+ if [ -d "$OUTPUT_PATH" ]; then
+ echo "[ablation-grid-layer-worker gpu=$GPU_ID] $OUTPUT_PATH already exists, skipping layer=$LAYER (delete the dir manually to re-run)"
+ continue
+ fi
+
+ echo "=================================================="
+ echo "[ablation-grid-layer-worker gpu=$GPU_ID] idx=$i layer=$LAYER s_text=$S_TEXT s_vis=$S_VIS -> $OUTPUT_PATH"
+ echo "=================================================="
+
+ accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$LAYER" \
+ --attn_key_bias_text "$S_TEXT" \
+ --attn_nonkey_bias_text "0" \
+ --attn_layers_vis "$LAYER" \
+ --attn_key_bias_vis "$S_VIS" \
+ --attn_nonkey_bias_vis "0" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
+
+ echo "[ablation-grid-layer-worker gpu=$GPU_ID] idx=$i layer=$LAYER finished"
+done
+
+echo "[ablation-grid-layer-worker gpu=$GPU_ID] done with layers [$START, $END)"
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_pick.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_pick.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c930034d8efb14d06428e402ce4bd488f64b5c6e
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_pick.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+# Picks the best (strength_text, strength_vis) across the full grid and syncs
+# it into every run_eval_attnbias_sam_*.sh via sync_attn_params.py. Run this
+# ONCE, by hand, after every run_ablation_grid_worker.sh slice (on every GPU
+# you split the grid across) has finished -- it requires *all* combos'
+# *_result.json to be present, since the "best" choice isn't meaningful until
+# the whole grid has been scored.
+#
+# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias is
+# pinned at 0 (amplify_only -- boost key regions only, no suppression) AND the
+# grid was searched with the auction mechanism OFF (see
+# run_ablation_grid_worker.sh), matching the final method exactly.
+# run_eval_attnbias_sam_both_suppress_only.sh has been dropped from
+# run_all_attnbias_sam.sh's comparison set (no longer a live ablation arm), so
+# there's no risk of this sync corrupting it.
+set -e
+
+source /home/jinhua/miniconda3/etc/profile.d/conda.sh
+conda activate huatuovision
+
+LAYER=17
+# must stay identical to run_ablation_grid_worker.sh's copy of these arrays.
+STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
+STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
+
+# ── pick the best (s_text, s_vis) across the full grid, layer fixed at 17.
+# Each combo's output dir holds exactly one *_result.json (eval_attnbias_sam.py's hparam_tag
+# already makes the filename unique per layer/strength/auction config, so
+# no risk of stale files from a previous combo lingering in the same dir),
+# so glob for it directly instead of hand-reconstructing the filename --
+# that reconstruction is what broke last time hparam_tag's format changed.
+BEST_S_TEXT=""
+BEST_S_VIS=""
+BEST_SCORE=""
+for S_TEXT in "${STRENGTHS_TEXT[@]}"; do
+ for S_VIS in "${STRENGTHS_VIS[@]}"; do
+ OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
+ RESULT_F=$(ls "$OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
+ if [ -z "$RESULT_F" ]; then
+ echo "[ablation-grid-pick] missing *_result.json under $OUTPUT_PATH -- cannot pick best (s_text, s_vis). Did every run_ablation_grid_worker.sh slice finish?" >&2
+ exit 1
+ fi
+ SCORE=$(python -c "
+import json
+with open('$RESULT_F') as f:
+ d = json.load(f)
+print(d['The total score for multiple-choice questions'])
+")
+ echo "[ablation-grid-pick] s_text=$S_TEXT s_vis=$S_VIS score=$SCORE"
+ if [ -z "$BEST_SCORE" ] || python -c "exit(0 if $SCORE > $BEST_SCORE else 1)"; then
+ BEST_SCORE="$SCORE"
+ BEST_S_TEXT="$S_TEXT"
+ BEST_S_VIS="$S_VIS"
+ fi
+ done
+done
+
+echo "[ablation-grid-pick] best overall: layer=$LAYER s_text=$BEST_S_TEXT s_vis=$BEST_S_VIS (score=$BEST_SCORE)"
+echo "[ablation-grid-pick] syncing into every run_eval_attnbias_sam_*.sh via sync_attn_params.py"
+
+python sync_attn_params.py \
+ --layers_text "$LAYER" --key_bias_text "$BEST_S_TEXT" --nonkey_bias_text "0" \
+ --layers_vis "$LAYER" --key_bias_vis "$BEST_S_VIS" --nonkey_bias_vis "0"
+
+echo "[ablation-grid-pick] done. All run_eval_attnbias_sam_*.sh now use the ablation-selected layer/strength (nonkey_bias=0, amplify_only style)"
+echo "[ablation-grid-pick] (amplify_only keeps its pinned-zero side; text.sh/vis.sh keep their single-modality side -- see sync_attn_params.py)."
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_worker.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_worker.sh
new file mode 100644
index 0000000000000000000000000000000000000000..7c39154db784abf6c0ba690d5f569a7352fbcd8c
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_ablation_grid_worker.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+# Runs a contiguous slice of the (strength_text, strength_vis) grid on a single
+# GPU, so the full 25-combo sweep can be split across e.g. GPU 0 and GPU 1 and
+# run concurrently. The full pair list is built in the same fixed order
+# (outer S_TEXT, inner S_VIS) as run_ablation_grid_pick.sh expects, so slicing
+# it by [START, START+COUNT) here and picking over the *union* of all slices'
+# output dirs later stays consistent -- this script does NOT do the final
+# "pick best + sync" step, that only makes sense once every slice (on every
+# GPU) has finished; run run_ablation_grid_pick.sh once by hand after all
+# workers exit.
+#
+# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias_text/vis
+# are pinned at 0 (amplify_only -- ablation found boosting key regions without
+# suppressing anything else beats full boost+suppress), AND the auction
+# mechanism is OFF (--auction_enable is not passed) -- every Stage1/SAM-detected
+# key position gets boosted, not just an auction-selected subset. This grid
+# searches under the SAME conditions as the final method (no auction), so the
+# winning strength is actually calibrated for what gets used, not for a
+# different (with-auction) config. Output dirs are tagged
+# "sam_both_amplify_noauction_..." so they don't collide with the earlier
+# auction-enabled grid searches' results.
+#
+# Usage:
+# ./run_ablation_grid_worker.sh
+# Example (25 combos split 13/12 across 2 GPUs -- 2/3 here because GPU 0/1 are
+# occupied by other jobs on this workstation, not the usual 0/1):
+# CUDA_VISIBLE_DEVICES managed internally from -- don't set it yourself.
+# ./run_ablation_grid_worker.sh 2 0 13 & # combos [0, 13) on GPU 2
+# ./run_ablation_grid_worker.sh 3 13 12 & # combos [13, 25) on GPU 3
+# wait
+# ./run_ablation_grid_pick.sh
+set -e
+
+GPU_ID="$1"
+START="$2"
+COUNT="$3"
+if [ -z "$GPU_ID" ] || [ -z "$START" ] || [ -z "$COUNT" ]; then
+ echo "usage: $0 " >&2
+ exit 1
+fi
+export CUDA_VISIBLE_DEVICES="$GPU_ID"
+
+source /home/jinhua/miniconda3/etc/profile.d/conda.sh
+conda activate huatuovision
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+INTERVENTION="both"
+LAYER=17
+# must stay identical to run_ablation_grid_pick.sh -- these define the pair
+# ordering/indices that / slice into.
+STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
+STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
+
+MAX_SAMPLES=""
+
+# flatten into "s_text s_vis" pairs, outer S_TEXT / inner S_VIS -- same order
+# run_ablation_grid_pick.sh iterates in, so index N here means the same combo
+# there.
+PAIRS=()
+for S_TEXT in "${STRENGTHS_TEXT[@]}"; do
+ for S_VIS in "${STRENGTHS_VIS[@]}"; do
+ PAIRS+=("$S_TEXT $S_VIS")
+ done
+done
+
+TOTAL=${#PAIRS[@]}
+END=$((START + COUNT))
+if [ "$END" -gt "$TOTAL" ]; then
+ END="$TOTAL"
+fi
+
+echo "[ablation-grid-worker gpu=$GPU_ID] running combos [$START, $END) of $TOTAL total"
+
+for ((i = START; i < END; i++)); do
+ read -r S_TEXT S_VIS <<< "${PAIRS[$i]}"
+ OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
+ if [ -d "$OUTPUT_PATH" ]; then
+ echo "[ablation-grid-worker gpu=$GPU_ID] $OUTPUT_PATH already exists, skipping s_text=$S_TEXT s_vis=$S_VIS (delete the dir manually to re-run)"
+ continue
+ fi
+
+ echo "=================================================="
+ echo "[ablation-grid-worker gpu=$GPU_ID] idx=$i layer=$LAYER s_text=$S_TEXT s_vis=$S_VIS -> $OUTPUT_PATH"
+ echo "=================================================="
+
+ accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$LAYER" \
+ --attn_key_bias_text "$S_TEXT" \
+ --attn_nonkey_bias_text "0" \
+ --attn_layers_vis "$LAYER" \
+ --attn_key_bias_vis "$S_VIS" \
+ --attn_nonkey_bias_vis "0" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
+
+ echo "[ablation-grid-worker gpu=$GPU_ID] idx=$i s_text=$S_TEXT s_vis=$S_VIS finished"
+done
+
+echo "[ablation-grid-worker gpu=$GPU_ID] done with combos [$START, $END)"
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_all_attnbias_sam.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_all_attnbias_sam.sh
new file mode 100644
index 0000000000000000000000000000000000000000..e61ddc8eff77724aab5a252b479995598c1dad33
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_all_attnbias_sam.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+# 先跑 baseline(无干预的 eval.py),再依次跑完对比组:
+# none(无attention干预)/ both(正式配置:全量放大关键区域,不开拍卖)/
+# text / vis(单模态消融)
+# run_eval_attnbias_sam_both_noauction.sh 内容跟正式配置both.sh完全一样(both.sh
+# 本身已经改成不开拍卖了),文件保留但不再放进这个清单,避免重复跑同一件事。
+# 任意一个失败就停止,避免在错误的环境下继续浪费时间
+set -e
+
+# 默认使用 huatuovision conda 环境,不依赖调用者当前激活的环境。
+# source profile.d/conda.sh是必须的:非交互式shell(setsid/nohup这类后台
+# 启动方式)不会自动加载~/.bashrc,conda activate这个shell函数不会被定义,
+# 必须显式source这个脚本才能在当前shell里用conda activate。
+source /home/jinhua/miniconda3/etc/profile.d/conda.sh
+conda activate huatuovision
+
+SCRIPTS=(
+ "run_eval.sh"
+ "run_eval_attnbias_sam_none.sh"
+ "run_eval_attnbias_sam_both.sh"
+ "run_eval_attnbias_sam_text.sh"
+ "run_eval_attnbias_sam_vis.sh"
+)
+
+for script in "${SCRIPTS[@]}"; do
+ echo "=================================================="
+ echo "[run_all] 开始运行 $script"
+ echo "=================================================="
+ bash "$script"
+ echo "[run_all] $script 运行完成"
+done
+
+echo "[run_all] 全部干预模式运行完成"
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval.sh
new file mode 100644
index 0000000000000000000000000000000000000000..665d1e401b40f090d5aba08d4de5cff8006da1ec
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+# 单卡跑,卡0/卡1留给其他任务,显式锁定卡2。
+# Single GPU -- pin to GPU 2 explicitly (GPU 0/1 are left for other jobs on
+# this workstation).
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS"
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both.sh
new file mode 100644
index 0000000000000000000000000000000000000000..335623f7a3b400f0af126e3c5d10e2567e5fb775
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+# FINAL METHOD: both mode, amplify-only (nonkey_bias pinned at 0 -- boost key
+# regions, don't suppress anything else) and auction OFF -- every Stage1/SAM-
+# detected key position gets boosted directly, not just an auction-selected
+# subset (ablation found the auction mechanism doesn't help over this simpler
+# design; see run_eval_attnbias_sam_both_noauction.sh, kept around for
+# reference but no longer part of the active comparison set).
+INTERVENTION="both"
+ATTN_LAYERS_TEXT=17
+ATTN_KEY_BIAS_TEXT=5.0
+ATTN_NONKEY_BIAS_TEXT=0
+ATTN_LAYERS_VIS=17
+ATTN_KEY_BIAS_VIS=1.0
+ATTN_NONKEY_BIAS_VIS=0
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
+ --attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ --attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
+ --attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_amplify_only.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_amplify_only.sh
new file mode 100644
index 0000000000000000000000000000000000000000..7f1da6b37dafdc7eeda642afd1909736504057d0
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_amplify_only.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_amplify_only"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+# Ablation: amplify-only. Key positions still get the positive bias, but
+# nonkey_bias_* is 0 instead of negative -- isolates how much of the "both"
+# result comes from amplifying keyword text / SAM patches, with no suppression
+# of distractors. Auction stays ON with the same ratio/alpha/beta as
+# run_eval_attnbias_sam_both.sh, so this differs from "both" by exactly one
+# factor (nonkey_bias_*); compare against run_eval_attnbias_sam_both_suppress_only.sh
+# (same setup, opposite side zeroed) and run_eval_attnbias_sam_both.sh.
+INTERVENTION="both"
+ATTN_LAYERS_TEXT=17
+ATTN_KEY_BIAS_TEXT=5.0
+ATTN_NONKEY_BIAS_TEXT=0.0
+ATTN_LAYERS_VIS=17
+ATTN_KEY_BIAS_VIS=1.0
+ATTN_NONKEY_BIAS_VIS=0.0
+
+AUCTION_TOTAL_RATIO=0.8
+AUCTION_NEG_RATIO=0.8
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
+ --attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ --attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
+ --attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ --auction_enable \
+ --auction_total_ratio "$AUCTION_TOTAL_RATIO" \
+ --auction_neg_ratio "$AUCTION_NEG_RATIO" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_noauction.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_noauction.sh
new file mode 100644
index 0000000000000000000000000000000000000000..29097cbb98c0da4fd12330218528dfc0ea425e1c
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_noauction.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_noauction"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+# both mode, auction OFF (legacy behavior): every SAM patch / scispaCy keyword
+# gets amplified, everything else gets suppressed -- no scoring, no budget. This
+# is the "before" half of the main ablation: none vs both-noauction vs both+auction.
+INTERVENTION="both"
+ATTN_LAYERS_TEXT=17
+ATTN_KEY_BIAS_TEXT=5.0
+ATTN_NONKEY_BIAS_TEXT=0
+ATTN_LAYERS_VIS=17
+ATTN_KEY_BIAS_VIS=1.0
+ATTN_NONKEY_BIAS_VIS=0
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
+ --attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ --attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
+ --attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_suppress_only.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_suppress_only.sh
new file mode 100644
index 0000000000000000000000000000000000000000..d5df95c8705174ba6733f36e7c7b11bb7054752b
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_both_suppress_only.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_suppress_only"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+# Ablation: suppress-only. nonkey_bias_* keeps the negative bias (distractors
+# suppressed), but key_bias_* is 0 instead of positive -- isolates how much of
+# the "both" result comes from suppressing non-keyword text / non-SAM visual
+# patches, with no amplification of the key set. Auction stays ON with the
+# same ratio/alpha/beta as run_eval_attnbias_sam_both.sh, so this differs from
+# "both" by exactly one factor (key_bias_*); compare against
+# run_eval_attnbias_sam_both_amplify_only.sh (same setup, opposite side
+# zeroed) and run_eval_attnbias_sam_both.sh.
+INTERVENTION="both"
+ATTN_LAYERS_TEXT=17
+ATTN_KEY_BIAS_TEXT=0.0
+ATTN_NONKEY_BIAS_TEXT=0
+ATTN_LAYERS_VIS=17
+ATTN_KEY_BIAS_VIS=0.0
+ATTN_NONKEY_BIAS_VIS=0
+
+AUCTION_TOTAL_RATIO=0.8
+AUCTION_NEG_RATIO=0.8
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
+ --attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ --attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
+ --attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ --auction_enable \
+ --auction_total_ratio "$AUCTION_TOTAL_RATIO" \
+ --auction_neg_ratio "$AUCTION_NEG_RATIO" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_none.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_none.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c86406e500269a1b895a05cb047cca413a73a578
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_none.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_none"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+# none: no attention intervention (model_output reuses plain inference result)
+INTERVENTION="none"
+ATTN_LAYERS_TEXT="17"
+ATTN_KEY_BIAS_TEXT=3.0
+ATTN_NONKEY_BIAS_TEXT=-3.0
+ATTN_LAYERS_VIS="17"
+ATTN_KEY_BIAS_VIS=3.0
+ATTN_NONKEY_BIAS_VIS=-3.0
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
+ --attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ --attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
+ --attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_text.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_text.sh
new file mode 100644
index 0000000000000000000000000000000000000000..a62b6fe923cee5b45953370811bc117acb172cae
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_text.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_text"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+# Modality ablation: text-only. Only the scispaCy keyword text positions get
+# biased (key_bias_text / nonkey_bias_text); the vis side is forced to 0 bias
+# inside _make_attn_ctx regardless of what's passed here. SAM/MedSAM3 is
+# skipped entirely (_needs_sam is False for "text"), so no medsam3_* args.
+# Matches run_eval_attnbias_sam_both.sh's mechanism (amplify-only, auction
+# OFF) so this differs from the final method by exactly one factor (modality
+# restricted to text); compare against run_eval_attnbias_sam_vis.sh and
+# run_eval_attnbias_sam_both.sh.
+INTERVENTION="text"
+ATTN_LAYERS_TEXT=17
+ATTN_KEY_BIAS_TEXT=5.0
+ATTN_NONKEY_BIAS_TEXT=0
+ATTN_LAYERS_VIS="17"
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
+ --attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_vis.sh b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_vis.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ff661e91f789f3f37d6ed91795a124cb5eaf8d44
--- /dev/null
+++ b/HuatuoGPT-Vision-Abla-New/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext1.0_svis1.0/_snapshot/run_eval_attnbias_sam_vis.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+cd "$(dirname "$0")"
+
+DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
+MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
+OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_vis"
+
+SEED=42
+MAX_NEW_TOKENS=256
+
+MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
+MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
+
+# Modality ablation: vis-only. Only the SAM bbox patches get biased
+# (key_bias_vis / nonkey_bias_vis); the text side is forced to 0 bias inside
+# _make_attn_ctx regardless of what's passed here. SAM/MedSAM3 still runs
+# (_needs_sam is True for "vis"). Matches run_eval_attnbias_sam_both.sh's
+# mechanism (amplify-only, auction OFF) so this differs from the final method
+# by exactly one factor (modality restricted to vis); compare against
+# run_eval_attnbias_sam_text.sh and run_eval_attnbias_sam_both.sh.
+INTERVENTION="vis"
+ATTN_LAYERS_TEXT=17
+ATTN_LAYERS_VIS=17
+ATTN_KEY_BIAS_VIS=1.0
+ATTN_NONKEY_BIAS_VIS=0
+
+MAX_SAMPLES=""
+
+# 单卡跑,跟run_eval.sh一样显式锁定卡2。
+export CUDA_VISIBLE_DEVICES=2
+
+accelerate launch --num_processes=1 eval_attnbias_sam.py \
+ --data_path "$DATA_PATH" \
+ --model_path "$MODEL_PATH" \
+ --seed "$SEED" \
+ --max_new_tokens "$MAX_NEW_TOKENS" \
+ --output_path "$OUTPUT_PATH" \
+ --intervention "$INTERVENTION" \
+ --attn_layers_text "$ATTN_LAYERS_TEXT" \
+ --attn_layers_vis "$ATTN_LAYERS_VIS" \
+ --attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
+ --attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
+ --medsam3_config "$MEDSAM3_CONFIG" \
+ --medsam3_dir "$MEDSAM3_DIR" \
+ ${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0010458--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0010458--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..ab10c2ec0b1477b77b6def66071ad4bedf67d168
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0010458--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6cb4abb2f4ecab0893ec68f1e1b45740a2d360324392efd469e38ff114e79b9d
+size 3986
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0011119--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0011119--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..84bbe3b9bc551676c3cc647bf291011ef176c6cf
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0011119--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0f5b6c7c25c8af3ee00306d409ad5582d6a7dff8cda5019d7156ba33094329f7
+size 3883
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0011323--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0011323--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..e2d88070a1d968977d8a84c6433d8a102876a764
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2016_task1--ISIC_0011323--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:231c4f3583f550c9885b1a25b15b715d17c7c76e6e48d993c20f9e0e035973bc
+size 4849
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0000078--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0000078--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..fad592fce6cb90ca5357487be1b15fbc96513a4b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0000078--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b1ac798063c9549d6e79fb2086bbc0e1538bb3d6f7585d10ba449802f8788f86
+size 6603
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0007796--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0007796--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..9b843f489c030259818112871b6e700a1c96d829
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0007796--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:27c35181f7223f5c49263e1fdbf826eef6d166f9b8e9b5942ad77efa105af57e
+size 12119
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0012320--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0012320--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..c44d9cb629946d8bb10036a40deadd5c65776e5d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0012320--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a73034b376586d222a227198e630e795d7c5a98df37d77b31121f9c9b7acd226
+size 11746
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0012682--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0012682--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..1251e15e69e8f18bc4bfb2982191441c42997f59
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0012682--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bb72063d4c2b9a957ccf889e438cfc8481e1fbc87fd919dc64298ac5183a48c6
+size 10223
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0013364--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0013364--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..59947131f088ee4948d4785b416b09b0e2944333
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0013364--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:46d13d906619977309311d7c582dc56fcfe8a8d84c30311c61ff0e4f61271b0c
+size 19817
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0016068--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0016068--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..9c9fed23b2445ec8291741a27b9d9681ba6d6df3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2017_task1--ISIC_0016068--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:357f4e97fdab0f3f7c15808fd8ad2149c92e838c18883b8833ad3f4b6f927692
+size 24054
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0000254--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0000254--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..eb8b018a5e338708b673c5285fe13b60bb785cc5
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0000254--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:653c1c1d0c65b91739ce656def1afe13253362e55a78d2f166a58fc4a878c540
+size 4017
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0007475--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0007475--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..576f18354756e89bf53d563205687091dfe72e1c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0007475--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f1e65a7d00ec1877b95beb1622bf4abe99402fdfa3ba016581b8f1c2d81c81f2
+size 12999
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0009958--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0009958--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..8550023188b11206b4d615ffec87f839b4fa36f6
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0009958--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fb1ba877a69c8365fcfba39d38314e964fad53c34b2caf4489a2e52e21434a74
+size 4037
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0010183--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0010183--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..6064ab7b98653975e013f80004ab7bc40c36b295
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0010183--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1d57cf72182621c7774f30312d3e0f88d04faa7780cde19aa6399a1ab8975bd7
+size 3871
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0012208--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0012208--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..c8a23505b87419bac006c5c0943667a3a6e9e19a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0012208--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6dd328d0230a2bbf9b7f7e84169ab67d1c1001d201ff05bcca2ccd1ea527af95
+size 11671
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0012544--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0012544--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..b2191fd3dfdd9bc556d4d6f7bb0aa20dfc50ffda
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0012544--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:72e275b6462685e7e663349570778e0d000204e3e05d0bd3df6c02a8f4db3c45
+size 18139
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0013075--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0013075--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..beacf8fedb8f21aaa660207a77debe2cba27a9a5
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0013075--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c60a6338a916127b59480c6c5b5e769b17e2e7b92618f8bd70a289e30244c3da
+size 16350
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0014453--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0014453--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..f0c3774b6531797f795754c51d8d1efb606acbf2
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0014453--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:969a278a90fbf6a34aa7554b121a1a2f84be2f9f2b483b8c4c6f55e2a8f2e9d7
+size 19357
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0014576--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0014576--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..65480f60f80dea3141954c154cb9c8e7d851bb4a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0014576--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:d79f32b98f5d768f007dcd860252eb42a2618036167b1ff19777ca97eb410d61
+size 11202
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0015251--2d_none--0000_000.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0015251--2d_none--0000_000.png
new file mode 100644
index 0000000000000000000000000000000000000000..38def2d01d89a8de9209d9c4e9ff07f70cd372b7
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/dermoscopy/masks/dermoscopy_00--isic2018_task1--ISIC_0015251--2d_none--0000_000.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:78135a831ba5c2c0b63b934d1668229f8501a64748ae1d44061d79d9e1c3c777
+size 67008
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0002--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0002--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9a1fa7b63453025b0abc8c83e3f3ac6b66e95462
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0002--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a1a3f461397633a8b964953e921f612e5008c2b8f08534d9243e41d057eefd5d
+size 1753728
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0016--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0016--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5c7961f2b9c8076b2f0c3278cdf064f48888f73b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0016--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5650059c5127c03a5d1e158380a35cbd44cab08f26a1d6ddd5e66ff38a12d4ba
+size 3937339
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0023--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0023--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5adaf9f44419aec123a5aa1a5c8faf5016c0c360
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0023--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:eddc24eebc65db3fa4bf127920628b4771e6fc030757e3576e09e9b41afb34d3
+size 3838106
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0025--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0025--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..4b18bc6c7919edbf1ef9489ff82928ceb725f76e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--H0025--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:473ee7837a33afa3097d8d182272266206e8658238b714343d1b0c00e2656d15
+size 3961335
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0002--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0002--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..29e13260cc57dee40aa6547fe5b8d3429e485827
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0002--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0c92d8fb2c5d6f2a6eb0775aaab26cf1deb46080f965deef70ae6c1a6157886e
+size 3924755
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0010--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0010--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9ddf244aaaf23330e34a0c2968f52165a4073baa
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0010--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ab143c0021f1f57ab0166008609e4205326c9683de22fe63b6d4522779a762b5
+size 3628389
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0017--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0017--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..73c55c3e142440cdab4ae1b6f9c37bbcab03d60c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0017--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f8e452860899275be4df90fe634e2a4ceedbe09eb37caada6f216fa07c42be87
+size 3325515
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0019--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0019--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..19b0a9a6a9d288fda86f8f72dd278da7187f9117
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0019--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:50a20c89a8c691ea2d9aaf10c85b2c35449a9f7c56bffad98476958a65921cd9
+size 3681241
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0047--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0047--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..62f5464165aeb2e1a307b30920c5c1b421123d7e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0047--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e9e1d4fc45eebf36a6d4a62854eb2b953915582a39c8ba87308797b28239eed9
+size 3775849
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0055--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0055--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b09da9456d2e5216729b4c951fea19d3c147d6dc
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0055--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cd993ebe0c272e94e35ad24d032c5e6366e539e57f216221abccb0b5416a4825
+size 3979462
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0060--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0060--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..688e84e08eaab08181b89d897f998690bdc757a3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0060--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:90d9130b0dbf3db3cab1ab8c8ae5ef33354d523610af2613840e69c6f132b2b6
+size 3649940
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0062--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0062--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..bc8368b217892771b1a41905461a2615a0a69b06
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0062--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3b56efe968d466f3fb4c9f7eb929f96c01baf4099ed219214f932342f2c13b1b
+size 3892529
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0073--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0073--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5ddf738881bbb249aea3438eaa1fb09c511ebfc5
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0073--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:535fa4635daceae85353a290e7e1acd9717d0310cdbe591d60c903754fad37fc
+size 3334803
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0086--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0086--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2b26b9e18eee572d10e890210877b877ef345740
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0086--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:86c226d70434bd4e7e5f6335dd0dcfed1c256e5227f8b717ee729ab88f00383d
+size 3696697
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0093--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0093--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..c0b419954875f3e0adaa274a5be61afaf82a2591
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0093--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f03893fc90649301c6cbf59488af5f287b3090f025c4b41ea9cadf02413eb4d8
+size 3465276
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0095--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0095--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2a6d3cf7075bc5c9251569a250a8aa932b395f99
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0095--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c3b0eac50b4019c5920fb78597e98524d58dd26812663a0b0ba8a10cd06bda1e
+size 3502656
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0115--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0115--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e3c32f1e7a185ff3a23188464a1bf2ef965457c8
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0115--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7e4910f76da5771ee8d543b8b42a044394430c27a72810ab909a1304e8987741
+size 3578438
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0120--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0120--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..c8d4b0a3b61bab1034af3d8bc2ce50a8078d995d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0120--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3d878be9b25406144cf969c2b278823ccb36e0083125bea5427f97314f1925b0
+size 3722885
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0122--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0122--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..191233485c0a5b7de40ae55857e2e60c6c2c7b4d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0122--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ba0e64077c8bf009e5ad76edd9cae47994bffeb8e7f4c399110627d68e1ec62d
+size 3588042
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0139--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0139--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..76ab4dca8df1336384afedb3bae2b80098147401
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0139--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b42a53faa27b58cd2b5ebe68f648d275114f03f5705f7c9188049bb43b781d6f
+size 3218881
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0158--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0158--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..72097d2acd7ebdb8cafb3ba0a43988b14805b092
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--N0158--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3974e202018bcc050709baa0450950104a2271683c38522a38e370b7de879928
+size 3427004
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0004--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0004--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..fd897a1ba23fca2c155b7d35bad13e90cb2fb9d3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0004--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0a50f3229ee1922709e6575fb9ad016225a206e1562d1754cfae0b0ae01fe81c
+size 1835940
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0005--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0005--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..f9360348fd2074f61f70e932b4c318c396a4c9c3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0005--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:8c8770566b583f49b925a28a7f6d36d2dd598e66994f374640e9e3f9f1cd851d
+size 2196559
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0008--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0008--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..f95365a95cf2d111164972b015bf754fd76d9705
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0008--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:8ff583309cc2a938a8467de548398e7ff0fad0ec923b4de4a3956f77d56be2a3
+size 3024115
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0014--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0014--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..d2a713689ed454b40a70f268c430be82c4b8697d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0014--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f92f7b59bf3abf65c722552813ecf1af8cd7cae4d2c3f13f146af57862e1e59f
+size 2127992
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0016--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0016--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..4b632ab2f44ce6c975066e5c5d3c292484471cef
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0016--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9651b4d1f1a7d7a946642eae831e47402d7dd44eaf2c6a0b60f169ce39b9c13b
+size 1878250
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0018--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0018--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..bf3641cb6cae06b3b95fafca47e9a9f071af92e4
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0018--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:080f7189f4dcd1afd8d5662788bf50f1454b739c2864556e859b0dcab4e538d0
+size 1462332
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0020--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0020--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..7ea260ce19a585452e160111a8dc64eeef716fe3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0020--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a487f20f1ce02ac98222ff29a207ca1c2fe1e3d0c8b2a925fb940894bedfe061
+size 1743325
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0037--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0037--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..93c07d53613a5c643f3dee79ef114ea1533f097d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0037--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a197c56790ca237c895c64813b9486bc53f9fed58dd18b4acc4437d5010f2d14
+size 2059609
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0038--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0038--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e6b44955d4cddfd89842ae4d756e95007c3dc36e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0038--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:85f36f0ec6c50a58aa54f80d0a62817be7d8d3b0ae39ede061404409bb4d1fdf
+size 2460285
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0039--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0039--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..ae2e06e02094ddb785e5fec57535ad450369f132
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0039--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:26beabb103a579ed0f40dfb1f75bc12752e43ba2530656bd3105864eef6171aa
+size 2183539
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0046--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0046--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..f4948b13152025fe7ab33759ed17bb2b4bcd9c50
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0046--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f1ed277f4826d48abd57b4d78739e4a534b7bee1e3b157bf9f82f89069a5c9c1
+size 2427912
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0054--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0054--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..095477ab9b45c8edd7e7079a8b90c60cc224fe92
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0054--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:20260dbd8287b78fb8c69953187dd21c51c46cdf80a9ea27fbdf31f1b8fbedfa
+size 2337988
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0067--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0067--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5380a3bc10e4bf923f1f9f9ac1bf867e6ce29e63
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0067--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e1aa14d986a165abbfb1b7f2c3f1f71c41a2326f27b888467510070b80669a1f
+size 3645555
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0069--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0069--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..dab244baf0199b76a10d8f921319056a9c7e8b94
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0069--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ac6e19fb6d1a35274a4a32a4a7299aae213bf33b6d588d2e72e924005f5646e0
+size 3152500
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0088--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0088--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..d12e8173041e6305a1fcb7dc7a80f1c0ab45d5d0
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0088--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b542078f58aebc3f94bb0a5f5d347ce9d0f68ffd8560ffadb2c64dfe407b07cf
+size 1790555
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0094--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0094--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..c75d8a86268d904ae04169a42da28691f7458f1d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0094--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6d3f9c136cbaa7ce27dbd282013332a9c3791fd6689e7d950ed576590115b75a
+size 2295161
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0097--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0097--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e314847d5fbdc6de418d0954598300611bead166
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0097--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7823b995ccac9d6e9445af0e99f3d5acd7bcadce3f638ed8679a31eefae52e90
+size 1892252
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0104--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0104--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..bb6fd131d7efd227faa42caf9adc0bef14bf8293
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0104--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:af3d0c60275078d08356f8c7a9b295e7d54b05034a2253720d3caf1fd7475fb5
+size 3578443
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0108--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0108--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..dbba217152293a91237357e183c386ef393dafa7
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0108--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ca61b0530a92f5d192e42228c546c7333820b5a9253b4896bb5699e71dce354d
+size 1721954
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0109--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0109--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..77a3a9805bf80a829d10f6279c17aeb38d79553f
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0109--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:06c7f63451110caa72e693aa6484fb6b482eccf6e51d7e6bf17cd46d9676ef78
+size 1760765
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0125--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0125--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..0053fc75b7bba6aaf9a31c6fa822b6a96cd47c34
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0125--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:61c43b09759ed0219a7f0519612c9c3977ee04cbec1a2d72799d776c7e170b1b
+size 1762696
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0129--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0129--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..7e9576ce8460b536290596d0784d647351106c09
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0129--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9c19a4eb398062dfb79d4793238425ebdccdd69430a14a3936231421b737846c
+size 1871634
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0133--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0133--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b0e81348912f2addf02583794887dadec2a36b9c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0133--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a965d5453773a1f3927f9e00638a3f0ecde929dfdbc461079191391c6f0322d6
+size 3519788
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0148--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0148--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..11a04e191f379f9109e5d913b927db8d55c6e3cf
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0148--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:8e06ab15c51f3613962390d7f936efcae569cad4bcc8ecbda7cedbef34970949
+size 1686527
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0161--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0161--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..efd99ca7cf75e64d52feffb10c565c55aa8cb082
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0161--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:da8af4fe93835a4f884f5891e3c7a1a55857b46a12dd3065345ca2df09770eb5
+size 1740205
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0169--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0169--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..05c00d4169938d23b5b06aa296526b0fd36eb7cb
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0169--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6cd65112047cdfe16d1b92271e1515bf2eeedf224734ed90e1a6d3a542395042
+size 3167993
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0170--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0170--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2269e6ebd23ffbc97769115c243cd17d00e7a871
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0170--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fb11c7359b33679d21d245cab6c66a098d2475f86eb6f968917779b0b1d4e4a4
+size 1486103
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0182--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0182--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..070e3d3d6c9b703e668485410d0aa67fdbd7ea2d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0182--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:88837c28fe7d07e4dbdb9874299e20dec1a05a0a10f03a2fe6e00be8450e85ae
+size 2142037
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0192--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0192--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..a6e8f28cba47d7c0c1d5a88f60a2f44d22e21475
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0192--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4d2343f7e694ed3b36c333f48585fab32351ea67b6c41e47093e12356e60fdee
+size 2671430
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0209--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0209--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..6964717e4ee953f10ab4305c2838449c031c9c7b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--P0209--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ce0c78651e745c0a88bc9fa0238900ca42d5a094e87c04b77039698cdc9ede08
+size 1557684
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0007--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0007--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..820e482149763035f52bdd7290187b609290aac8
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0007--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b49600dc335241de32761b5f68fd5fcea0911fdca80aa712bbacf1cc1b7f4168
+size 2096241
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0026--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0026--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9bdd212ab597160e2451e0027e09066e81afd95e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0026--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0d4a103790a140dbffe076dc4494f441ac72052cb3fbcccb99be0f0175621715
+size 2087779
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0029--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0029--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..6b5e220305abdbd6a1afad3dc990a41841f7ef46
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0029--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:15657534de5330ad5ed094113a38882d70b1c18cd8ebc5b18b1ceb7ed7d67e5f
+size 1928905
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0035--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0035--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2a5e53242cefd4589665e41e2b35c3fd526d60ac
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0035--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cebc9b1c34e207be09346c49daf950c49d00d76b5e6194154d0966a5fe90cef1
+size 1603060
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0040--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0040--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..509e1083eed8cc417e9b16efbf4f2476d7c5237c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0040--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bafd4d01a9bb9b5b6ded3bb84354670f0fc8981c31dc28ecfadbe04343b8d69e
+size 3275408
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0042--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0042--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2f30141c6348cf1c661aa778f280ec08a07bd5d8
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0042--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ba794ea240350a59dfc59f76975e75008a12e85f793e4359963bd9bd662712d3
+size 3557931
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0058--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0058--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..077b445cf0b5b1c2a1595a3ff3b5d96fb15ca002
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0058--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5df265e432f8d60901f10de5ea19eda1a87ee0743881eef1326eecdfaadcc1a9
+size 3503645
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0059--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0059--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b3ca081a68d3520db5bbe8a5ade1f77cef80d572
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0059--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:be8ad427fcf193cf256136ac5250adb267599d91caa806d861f09301708f2845
+size 1888422
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0071--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0071--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e23fbf8eaeba0c00c8c97ebcedd5bc3eab00451f
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0071--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0e0ca78cfc5d8b2dd26f47968e3b2440ec98cfdb268936c4e6c50146f3c1b23a
+size 2070535
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0082--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0082--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..863d6fb3daf57fbe4dd83b832a0a364ebae7a1c3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0082--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:2aadc56bf545c62d42fbfb30da5414f2b71871be6fef639b70e081ebc73b2950
+size 1640311
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0090--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0090--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..454bf8e24434615d646f24b1200a391b7608a3ac
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0090--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3620af12999c541119b276ac5f7c6d5c74cf4df026872c8c4b3b41a3ef6b87e6
+size 3533095
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0095--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0095--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..360d8136d643240924f1a358c3788beb789c796c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0095--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7b47862106ce0192fd62a4ba174cf4a28d72775195e0a40b282cedbd264be0fb
+size 3430855
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0102--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0102--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..4e9531839aff167e6e30c33c283a737424c47b07
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0102--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f8b2a4e091d26ee90acdec4d0bcdde76e0928f738ca92f4f2475195e1073d306
+size 1641861
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0110--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0110--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..ac070819c10e00d3133c6540a4f25add1cd4f607
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0110--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4cd041b7e8200b27a8db9342ca27657125911afeca38f17aa75ed70f0b27b9b7
+size 3565571
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0116--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0116--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..ca530d47404be317610384743aa36427002b287a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0116--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5c9b3c0978266caf6c8779cf75b8e5c6ee87949fa4fa39d7ea80afd4efdc2285
+size 1751870
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0117--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0117--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..4d5055e21fcb04685af92609d7601c433c919782
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0117--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c8d30ba44f2be832570ef37489c1e1fe6478f8f9be8dfcc58a4ef8d35497c502
+size 3551597
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0120--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0120--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2e86a1b570cbae73f8ec084eb66f9073f87bcd81
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0120--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6f034dc1bc2e6228cf444f3ede951382b7c80f67bb6c689f765799addb669c20
+size 3489189
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0121--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0121--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..eda25e3b27bd16af9278da9dcfdbfd9f1b737f25
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0121--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1edc80d723b7658dba8d9d57ed1b0e6673249125e54a5d7a7640cda524d047fe
+size 3715085
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0130--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0130--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8feec8ea9baacb2877748ed3c936696dc5175421
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0130--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c4b05dd65930be2d6bfa6b84a3884ecb84ec85fb8102ce72c2bc83bb0dde8c0a
+size 2091416
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0152--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0152--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2ee154232a47d0b60fb7708432ed425b5b999863
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0152--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:24535da79830022a8884c405cf21d824f3b1e9dca07324754f0832a2e3f873f5
+size 1790802
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0155--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0155--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..992ff4880dcb022f0e34decbfe79a699678bcd2c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0155--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:04671047bf408074506fc0d7946daf4cf1c232170dd57a763f91b79267cf22f8
+size 1708821
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0161--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0161--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9e70d4aedaf5f521b7e8ddff40321d4574d05d7b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0161--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:368560d70508d8e8fa4b975393217a1a328e869778fef312bd20b462545abe4d
+size 3497128
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0163--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0163--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..cfd6962ccb927e289f72fd18bd18f99b46c1f545
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0163--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6f6f20ad22963a697d08680a04d16233f4a752f109a5746a54cc61b7a1984df8
+size 3639829
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0178--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0178--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8fdd92f843a79dde90f6c53102ef8b75b1c598f9
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0178--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:927fe3ebf3c72eeec67f7b6d0df7caef66a6effc948a41d5feb0d386a1e13054
+size 1987920
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0180--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0180--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b2e35ae106d8539238ae5cde634271051c6fc93a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0180--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0e0b541119f7f277c52320f7c18d00e1c00930b6cc8d1b81188f109afe5bc6f8
+size 2372642
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0181--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0181--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..613b0083ffd3dcc37ca743ed3f0fb954ab06dacf
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0181--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c03be805db07d97608dbb88954031168310ac0c492983dabbae73f1d3536f3cd
+size 1439797
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0190--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0190--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..0e4c9c8954b8af9169342178baaab76491c66b9e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0190--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ac2dc390bd555769b2ad0db90dc4807944603341f561366b561a06e40c91ba69
+size 3235501
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0191--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0191--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..93b63efa698a5db9e40649417fbe3dbe877588ee
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0191--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7afe938a8580434e5c63d6a214701c97ccd7eadea692447a3c4e22e26b73bc5d
+size 3565047
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0196--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0196--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..6e81264deb2480430ce640cb57fd5dcb6eb1839e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0196--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:73a7d3e1e42734ae545e05fc91008533ff278d529439b0c5933cfdf5ab1da78c
+size 1606102
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0197--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0197--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..68b2c8e15b68cb2c6f58a7d1be081f920d649794
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0197--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:d45ea5d53e7de36b464859f7cb2d611b613af27516773c59e45516cc5ad8d566
+size 3687766
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0198--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0198--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..380c0ee1fafc33719f03ae97d2d2c18323bee876
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0198--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f454fe1a64eac7dbfc797f83f6b87cb0c064a1cf0bbdf2d22b12785fea32ee1f
+size 1860795
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0203--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0203--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8cab91e786c2f795489e9384f23af1db5726857e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0203--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0c8f62428df91d068a17d818bac7116945f692771f780ec8459ef9bf790a04ed
+size 2144506
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0204--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0204--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..91603dd0f7ccb6bb3753ef7ffc6af1b238dd3643
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0204--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:dd513d2d063be99985e3a14e8e2394c155d3f5a6be06d89ebe4074151f43a47c
+size 3806933
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0206--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0206--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b4ff7f048ee373edf8a5e9aedb0ae785b3ccba3a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0206--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1f6dfcd4dc0cd75e7384ff6038c193275cb95aa4e7696b5f7bfdfc32f217e08c
+size 3825701
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0215--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0215--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..cb017c5cb491e310c218e16c74eae21e5f478a91
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0215--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:92283347b9701fdf1fcdaa17ee3f854e256248aed19df56e8bcf4af12054a0b5
+size 3622343
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0218--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0218--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9feb453fe8c201784dd88687e909d75380aa7d56
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0218--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b5f61a3b8f0a34edd0fe0277c16b9500ad147c14e49ff129b2bce819c478293a
+size 3155001
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0223--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0223--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..0e9718461e303d3fa7ad0a7d90d3a5b3eb6e5575
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0223--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:42535f0821f4d2e2827e2f5c5e92cca745da45ba90a05acefbe746d132c32335
+size 1933375
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0229--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0229--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..a816b7cd0947870b943b7e638c48085d4e24875c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0229--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:add8945403317583071d1e090330cba6a5532e4e8c1919f2c20b31b202c208dd
+size 3918569
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0244--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0244--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5cb3b6856beebdcbc06235cd8af830b31bae4a0a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0244--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:76318735c1b626340a3e03427f83e8545c7dea74b3433389672272473d0ed581
+size 2171589
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0248--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0248--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..ec4372cc81337671e5bf17f5f4e612a96a1fe918
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0248--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:04f8c0db385d509b4e3b4e7ae6172b5e79beb90f37bbc2080b2a0a1f9e8b8bba
+size 3443960
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0249--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0249--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..1a79d896a7f7735caadfe273c689c2037749b788
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0249--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:afefdacc4a1df1f64b9eeb6d4070d052b97909197c88c556f78a49d5017ab9db
+size 3705707
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0273--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0273--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..ba6f78757799276a04890d09ef653ec255c992ac
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0273--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6edeb553e8db853f4ffa1541f5cc96cf613003d02fa0d360fd1c333a6697dc75
+size 2152763
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0278--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0278--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..386814ba0892ab734cd065782e7f93c26201d64e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0278--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b78cdab3ccf5a8844546a509f828baaf6b8a916a3e227f4936e57210ba278cbc
+size 3210868
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0283--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0283--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9e1f3c31bcb7d4680c6a11f3a2336287c73f0fd4
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0283--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a26b215ac6ebc5a9d5b1e5fff265aa3a36b0c7001adca78e422fe64d109212b0
+size 3617445
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0291--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0291--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8150e061507ddc0a54d3b532f43b01d007e854f3
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0291--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:71f83c98a2180c84af3e67a88b7aba093beb4562d457bffad679c97c5d04a669
+size 3500977
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0318--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0318--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..96dac2b254af4c9178c30f03dfcc1fe29be48283
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0318--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:013a421b0b30d6b078c92559fb52e3b0b18a8ad91b86d8a62b0006fd311a42f4
+size 3346090
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0328--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0328--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..90af321ae38fc5ce183dfeae595813faedad4ad1
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0328--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f22240752afe6f1a3bc4b66e8f10912f6ffca47b7691e8c4001d637729fe829a
+size 3717711
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0351--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0351--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..7e9576ce8460b536290596d0784d647351106c09
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0351--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9c19a4eb398062dfb79d4793238425ebdccdd69430a14a3936231421b737846c
+size 1871634
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0358--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0358--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..53fdcd376814b819eafa501e424f118cc6f71ef4
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0358--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:667941157ebfbd4e4ce1978c3088b72e103c93b18ee8c6939ab37c3c4d947cc0
+size 3682932
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0359--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0359--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..71118b5ecb35df5b6198bd4713dd13cf32272939
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0359--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3fdc68c214a0c6062169f0763e109ab5197b961371f615103f7b95d85d129cca
+size 2459201
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0361--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0361--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..1ad50c2e040816139244df7c56982604360c45ed
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0361--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6a9c84a24216aec991ef9b6ced8dfdb988bfff97781eed8528c5cb751d173d54
+size 3644025
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0362--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0362--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..45a37cf271dd8cd4ac5a906d37d04cecbca03a69
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0362--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5acef960e963605532f48d284fa3ba3ea56eec7f2de333b7acf0fe688f8fccd8
+size 3422135
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0363--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0363--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..24e7c1c89cc5797ea6bbb0f2a0a0ffca0a2f676c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0363--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4f663316f5335d38055a08e27dea79f770e49f824ff28e77f83382bc9e3ac6c9
+size 3725109
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0368--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0368--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e5914bb5f5bc2a942ca3b5a65384de65840fc4c8
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0368--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7473f3d454d9c9c7c8c52af2668aff2636e525229442ff9f8de15f8b38a6c4f9
+size 1825700
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0369--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0369--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..a4bacc6eea581f70f28aa949d272ea0ee5f40dae
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0369--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f370af11a4e6fc3abff5b06925f69bbe5ec6ea8e1f54c10aa014958c1dc4581f
+size 1527420
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0372--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0372--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..ef0fc6f2e7aa3e6fe9d2e90e6f06628e98e1ea2c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0372--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6885e732cbf430037f3fbf7b4aea3f0effb0acded9cec034de4ab56947b2e0d8
+size 3538848
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0373--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0373--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2b6294e85146e1876a505850e99e0ff43a1b7024
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0373--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fb32a3421febe3141f3ed604cf3a26c8495aea3a9ab98fbc023fcfff50adb07e
+size 2574354
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0377--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0377--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..40fb4d6f9e06f06ee48dbe8fda48d265b522a23e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0377--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:d048706ae6768031a1704ddce81966b46ab7862fa41d2de1535723d80fa34c84
+size 3432270
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0393--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0393--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..6caf18d3022634293512b5d49f046e158ca563b1
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--T0393--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bb050f4b801df97f4bbfe8fabcd5f7bbde9be44e883a4dcc4cf9097a129c787e
+size 1900532
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0003--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0003--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..dc1875e6063cfb29f413f69227d1a0a85ecb4b95
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0003--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7c8e4452d6ee53862e46f9eb36c99ab45e19504ffc8766d509bd994ead0e473e
+size 1999486
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0007--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0007--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..523f5b9aeef337539ec704ba34ecb7810e9a3c02
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0007--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:664739ab4336cc6457c2cf686101e824d763ab462f693cf78f9abd85ec45de1c
+size 3537915
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0014--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0014--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9d4a00f10331603c0547a35091cc0a1745ac8e05
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0014--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:2d5bb04d84f4d9a34c3948f9807d1882ba3cfd5de914782cd869015c45c42034
+size 3578357
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0017--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0017--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..d6ca5fd91b8b9e98a087d4b95db92fc399465b6f
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0017--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c888076b89193bb5f131cc03fda81025806f4c4f3fa8def86f2ab36c5f0ff273
+size 2403126
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0028--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0028--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8c032f443f3ec2b8564dd6599886ad7677cff63b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0028--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:dc3ae968b7068106d780f62b6cb756f3cceed41155dc423defd61456e1d822bf
+size 2661237
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0030--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0030--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e3d3e74c865cfcede1c40ae95264097cd2d095a0
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0030--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:23ecd558b4111b71d6abb7beb2252d83fd9e9f9ee8274b602392042a446eea99
+size 2271122
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0031--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0031--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5ce4492ecc6b2673d8b2b55ace422bd75c37395c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0031--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fa28ac3ef02f4adb60b11fcb9627bd6d9b621e50568283728d99b4c29c476c96
+size 3627001
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0033--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0033--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..622cf5c76891be4b74895a380eede16fe02dd354
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0033--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c2ebf606dd87ce371e36be82959519f3a1725bdee785c2c072c830038031bb6f
+size 2026276
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0039--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0039--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..d0a7b463bd3e5d80a7758b73c8e5546cecd9d52b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0039--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c4c5f169d449d163d721829815deed32630800037f0a5ead1076704f11b98687
+size 3399914
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0049--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0049--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..18dd498542053d2577fe6129f7436d39ef6f953f
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0049--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b1e0e50bb092bafa6e0036f45178c2b8127117cd275d8ebea81729074ac4481a
+size 2596757
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0058--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0058--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..12b504884e730b7317b82ddf14562eaf6b90ff90
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0058--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:792ee13c2396109bdd4a4f6634c65ca74f69f98ae81381bbca2be8adb68c0d03
+size 3466967
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0064--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0064--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b7da27f81d6a385f3f1c7244bd7a6847bd89bfdc
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0064--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:587d8e54e2fdd44f5acb63aabbf4c57af017b4f88186e966a33bd4ac6bfc3fbb
+size 3583142
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0068--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0068--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..25d227bffd15a21bc562356e45252ec277be6033
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0068--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:31e201921dd057baaf7e40f4f3f816f5a5e0463174ab493caba55ec05bf9265b
+size 1706963
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0082--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0082--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..36d19cb9a154c813a3d58523250a510db320b9ec
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0082--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e60364fa3cb1202e42900a97ea098eaa8e945b962cd80dda088dd22b737374a7
+size 2225089
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0104--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0104--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..1c32d89e76bfb7fd24c55bdc4fa712b2bbf3db1e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0104--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:03af6418e587eed3002b8ec01f77cbd0d5adaa5d64b6e9e5791c3093a5924cb8
+size 2661863
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0105--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0105--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..53f3b456770dcb4d87343de6ed9e79a586b23978
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0105--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:71504c4bbaf7439a057cfd0d23f2506c6de76de871b4f60ca65761c312f9399e
+size 1956095
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0117--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0117--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2337411fdae259efd0b4404f415f17905026bc64
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0117--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7802d9ae1966e01a87f24f1c776c698fcda210f20c95a139b32ef2d44e094790
+size 1890365
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0129--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0129--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e66d7f2b40bcc331a9c1e1980ad5b08cf5f5c7bd
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0129--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e6bdc735879e763bff3a34c3ae3438d91ecbd692b745d22203703886b1079b4e
+size 3888802
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0132--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0132--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e04afc574799c2888ec213625ff614175e5ec94c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0132--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:56bdccf4d1510685778abaaff5370f778a3bc70e223bf6672a4cbb031bd5fd82
+size 2428437
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0133--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0133--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8d339f2b2e80c94523e027424c4024f5a8f6f116
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0133--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:449f010d222892cf35e1420c46e4ee2f8dd09c212998994847d07c84abf49b3b
+size 3332952
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0136--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0136--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..7706e7834e3f3805eeb84eb3f6d6ca990d5f63a5
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0136--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:dc59c6deeede977be16e8084cc4ded426bc43368be977b54c26a44ee1d010065
+size 1735368
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0139--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0139--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..e14931f4daebdc83438c842828a87b3d7a6854c0
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0139--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:d62db853f6c6049bef1ad42a6362dec72519a957e981067eea0c15a792655874
+size 3535427
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0144--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0144--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..0f83a8e6694b1c68987cc66073abe492c0a154ce
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0144--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:72099702bccdc5518376924c8855f53be173f9d50346a98bf61a2e269d86aa88
+size 3471335
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0148--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0148--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2814a77d57381526f3ad4acdc77859251b9aed75
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0148--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:93de6b9839ea71d7848fe189192bcb4b4ebc078e111181b9b9725d53af1bf8d2
+size 1501769
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0154--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0154--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..3dac9a5128db27e76f7679f9ca8fba26fdb06a37
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0154--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b7790af56acfe7d757eaf1bd133dd8a920aa162c1ca988d5d7d5c7f6694aa6d3
+size 3843957
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0156--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0156--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..a7c990ce2cb71f04981558200eaaf0dd71e80015
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0156--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bcda7bef4a9c9b770b4421b338374df8e5c1e16bddefbc0896a76097865acf74
+size 3377332
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0163--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0163--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b6b22e5e8d95a7ce7981dad194db621f3a02bc82
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0163--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9763310ccfb9b874275fa1283241439df8cb1ac7f2672f3c5c38b3c1db427f39
+size 1353384
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0170--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0170--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5337bc574c952eb28ab9b041a5a0973b1f37b67c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0170--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ba05215d0d451acceaa0aadff656772c677b24d16964e5efee1e9da145f138fc
+size 3440128
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0180--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0180--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..c6c5421327faac8d37e552c4ec0ae99587de138d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0180--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6d9d78490a7d4ef6da1a3d79299862f79ec15af9bb205d64d517494e61938c1c
+size 2324941
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0182--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0182--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..31330be323c6bf533fe1aac90022bc733d1a3c18
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0182--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a64e37c790168f024a3abf78ae50364c782aeff193394e66bd3a517dab1040e1
+size 1892388
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0215--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0215--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..52482d748973c38a2581b9e6d6e38aa169cc192a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0215--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cd8146f21aa4709338313766fc32e3ecb0f6204cf5d8c20d39c2b00c7f898102
+size 3619189
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0216--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0216--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..37aeb9afa804c7568313c22eb91194848b4ede4f
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0216--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:69accc4316ddb29896d8b343e2cab8375de238b215b8f0e3406b729995d49413
+size 1626831
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0219--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0219--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..72ddb0ebbb50ea1eecba98385cb67bd33b84b5fb
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0219--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9faa7ada3f4431297c8d7ef11b6199365f8eb2867dae3db31980728b596ae995
+size 2920807
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0220--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0220--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..fdf5ec8420b22d3131b14eccba7c97c70e55b414
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0220--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:2acac7b21ad26186385e6939cef940e3cedc75754ba891dca335dd487effaa5b
+size 1681880
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0223--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0223--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..a3d97e3a0210385cc0589efe6cb1367065fbc26c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0223--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fe595519bbae58e21a6905f4aa340b3317742f2f377629e31c1df0fad6d19596
+size 3315568
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0230--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0230--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..0b793b467e3be7f09e26eca73c21a220072bb24c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0230--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:dec92034d612a88845e9671e53922aab2f2d2435c12970342677ee09413924c1
+size 1558287
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0241--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0241--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b25db6d4200afafaad300b229a50c755cac77b6b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0241--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:48c04142dd84cfd47ca1ac56c95c8f8f57f313dddde13a9e923d5ace082c3d0c
+size 3632169
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0250--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0250--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..589ba291824ef678ce11a81413ef741f55788b23
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0250--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5f9be54f04fa3120925f314d3f59fc65fac8bb250a500e7ec854aa8a899d8693
+size 1705085
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0259--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0259--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..468a48f959c692117ea1b66eb5774c55d7bb7921
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0259--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:482ab83b84a9a26f21d94fcfa6a41d9c9bb0497eadec422719369859b1aef05e
+size 1804133
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0260--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0260--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..9d27a87ea3c192aba918bcc9ffbc55f3ac9d7c2d
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0260--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0d55c4d0439b7f653a86fd6cf62f3bc54a119b5feb0b357266c4bd747bc6ea63
+size 3766622
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0280--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0280--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..6d403fba02e7fd790da3b43fa90fb8034de7bec6
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0280--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f3aa09c24a64f20cfd50412c0d849675dfa4be842338efd32b7fd1b14ea5ba6c
+size 3038092
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0290--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0290--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..d3b9d14fd1c12639a8f93cf3e48ec14cc9a31ecd
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0290--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1f8508abf7cedd9530a0d9041f0c512d8c94541b98a706ac7ceb26ff8d39acb1
+size 3541015
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0299--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0299--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..8f36988ac39b7c4800ec04fc535a2a2763d52cfb
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0299--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:eed8def1bece09e40e99cb6c3a3e15eec58b7469e66ad193982df9e53546e54b
+size 2148920
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0304--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0304--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..c48b76acb8189bfd908a7f7d2bcadb4ec09ee3ef
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0304--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e80841011455ac7c54b7c3b6e00688ada600715e8e1e8399c8d246b51bb5c085
+size 4081100
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0308--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0308--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..951a9d41e6683c98d191eddc0511a8190628e96c
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0308--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:45d8039d12061de8f4514624f578525df15c11655fed3abeed72f6435cf6e31e
+size 2213408
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0319--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0319--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..567fb576a8a0bcc944b848a84d0ed2e5989bc80e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0319--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f215afd9dda29a7fa8ae28a4b6bbee59f8381e022791f04f06ee424424cda51c
+size 2287166
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0321--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0321--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..4dfa06b78d1c0432fb16504bc388adfcc23ed38a
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0321--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3553cd1adeea5581f1d6d3145a3d9e136d3ee67c7c20a49809e491bd052b01df
+size 3803037
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0328--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0328--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..b78e35507689aa08451553216eb80097b85452c2
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0328--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3f4037778f9724d7c03e51ff2d5c5a607f91e66fe61d1ac286ccecf5fb37544c
+size 2132305
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0334--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0334--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..660262fc88cea34adab03a95b4869363c0ce34e5
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0334--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:02bb74036a54f343c93621d3160539d9708660b8648cf71a2e70756f57773707
+size 1799912
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0357--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0357--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..5828df6c61dcd6f4fb96126e23803ab183e4655b
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0357--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5450ac4402c0f3f74c84bdc41d8b689f326742665e963cf96c0d8ee500cdb9be
+size 3345122
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0365--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0365--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..6452629c5e39530aba939ca8ef0ab9e800558b51
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0365--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fcc1ba2b0accc3f0c0ab479293c5ba3c69870a520a72aa9a901519d50d81fc0d
+size 2235946
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0376--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0376--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..d7be9c5c80c7116829b3bff265377922a65ddf7e
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0376--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:249edbbefc0b5160b36351106ed2e07bc1f21959133e89eff8bf823e5a5824c1
+size 1670241
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0385--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0385--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..bc1b871196e12f4239c13cc2a781d5722ed2dce9
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0385--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:de5301850a3d0b99690d573429567714e65dedea2a8aaea44c49375dc1c0ec7a
+size 1321816
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0386--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0386--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..2ab48b5d332f64abb0802b579d9c506a53ca6e47
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0386--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:813bcf23ac40824d99c00774ca3e2fa83166257cc1b2b178c157c177afb9ee84
+size 1644423
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0395--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0395--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..0b5ac4f56d10c623a41c719b9d5ab45ed1174f43
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0395--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:8f78fe8e0481c0a259f30769c7668eb03e0a9aa14423c4c50d3f93c2fb834c13
+size 3769313
diff --git a/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0400--2d_none.png b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0400--2d_none.png
new file mode 100644
index 0000000000000000000000000000000000000000..3c1ab989b0b5f0395e6041851008b550c8110deb
--- /dev/null
+++ b/benchmarks/VGMED/image_folder/SAMed2D_v1/fundus_photography/images/fundus_photography--PALM19--V0400--2d_none.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3f67f3b7f5a3d27cd6d9ab4f94241f105603d983e98b57dcf0d00af5c34477d9
+size 3572567