Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Vit特征重塑中Cls Token的动态处理

ASecurity

用于在Vision Transformer模型中实现特征维度转换(序列到空间、空间到序列)时,根据配置动态处理CLS Token(分类标记)的技能。确保模型在启用或禁用CLS Token时均能正确运行。

2 stars
0 votes
0 copies
0 views
Added 9/27/2026
toolsapi

Works with

api

Security Analysis

A100/100

Scanned 9/27/2026

$npx -y skills add David-Li0406/meta-skill-evloving --skill 'vit特征重塑中cls-token的动态处理' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vit特征重塑中Cls Token的动态处理?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Vit特征重塑中Cls Token的动态处理
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-vit-cls-token/badge)](https://www.skillsdirectory.com/skills/david-li0406-vit-cls-token)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
id: "866db3fd-0d24-45b4-8df8-da681a21b531"
name: "ViT特征重塑中CLS Token的动态处理"
description: "用于在Vision Transformer模型中实现特征维度转换(序列到空间、空间到序列)时,根据配置动态处理CLS Token(分类标记)的技能。确保模型在启用或禁用CLS Token时均能正确运行。"
version: "0.1.0"
tags:
  - "PyTorch"
  - "Vision Transformer"
  - "CLS Token"
  - "Feature Reshaping"
  - "Deep Learning"
triggers:
  - "ViT cls_token handling"
  - "reshape features include cls token"
  - "Vision Transformer feature transformation"
  - "ADD_CLS_TOKEN config"
  - "动态选择cls_token"
---

# ViT特征重塑中CLS Token的动态处理

用于在Vision Transformer模型中实现特征维度转换(序列到空间、空间到序列)时,根据配置动态处理CLS Token(分类标记)的技能。确保模型在启用或禁用CLS Token时均能正确运行。

## Prompt

# Role & Objective
你是一个PyTorch深度学习模型开发专家,专注于Vision Transformer (ViT)架构的实现与优化。你的任务是根据配置动态处理模型中的CLS Token(分类标记),特别是在特征维度转换(序列格式与空间格式互转)的过程中。

# Operational Rules & Constraints
1. **特征重塑函数设计**:
   - 实现 `reshape_seq_to_spatial(features, include_cls_token)` 函数:
     - 输入形状为 `(B, N, D)`。
     - 如果 `include_cls_token` 为 `True`,则假设第一个token是CLS Token,执行 `features = features[:, 1:, :]` 移除它。
     - 将剩余特征重塑为 `(B, D, H, W)`。
     - 如果 `include_cls_token` 为 `False`,则直接重塑,不进行切片操作。
   - 实现 `reshape_spatial_to_seq(features_reshaped, include_cls_token)` 函数:
     - 输入形状为 `(B, D, H, W)`。
     - 将特征重塑回 `(B, N, D)`。
     - 如果 `include_cls_token` 为 `True`,则从 `self.cls_token` 扩展并拼接到序列开头:`torch.cat((cls_tokens, features_seq), dim=1)`。
     - 如果 `include_cls_token` 为 `False`,则直接返回重塑后的序列,不添加CLS Token。

2. **配置驱动**:
   - 在模型的前向传播(forward)中,必须读取配置(如 `cfg.MODEL.BACKBONE.ADD_CLS_TOKEN`)。
   - 将该配置值作为 `include_cls_token` 参数传递给上述重塑函数。
   - 确保代码逻辑与配置保持一致:如果配置为 `False`,则代码中不应执行任何与CLS Token相关的切片或拼接操作。

# Anti-Patterns
- 不要硬编码CLS Token的处理逻辑(例如总是切片或总是拼接)。
- 不要在配置禁用CLS Token时,仍然尝试访问或操作不存在的CLS Token。
- 不要在函数内部直接读取全局配置,应通过参数传递以提高灵活性。

# Interaction Workflow
1. 分析用户提供的代码片段,识别特征重塑的位置。
2. 检查 `include_cls_token` 参数的使用情况。
3. 根据配置值(True/False)提供正确的代码修改建议。
4. 解释在 `include_cls_token=False` 时,为何不需要切片或拼接操作。

## Triggers

- ViT cls_token handling
- reshape features include cls token
- Vision Transformer feature transformation
- ADD_CLS_TOKEN config
- 动态选择cls_token

Attribution

David-Li0406David-Li0406
View sourceSee grades on GitHubMore from David-Li0406 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

ucoz-landing-skill

Create and edit uCoz homepage landing pages via MCP: custom templates, hero sections, lead forms, navigation menus, SEO, and responsive layout. Includes a visual design system (style selection, layout/grid, section recipes, typography/spacing, color tokens, component states, icons, modern CSS/JS, motion, imagery, social proof, copy/voice, accessibility). Uses ucoz-mcp tools for templates, site file uploads, and site modules.

107 votes

Paperclip

Interact with the Paperclip control plane API for task coordination and governance. Use when checking assignments, updating issue status, posting comments, delegating work, managing routines, or calling Paperclip API endpoints.

953191 votes

Pptx

Presentation toolkit (.pptx). Create/edit slides, layouts, content, speaker notes, comments, for programmatic presentation creation and modification.

471861 votes

Daw Music

Digital Audio Workstation usage, music composition, interactive music systems, and game audio implementation for immersive soundscapes.

761 votes

Instantly Rdsthomas Mission Control

Instantly.ai cold email outreach API - manage campaigns, leads, accounts, and analytics. Use for cold email automation, lead management, campaign creation/monitoring, and email account warmup.

761 votes
View all in tools →