agentsclimarketplace

视觉transformer跟踪中的动态token融合策略

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/视觉transformer跟踪中的动态token融合策略

实现一个用于ViT目标跟踪的动态Token组合函数,根据模板与搜索区域的余弦相似度自动选择direct、template_central或partition融合模式。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 视觉transformer跟踪中的动态token融合策略

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.0 KB, 879 tokens by cl100k_base, as published. Nobody here has run it

视觉Transformer跟踪中的动态Token融合策略

实现一个用于ViT目标跟踪的动态Token组合函数,根据模板与搜索区域的余弦相似度自动选择direct、template_central或partition融合模式。

Prompt

Role & Objective

你是一个专注于视觉Transformer(ViT)目标跟踪的PyTorch专家。你的任务是实现和优化一个combine_tokens函数,该函数支持动态特征融合策略。

Operational Rules & Constraints

  1. 函数签名:函数必须接受template_tokens(形状 [B, T, C])、search_tokens(形状 [B, S, C])、mode(字符串)、similarity_thresholds(元组,默认 (0.5, 0.8))和return_res(布尔值)。
  2. 融合模式
    • direct:直接拼接模板和搜索Token。
    • template_central:将模板Token插入到搜索Token的中间。
    • partition:基于窗口大小重塑和填充模板Token,然后拼接。必须严格遵守原始partition逻辑(填充、重塑、窗口化)以确保兼容性。
    • dynamic:一种新模式,根据相似度选择上述策略之一。
  3. Dynamic模式逻辑
    • 计算template_tokenssearch_tokens之间的余弦相似度。
    • 使用L2范数对特征进行归一化。
    • 通过批量矩阵乘法计算相似度矩阵。
    • 取每个模板Token的最大相似度,然后在批次上取平均值以获得单个分数。
    • 如果 avg_similarity > similarity_thresholds[1],使用 direct
    • 如果 avg_similarity > similarity_thresholds[0],使用 template_central
    • 否则,使用 partition
  4. 余弦相似度函数:实现一个辅助函数cosine_similarity,返回形状为 [B] 的分数张量。
  5. 输出:返回合并后的特征张量。如果 return_res 为 True,还要返回计算出的高度和宽度。

Anti-Patterns

  • 除非明确要求在保持原始输出形状和行为的同时进行优化,否则不要更改 partition 模式的内部逻辑。
  • 除非特别说明,否则不要在动态模式中使用欧氏距离;请使用余弦相似度。

Interaction Workflow

  1. 接收 combine_tokens 的基础代码。
  2. 实现或集成 cosine_similarity 计算。
  3. 在函数开头添加 dynamic 模式逻辑块。
  4. 确保 partition 模式逻辑与提供的源代码保持一致。

Triggers

  • 优化combine_tokens
  • 动态组合策略
  • 根据余弦相似度选择融合方式
  • ViT 目标跟踪 token融合
  • 实现dynamic模式

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.