[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-raoyongming--DynamicViT":3,"tool-raoyongming--DynamicViT":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":78,"owner_email":80,"owner_twitter":78,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":10,"env_os":96,"env_gpu":97,"env_ram":98,"env_deps":99,"category_tags":110,"github_topics":111,"view_count":23,"oss_zip_url":78,"oss_zip_packed_at":78,"status":16,"created_at":116,"updated_at":117,"faqs":118,"releases":159},3266,"raoyongming\u002FDynamicViT","DynamicViT","[NeurIPS 2021] [T-PAMI] DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification","DynamicViT 是一款专为提升视觉模型效率而设计的开源框架，核心功能是通过“动态令牌稀疏化”技术，智能地剪除 Vision Transformer 中冗余的图像块（Token）。它主要解决了传统视觉模型在推理过程中计算量大、速度慢的痛点，能够在几乎不损失精度（下降小于 0.5%）的前提下，显著降低超过 30% 的计算量（FLOPs），并将处理吞吐量提升 40% 以上。\n\n该工具特别适合从事计算机视觉研究的学者、需要部署高效模型的算法工程师以及关注推理成本的开发者使用。其独特的技术亮点在于“动态”与“渐进式”机制：不同于静态剪枝，DynamicViT 能根据每张输入图片的具体内容，实时判断并逐步剔除不重要的信息区域，从而实现真正的按需计算。此外，该项目已扩展支持 ConvNeXt、Swin Transformer 等多种主流架构，并涵盖目标检测与语义分割等任务，提供了丰富的预训练模型供社区直接调用或二次开发，是平衡模型性能与推理速度的优秀选择。","# Efficient Vision Transformers and CNNs with Dynamic Spatial Sparsification\n\nThis repository contains PyTorch implementation for DynamicViT (NeurIPS 2021).\n\n**DynamicViT** is a dynamic token sparsification framework to prune redundant tokens in vision transformers progressively and dynamically based on the input. Our method can reduces over **30%** FLOPs and improves the throughput by over **40%** while the drop of accuracy is within **0.5%** for various vision transformers.\n\n[[Project Page]](https:\u002F\u002Fdynamicvit.ivg-research.xyz\u002F) [[arXiv (NeurIPS 2021)]](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.02034)\n\n### 🔥Updates\n\nWe extend our method to more **network architectures** (i.e., ConvNeXt and Swin Transformers) and more **tasks** (i.e., object detection and semantic segmentation) with an improved ***dynamic spatial sparsification*** framework. Please refer to the extended version of our paper for details. The extended version has been accepted by T-PAMI. \n\n[[arXiv (T-PAMI, Journal Version)]](https:\u002F\u002Farxiv.org\u002Fabs\u002F2207.01580)\n\n### Image Examples\n\n![intro](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_readme_2e3b8aad84ed.gif)\n\n---\n\n### Video Examples\n\n![result1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_readme_4bef79c41b00.gif)\n\n\n## Model Zoo\n\nWe provide our DynamicViT models pretrained on ImageNet:\n| name | model | rho | acc@1 | acc@5 | FLOPs | url |\n| --- | --- | --- | --- | --- | --- | --- |\n| DynamicViT-DeiT-256\u002F0.7 | ```deit-256``` | 0.7 | 76.53 | 93.12 | 1.3G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fpdTNRZtGOW25UwOadj1iUdjqmu88WkO\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fb0e1ff6af1004039855e\u002F?dl=1) |\n| DynamicViT-DeiT-S\u002F0.7 | ```deit-s``` | 0.7 | 79.32 | 94.68 | 2.9G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1H5kHHagdqo4emk9CgjfA7DA62XJr8Yc1\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F698896dfbcea430b9591\u002F?dl=1)|\n| DynamicViT-DeiT-B\u002F0.7 | ```deit-b``` | 0.7 | 81.43 | 95.46 | 11.4G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1J9PCPiOSHmzRiWw370GDYJPEZ8r4uU3M\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F660f27ddb6b945a797a8\u002F?dl=1)|\n| DynamicViT-LVViT-S\u002F0.5 | ```lvvit-s``` | 0.5 | 81.97 | 95.76 | 3.7G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1kPe3MhtYHNdG7natrU20xcAqodO6-Z58\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F635cb172312749e39cf2\u002F?dl=1) |\n| DynamicViT-LVViT-S\u002F0.7 | ```lvvit-s``` | 0.7 | 83.08 | 96.25 | 4.6G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1dNloEsuEiTi592SdM_ELC36kOJ7aaF-3\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fd732a3511dd64db598e1\u002F?dl=1)|\n| DynamicViT-LVViT-M\u002F0.7 | ```lvvit-m``` | 0.7 | 83.82 | 96.58 | 8.5G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1dNab1B5ZOTVNpnpO6H1TsXKFM8BAlA3I\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fb8d1efdfc41d4777903e\u002F?dl=1) |\n\n---\n\n**🔥Updates:** We provide our DynamicCNN and DynamicSwin models pretrained on ImageNet:\n\n| name              | model            | rho  | acc@1 | acc@5 | FLOPs | url                                                          |\n| ----------------- | ---------------- | ---- | ----- | ----- | ----- | ------------------------------------------------------------ |\n| DynamicCNN-T\u002F0.7  | ```convnext-t``` | 0.7  | 81.59 | 95.72 | 3.6G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1Jdp5Xi5E3teBm6zfXqAE681XiszrwqCe\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F95b2daf7593a42f48baa\u002F?dl=1) |\n| DynamicCNN-T\u002F0.9  | ```convnext-t``` | 0.9  | 82.06 | 95.89 | 3.9G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1AHh4kQ_zecKhDzm4bvcZxdl0SoJA3K4Q\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F030c6b8268104c16a666\u002F?dl=1) |\n| DynamicCNN-S\u002F0.7  | ```convnext-s``` | 0.7  | 82.57 | 96.29 | 5.8G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F155I0ixZzLFLn9xqZtQML5lXt0QWiQaak\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F293972cc7d8c4adaac23\u002F?dl=1) |\n| DynamicCNN-S\u002F0.9  | ```convnext-s``` | 0.9  | 83.12 | 96.42 | 6.8G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1xFvhSXua2w2m1tr3WFA_d8MH3wEGgRhN\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F64c4ed5ab02d45998bf6\u002F?dl=1) |\n| DynamicCNN-B\u002F0.7  | ```convnext-b``` | 0.7  | 83.45 | 96.56 | 10.2G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1epwmGKOEfqjU-WITgrB9VXTWhCu6pcgG\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F1e3a861f272142c38bbc\u002F?dl=1) |\n| DynamicCNN-B\u002F0.9  | ```convnext-b``` | 0.9  | 83.96 | 96.76 | 11.9G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1lQLXnxETK6hpsx2Tcv3q1HtRjLI21epl\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F9b4c8df7b30d410bba75\u002F?dl=1) |\n| DynamicSwin-T\u002F0.7 | ```swin-t```     | 0.7  | 80.91 | 95.42 | 4.0G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1BFlCvXedgttyj8n9smcNphE7NLOy99ig\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F6a3d0de592f04d77a2fa\u002F?dl=1) |\n| DynamicSwin-S\u002F0.7 | ```swin-s```     | 0.7  | 83.21 | 96.33 | 6.9G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1gveNkt5aCzjb5CX_DaGq_XJRvvxruxmy\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F86b58132f354495590d0\u002F?dl=1) |\n| DynamicSwin-B\u002F0.7 | ```swin-b```     | 0.7  | 83.43 | 96.45 | 12.1G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1sJctKZxdIH0zHwTekWmmCns_1AOeFzeN\u002Fview?usp=sharing) \u002F [Tsinghua Cloud](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fea260248adc040929970\u002F?dl=1) |\n\n## Usage\n\n### Requirements\n\n- torch>=1.8.0\n- torchvision>=0.9.0\n- timm==0.3.2\n- tensorboardX\n- six\n- fvcore\n\n**Data preparation**: download and extract ImageNet images from http:\u002F\u002Fimage-net.org\u002F. The directory structure should be\n\n```\n│ILSVRC2012\u002F\n├──train\u002F\n│  ├── n01440764\n│  │   ├── n01440764_10026.JPEG\n│  │   ├── n01440764_10027.JPEG\n│  │   ├── ......\n│  ├── ......\n├──val\u002F\n│  ├── n01440764\n│  │   ├── ILSVRC2012_val_00000293.JPEG\n│  │   ├── ILSVRC2012_val_00002138.JPEG\n│  │   ├── ......\n│  ├── ......\n```\n\n**Model preparation**: download pre-trained models if necessary:\n\n| model | url | model | url |\n| --- | --- | --- | --- |\n| DeiT-Small | [link](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fdeit\u002Fdeit_small_patch16_224-cd65a155.pth) | LVViT-S | [link](https:\u002F\u002Fgithub.com\u002FzihangJiang\u002FTokenLabeling\u002Freleases\u002Fdownload\u002F1.0\u002Flvvit_s-26M-224-83.3.pth.tar) |\n| DeiT-Base | [link](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fdeit\u002Fdeit_base_patch16_224-b5f2ef4d.pth) | LVViT-M | [link](https:\u002F\u002Fgithub.com\u002FzihangJiang\u002FTokenLabeling\u002Freleases\u002Fdownload\u002F1.0\u002Flvvit_m-56M-224-84.0.pth.tar) |\n| ConvNeXt-T | [link](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fconvnext\u002Fconvnext_tiny_1k_224_ema.pth) | Swin-T | [link](https:\u002F\u002Fgithub.com\u002FSwinTransformer\u002Fstorage\u002Freleases\u002Fdownload\u002Fv1.0.0\u002Fswin_tiny_patch4_window7_224.pth) |\n| ConvNeXt-S | [link](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fconvnext\u002Fconvnext_small_1k_224_ema.pth) | Swin-S | [link](https:\u002F\u002Fgithub.com\u002FSwinTransformer\u002Fstorage\u002Freleases\u002Fdownload\u002Fv1.0.0\u002Fswin_small_patch4_window7_224.pth) |\n| ConvNeXt-B | [link](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fconvnext\u002Fconvnext_base_1k_224_ema.pth) | Swin-B | [link](https:\u002F\u002Fgithub.com\u002FSwinTransformer\u002Fstorage\u002Freleases\u002Fdownload\u002Fv1.0.0\u002Fswin_base_patch4_window7_224.pth) |\n\n\n### Demo\n\nYou can try DynamicViT on Colab [![][colab]][colab-dynamicvit]. Thank [@dirtycomputer](https:\u002F\u002Fgithub.com\u002Fdirtycomputer) for the contribution.  \n\n[colab]: \u003Chttps:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg>\n[colab-dynamicvit]: \u003Chttps:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fraoyongming\u002FDynamicViT\u002Fblob\u002Fmaster\u002Fcolab_demo.ipynb>\n\n\nWe also provide a [Jupyter notebook](https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fblob\u002Fmaster\u002Fviz_example.ipynb) where you can run the visualization of DynamicViT.\n\nTo run the demo, you need to install ```matplotlib```.\n\n![demo](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_readme_decbbb00e277.png)\n\n### Evaluation\n\nTo evaluate a pre-trained DynamicViT model on the ImageNet validation set with a single GPU, run:\n\n```\npython infer.py --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --model model_name \\\n--model_path \u002Fpath\u002Fto\u002Fmodel --base_rate 0.7 \n```\n\n\n### Training\n\nTo train Dynamic Spatial Sparsification models on ImageNet, run:\n\n(You can train models with different keeping ratio by adjusting ```base_rate```. )\n\n**DeiT-S**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_deit-s --model deit-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5\n```\n\n**DeiT-B**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_deit-b --model deit-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5 --drop_path 0.2 --ratio_weight 5.0\n```\n\n**LV-ViT-S**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_lvvit-s --model lvvit-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5\n```\n\n**LV-ViT-M**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_lvvit-m --model lvvit-m --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5\n```\n\nDynamicViT can also achieve comparable performance with only 15 epochs training (around 0.1% lower accuracy compared to 30 epochs).\n\n**ConvNeXt-T**\n\nTrain on 8 GPUs: \n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_conv-t --model convnext-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\nTrain on 4 8-GPU nodes:\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_conv-t --model convnext-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**ConvNeXt-S**\n\nTrain on 8 GPUs: \n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_conv-s --model convnext-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\nTrain on 4 8-GPU nodes:\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_conv-s --model convnext-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**ConvNeXt-B**\n\nTrain on 8 GPUs: \n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_conv-b --model convnext-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 4 --lr_scale 0.2\n```\n\nTrain on 4 8-GPU nodes:\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_conv-b --model convnext-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 1 --lr_scale 0.2\n```\n\n**Swin-T**\n\nTrain on 8 GPUs:\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_swin-t --model swin-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\nTrain on 4 8-GPU nodes:\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_swin-t --model swin-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**Swin-S**\n\nTrain on 8 GPUs: \n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_swin-s --model swin-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\nTrain on 4 8-GPU nodes:\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_swin-s --model swin-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**Swin-B**\n\nTrain on 8 GPUs: \n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_swin-b --model swin-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 4 --lr_scale 0.2\n```\n\nTrain on 4 8-GPU nodes:\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_swin-b --model swin-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 1 --lr_scale 0.2\n```\n\n## License\n\nMIT License\n\n## Acknowledgements\n\nOur code is based on [pytorch-image-models](https:\u002F\u002Fgithub.com\u002Frwightman\u002Fpytorch-image-models), [DeiT](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fdeit), [LV-ViT](https:\u002F\u002Fgithub.com\u002FzihangJiang\u002FTokenLabeling), [ConvNeXt](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002FConvNeXt) and [Swin-Transformer](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FSwin-Transformer).\n\n## Citation\nIf you find our work useful in your research, please consider citing:\n```\n@inproceedings{rao2021dynamicvit,\n  title={DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification},\n  author={Rao, Yongming and Zhao, Wenliang and Liu, Benlin and Lu, Jiwen and Zhou, Jie and Hsieh, Cho-Jui},\n  booktitle = {Advances in Neural Information Processing Systems (NeurIPS)},\n  year = {2021}\n}\n```\n\n```\n@article{rao2022dynamicvit,\n  title={Dynamic Spatial Sparsification for Efficient Vision Transformers and Convolutional Neural Networks},\n  author={Rao, Yongming and Liu, Zuyan and Zhao, Wenliang and Zhou, Jie and Lu, Jiwen},\n  journal={arXiv preprint arXiv:2207.01580},\n  year={2022}\n```\n","# 基于动态空间稀疏化的高效视觉Transformer和CNN\n\n本仓库包含DynamicViT（NeurIPS 2021）的PyTorch实现。\n\n**DynamicViT** 是一种动态标记稀疏化框架，能够根据输入逐步且动态地剪枝视觉Transformer中的冗余标记。我们的方法可将FLOPs降低超过 **30%**，并将吞吐量提升超过 **40%**，同时各类视觉Transformer的精度下降幅度不超过 **0.5%**。\n\n[[项目页面]](https:\u002F\u002Fdynamicvit.ivg-research.xyz\u002F) [[arXiv (NeurIPS 2021)]](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.02034)\n\n### 🔥更新\n\n我们已将该方法扩展至更多 **网络架构**（如ConvNeXt和Swin Transformer）以及更多 **任务**（如目标检测和语义分割），并引入了改进的 ***动态空间稀疏化*** 框架。详情请参阅论文的扩展版本，该版本已被T-PAMI接收。\n\n[[arXiv (T-PAMI, 期刊版)]](https:\u002F\u002Farxiv.org\u002Fabs\u002F2207.01580)\n\n### 图像示例\n\n![intro](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_readme_2e3b8aad84ed.gif)\n\n---\n\n### 视频示例\n\n![result1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_readme_4bef79c41b00.gif)\n\n\n## 模型库\n\n我们提供了在ImageNet上预训练的DynamicViT模型：\n\n| 名称 | 模型 | rho | 精度@1 | 精度@5 | FLOPs | 下载链接 |\n| --- | --- | --- | --- | --- | --- | --- |\n| DynamicViT-DeiT-256\u002F0.7 | ```deit-256``` | 0.7 | 76.53 | 93.12 | 1.3G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fpdTNRZtGOW25UwOadj1iUdjqmu88WkO\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fb0e1ff6af1004039855e\u002F?dl=1) |\n| DynamicViT-DeiT-S\u002F0.7 | ```deit-s``` | 0.7 | 79.32 | 94.68 | 2.9G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1H5kHHagdqo4emk9CgjfA7DA62XJr8Yc1\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F698896dfbcea430b9591\u002F?dl=1)|\n| DynamicViT-DeiT-B\u002F0.7 | ```deit-b``` | 0.7 | 81.43 | 95.46 | 11.4G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1J9PCPiOSHmzRiWw370GDYJPEZ8r4uU3M\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F660f27ddb6b945a797a8\u002F?dl=1)|\n| DynamicViT-LVViT-S\u002F0.5 | ```lvvit-s``` | 0.5 | 81.97 | 95.76 | 3.7G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1kPe3MhtYHNdG7natrU20xcAqodO6-Z58\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F635cb172312749e39cf2\u002F?dl=1) |\n| DynamicViT-LVViT-S\u002F0.7 | ```lvvit-s``` | 0.7 | 83.08 | 96.25 | 4.6G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1dNloEsuEiTi592SdM_ELC36kOJ7aaF-3\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fd732a3511dd64db598e1\u002F?dl=1)|\n| DynamicViT-LVViT-M\u002F0.7 | ```lvvit-m``` | 0.7 | 83.82 | 96.58 | 8.5G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1dNab1B5ZOTVNpnpO6H1TsXKFM8BAlA3I\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fb8d1efdfc41d4777903e\u002F?dl=1) |\n\n---\n\n**🔥更新：** 我们还提供了在ImageNet上预训练的DynamicCNN和DynamicSwin模型：\n\n| 名称              | 模型            | rho  | 精度@1 | 精度@5 | FLOPs | 下载链接                                                          |\n| ----------------- | ---------------- | ---- | ----- | ----- | ----- | ------------------------------------------------------------ |\n| DynamicCNN-T\u002F0.7  | ```convnext-t``` | 0.7  | 81.59 | 95.72 | 3.6G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1Jdp5Xi5E3teBm6zfXqAE681XiszrwqCe\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F95b2daf7593a42f48baa\u002F?dl=1) |\n| DynamicCNN-T\u002F0.9  | ```convnext-t``` | 0.9  | 82.06 | 95.89 | 3.9G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1AHh4kQ_zecKhDzm4bvcZxdl0SoJA3K4Q\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F030c6b8268104c16a666\u002F?dl=1) |\n| DynamicCNN-S\u002F0.7  | ```convnext-s``` | 0.7  | 82.57 | 96.29 | 5.8G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F155I0ixZzLFLn9xqZtQML5lXt0QWiQaak\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F293972cc7d8c4adaac23\u002F?dl=1) |\n| DynamicCNN-S\u002F0.9  | ```convnext-s``` | 0.9  | 83.12 | 96.42 | 6.8G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1xFvhSXua2w2m1tr3WFA_d8MH3wEGgRhN\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F64c4ed5ab02d45998bf6\u002F?dl=1) |\n| DynamicCNN-B\u002F0.7  | ```convnext-b``` | 0.7  | 83.45 | 96.56 | 10.2G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1epwmGKOEfqjU-WITgrB9VXTWhCu6pcgG\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F1e3a861f272142c38bbc\u002F?dl=1) |\n| DynamicCNN-B\u002F0.9  | ```convnext-b``` | 0.9  | 83.96 | 96.76 | 11.9G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1lQLXnxETK6hpsx2Tcv3q1HtRjLI21epl\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F9b4c8df7b30d410bba75\u002F?dl=1) |\n| DynamicSwin-T\u002F0.7 | ```swin-t```     | 0.7  | 80.91 | 95.42 | 4.0G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1BFlCvXedgttyj8n9smcNphE7NLOy99ig\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F6a3d0de592f04d77a2fa\u002F?dl=1) |\n| DynamicSwin-S\u002F0.7 | ```swin-s```     | 0.7  | 83.21 | 96.33 | 6.9G  | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1gveNkt5aCzjb5CX_DaGq_XJRvvxruxmy\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F86b58132f354495590d0\u002F?dl=1) |\n| DynamicSwin-B\u002F0.7 | ```swin-b```     | 0.7  | 83.43 | 96.45 | 12.1G | [Google Drive](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1sJctKZxdIH0zHwTekWmmCns_1AOeFzeN\u002Fview?usp=sharing) \u002F [清华大学云](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fea260248adc040929970\u002F?dl=1) |\n\n## 使用方法\n\n### 需求\n\n- torch>=1.8.0\n- torchvision>=0.9.0\n- timm==0.3.2\n- tensorboardX\n- six\n- fvcore\n\n**数据准备**: 从 http:\u002F\u002Fimage-net.org\u002F 下载并解压 ImageNet 图像。目录结构应如下所示：\n\n```\n│ILSVRC2012\u002F\n├──train\u002F\n│  ├── n01440764\n│  │   ├── n01440764_10026.JPEG\n│  │   ├── n01440764_10027.JPEG\n│  │   ├── ......\n│  ├── ......\n├──val\u002F\n│  ├── n01440764\n│  │   ├── ILSVRC2012_val_00000293.JPEG\n│  │   ├── ILSVRC2012_val_00002138.JPEG\n│  │   ├── ......\n│  ├── ......\n```\n\n**模型准备**: 如有需要，请下载预训练模型：\n\n| 模型 | 链接 | 模型 | 链接 |\n| --- | --- | --- | --- |\n| DeiT-Small | [链接](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fdeit\u002Fdeit_small_patch16_224-cd65a155.pth) | LVViT-S | [链接](https:\u002F\u002Fgithub.com\u002FzihangJiang\u002FTokenLabeling\u002Freleases\u002Fdownload\u002F1.0\u002Flvvit_s-26M-224-83.3.pth.tar) |\n| DeiT-Base | [链接](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fdeit\u002Fdeit_base_patch16_224-b5f2ef4d.pth) | LVViT-M | [链接](https:\u002F\u002Fgithub.com\u002FzihangJiang\u002FTokenLabeling\u002Freleases\u002Fdownload\u002F1.0\u002Flvvit_m-56M-224-84.0.pth.tar) |\n| ConvNeXt-T | [链接](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fconvnext\u002Fconvnext_tiny_1k_224_ema.pth) | Swin-T | [链接](https:\u002F\u002Fgithub.com\u002FSwinTransformer\u002Fstorage\u002Freleases\u002Fdownload\u002Fv1.0.0\u002Fswin_tiny_patch4_window7_224.pth) |\n| ConvNeXt-S | [链接](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fconvnext\u002Fconvnext_small_1k_224_ema.pth) | Swin-S | [链接](https:\u002F\u002Fgithub.com\u002FSwinTransformer\u002Fstorage\u002Freleases\u002Fdownload\u002Fv1.0.0\u002Fswin_small_patch4_window7_224.pth) |\n| ConvNeXt-B | [链接](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fconvnext\u002Fconvnext_base_1k_224_ema.pth) | Swin-B | [链接](https:\u002F\u002Fgithub.com\u002FSwinTransformer\u002Fstorage\u002Freleases\u002Fdownload\u002Fv1.0.0\u002Fswin_base_patch4_window7_224.pth) |\n\n\n### 演示\n\n您可以在 Colab 上试用 DynamicViT [![][colab]][colab-dynamicvit]。感谢 [@dirtycomputer](https:\u002F\u002Fgithub.com\u002Fdirtycomputer) 的贡献。  \n\n[colab]: \u003Chttps:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg>\n[colab-dynamicvit]: \u003Chttps:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fraoyongming\u002FDynamicViT\u002Fblob\u002Fmaster\u002Fcolab_demo.ipynb>\n\n\n我们还提供了一个 [Jupyter 笔记本](https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fblob\u002Fmaster\u002Fviz_example.ipynb)，您可以在其中运行 DynamicViT 的可视化效果。\n\n要运行演示，您需要安装 ```matplotlib```。\n\n![demo](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_readme_decbbb00e277.png)\n\n### 评估\n\n要在单个 GPU 上使用 ImageNet 验证集评估预训练的 DynamicViT 模型，请运行以下命令：\n\n```\npython infer.py --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --model model_name \\\n--model_path \u002Fpath\u002Fto\u002Fmodel --base_rate 0.7 \n```\n\n### 训练\n\n要在 ImageNet 上训练动态空间稀疏化模型，请运行以下命令：\n\n（您可以通过调整 ```base_rate``` 来训练不同保留率的模型。）\n\n**DeiT-S**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_deit-s --model deit-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5\n```\n\n**DeiT-B**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_deit-b --model deit-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5 --drop_path 0.2 --ratio_weight 5.0\n```\n\n**LV-ViT-S**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_lvvit-s --model lvvit-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5\n```\n\n**LV-ViT-M**\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamicvit_lvvit-m --model lvvit-m --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 30 --base_rate 0.7 --lr 1e-3 --warmup_epochs 5\n```\n\nDynamicViT 仅需训练 15 个 epoch 也能达到相近的性能（相比 30 个 epoch 的准确率低约 0.1%）。\n\n**ConvNeXt-T**\n\n在 8 张 GPU 上训练：\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_conv-t --model convnext-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\n在 4 个 8-GPU 节点上训练：\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_conv-t --model convnext-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**ConvNeXt-S**\n\n在 8 张 GPU 上训练：\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_conv-s --model convnext-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\n在 4 个 8-GPU 节点上训练：\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_conv-s --model convnext-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**ConvNeXt-B**\n\n在 8 张 GPU 上训练：\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_conv-b --model convnext-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 4 --lr_scale 0.2\n```\n\n在 4 个 8-GPU 节点上训练：\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_conv-b --model convnext-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 1 --lr_scale 0.2\n```\n\n**Swin-T**\n\n在 8 张 GPU 上训练：\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_swin-t --model swin-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\n在 4 个 8-GPU 节点上训练：\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_swin-t --model swin-t --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**Swin-S**\n\n在 8 张 GPU 上训练：\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_swin-s --model swin-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 4 --lr_scale 0.2\n```\n\n在 4 个 8-GPU 节点上训练：\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_swin-s --model swin-s --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.2 --update_freq 1 --lr_scale 0.2\n```\n\n**Swin-B**\n\n在 8 张 GPU 上训练：\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --output_dir logs\u002Fdynamic_swin-b --model swin-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base_rate 0.7 --lr 4e-3 --drop_path 0.5 --update_freq 4 --lr_scale 0.2\n```\n\n在 4 个 8-GPU 节点上训练：\n\n```\npython run_with_submitit.py --nodes 4 --ngpus 8 --output_dir logs\u002Fdynamic_swin-b --model swin-b --input_size 224 --batch_size 128 --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --epochs 120 --base rate 0.7 --lr 4e-3 --drop_path 0.5 --update freq 1 --lr scale 0.2\n```\n\n## 许可证\n\nMIT 许可证\n\n## 致谢\n\n我们的代码基于 [pytorch-image-models](https:\u002F\u002Fgithub.com\u002Frwightman\u002Fpytorch-image-models)、[DeiT](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fdeit)、[LV-ViT](https:\u002F\u002Fgithub.com\u002FzihangJiang\u002FTokenLabeling)、[ConvNeXt](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002FConvNeXt) 和 [Swin-Transformer](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FSwin-Transformer)。\n\n## 引用\n如果您在研究中使用了我们的工作，请考虑引用以下文献：\n```\n@inproceedings{rao2021dynamicvit,\n  title={DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification},\n  author={Rao, Yongming and Zhao, Wenliang and Liu, Benlin and Lu, Jiwen and Zhou, Jie and Hsieh, Cho-Jui},\n  booktitle = {Advances in Neural Information Processing Systems (NeurIPS)},\n  year = {2021}\n}\n```\n\n```\n@article{rao2022dynamicvit,\n  title={Dynamic Spatial Sparsification for Efficient Vision Transformers and Convolutional Neural Networks},\n  author={Rao, Yongming and Liu, Zuyan and Zhao, Wenliang and Zhou, Jie and Lu, Jiwen},\n  journal={arXiv preprint arXiv:2207.01580},\n  year={2022}\n```","# DynamicViT 快速上手指南\n\nDynamicViT 是一个基于动态空间稀疏化（Dynamic Spatial Sparsification）的框架，旨在逐步且动态地剪枝视觉 Transformer（ViT）和 CNN 中的冗余 Token。该方法可在精度损失小于 0.5% 的前提下，降低超过 30% 的 FLOPs 并提升 40% 以上的吞吐量。支持 DeiT、LV-ViT、ConvNeXt 和 Swin Transformer 等多种架构。\n\n## 环境准备\n\n### 系统要求\n- Python 3.x\n- GPU 环境（推荐用于训练和推理）\n\n### 前置依赖\n请确保安装以下核心依赖库：\n```bash\ntorch>=1.8.0\ntorchvision>=0.9.0\ntimm==0.3.2\ntensorboardX\nsix\nfvcore\nmatplotlib (仅用于可视化 Demo)\n```\n\n## 安装步骤\n\n1. **克隆仓库**\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT.git\n   cd DynamicViT\n   ```\n\n2. **安装 Python 依赖**\n   建议使用国内镜像源加速安装：\n   ```bash\n   pip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n   ```\n   *注：若仓库无 requirements.txt 文件，请手动执行：*\n   ```bash\n   pip install torch torchvision timm==0.3.2 tensorboardX six fvcore matplotlib -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n   ```\n\n3. **数据准备**\n   下载 ImageNet 数据集 (ILSVRC2012)，目录结构需如下：\n   ```text\n   ILSVRC2012\u002F\n   ├── train\u002F\n   │   ├── n01440764\u002F\n   │   └── ...\n   └── val\u002F\n       ├── n01440764\u002F\n       └── ...\n   ```\n\n4. **模型准备（可选）**\n   如需使用预训练模型，可从下表下载。国内用户推荐使用 **清华云盘** 链接：\n\n   | 模型架构 | 推荐下载源 (清华云盘) |\n   | :--- | :--- |\n   | DynamicViT-DeiT 系列 | [点击下载](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002Fb0e1ff6af1004039855e\u002F?dl=1) |\n   | DynamicCNN (ConvNeXt) | [点击下载](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F95b2daf7593a42f48baa\u002F?dl=1) |\n   | DynamicSwin | [点击下载](https:\u002F\u002Fcloud.tsinghua.edu.cn\u002Ff\u002F6a3d0de592f04d77a2fa\u002F?dl=1) |\n\n   *完整模型列表及对应保持率 (rho) 请参考项目原文档 Model Zoo 部分。*\n\n## 基本使用\n\n### 1. 快速体验 (Demo)\n项目提供了 Colab 在线演示和本地 Jupyter Notebook 可视化示例。\n\n- **在线运行**: 点击 [Colab Demo](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fraoyongming\u002FDynamicViT\u002Fblob\u002Fmaster\u002Fcolab_demo.ipynb) 直接在浏览器中体验。\n- **本地可视化**: 运行以下命令查看 Token 剪枝效果（需安装 `matplotlib`）：\n  ```bash\n  jupyter notebook viz_example.ipynb\n  ```\n\n### 2. 模型推理 (Evaluation)\n使用单张 GPU 在 ImageNet 验证集上评估预训练模型。以下以 `deit-s` 模型为例，设置保留率 (`base_rate`) 为 0.7：\n\n```bash\npython infer.py --data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F --model deit-s \\\n--model_path \u002Fpath\u002Fto\u002Fpretrained_model.pth --base_rate 0.7\n```\n*请将 `\u002Fpath\u002Fto\u002F...` 替换为实际的数据集路径和模型权重文件路径。*\n\n### 3. 模型训练 (Training)\n基于 ImageNet 训练动态稀疏化模型。以下以 **DeiT-Small** 为例，在 8 卡环境下训练 30 个 epoch：\n\n```bash\npython -m torch.distributed.launch --nproc_per_node=8 --use_env main.py \\\n--output_dir logs\u002Fdynamicvit_deit-s \\\n--model deit-s \\\n--input_size 224 \\\n--batch_size 128 \\\n--data_path \u002Fpath\u002Fto\u002FILSVRC2012\u002F \\\n--epochs 30 \\\n--base_rate 0.7 \\\n--lr 1e-3 \\\n--warmup_epochs 5\n```\n\n**提示**：\n- 可通过调整 `--base_rate` 参数控制 Token 保留比例（如 0.5, 0.7, 0.9）。\n- 对于 ConvNeXt 或 Swin 等较大模型，建议参考原文档调整 `drop_path`、`update_freq` 及学习率策略。","某自动驾驶初创团队正在开发车载实时路况分析系统，需要在算力有限的边缘设备上运行高精度的视觉 Transformer 模型以识别行人和障碍物。\n\n### 没有 DynamicViT 时\n- **推理延迟过高**：标准的 DeiT 或 Swin Transformer 模型计算量巨大，导致单帧图像处理时间超过 50ms，无法满足车辆高速行驶时的实时响应需求。\n- **硬件资源浪费**：模型对所有图像区域（包括天空、路面等无信息背景）进行同等密度的计算，大量浮点运算（FLOPs）被消耗在冗余的 Token 上。\n- **部署成本高昂**：为了维持必要的帧率，团队被迫升级更昂贵的车载 GPU 芯片，显著增加了整车的 BOM（物料清单）成本。\n- **能耗与发热严重**：持续的高负荷运算导致设备功耗激增，引发散热问题，影响系统在封闭车机环境下的稳定性。\n\n### 使用 DynamicViT 后\n- **吞吐量大幅提升**：DynamicViT 根据输入图像内容动态剪枝冗余 Token，将系统吞吐量提升了 40% 以上，成功实现了低延迟的实时检测。\n- **计算效率优化**：通过渐进式稀疏化策略，模型自动跳过背景区域的计算，减少了超过 30% 的 FLOPs，让每一分算力都用在关键目标上。\n- **低成本硬件适配**：在精度损失控制在 0.5% 以内的前提下，原有中端芯片即可流畅运行大模型，直接降低了硬件采购成本。\n- **能效比显著改善**：计算负载的动态调整降低了整体功耗和设备发热量，延长了车载系统的持续工作时间并提升了稳定性。\n\nDynamicViT 通过“按需计算”的智能机制，在几乎不牺牲精度的情况下，成功解决了视觉 Transformer 在边缘端落地难、成本高、速度慢的核心痛点。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fraoyongming_DynamicViT_2576603c.png","raoyongming","Yongming Rao","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fraoyongming_8996ae72.jpg",null,"Tencent","raoyongming95@gmail.com","https:\u002F\u002Fraoyongming.github.io\u002F","https:\u002F\u002Fgithub.com\u002Fraoyongming",[84,88],{"name":85,"color":86,"percentage":87},"Jupyter Notebook","#DA5B0B",72.7,{"name":89,"color":90,"percentage":91},"Python","#3572A5",27.3,654,80,"2026-04-01T07:29:52","MIT","Linux","必需 NVIDIA GPU。训练部分模型（如 ConvNeXt, Swin）推荐使用多卡环境（示例命令使用 8 张 GPU 或 4 个 8 卡节点）。具体显存大小未说明，但需足以支撑 ImageNet 训练批次（batch_size 128）。CUDA 版本未明确说明，需匹配安装的 PyTorch 版本。","未说明",{"notes":100,"python":101,"dependencies":102},"1. 数据集：需手动下载并准备 ImageNet (ILSVRC2012) 数据集，目录结构需符合特定格式。\n2. 分布式训练：官方提供的训练命令主要基于 torch.distributed.launch (多 GPU) 和 submitit (多节点)，主要在 Linux 环境下验证。\n3. 预训练模型：提供 DeiT, LVViT, ConvNeXt, Swin 等多种架构的预训练权重，需单独下载。\n4. 演示：提供 Colab 演示链接及本地 Jupyter Notebook 可视化示例。","未说明 (需满足 torch>=1.8.0 要求，通常建议 Python 3.7+)",[103,104,105,106,107,108,109],"torch>=1.8.0","torchvision>=0.9.0","timm==0.3.2","tensorboardX","six","fvcore","matplotlib",[13,14,26],[112,113,114,115],"vision-transformers","image-classification","computer-vision","deep-learning","2026-03-27T02:49:30.150509","2026-04-06T05:17:22.546295",[119,124,129,134,139,144,149,154],{"id":120,"question_zh":121,"answer_zh":122,"source_url":123},15010,"为什么无法复现 DynamicViT-B\u002F0.7 的论文精度（报告为 81.3%，实际只有 80.8%）？","当应用较小的稀疏化比例（\u003C=0.7）时，ViT-B 模型的训练可能不稳定。如果训练损失变为 NaN，建议从上一次的检查点恢复训练或从头重新训练。NaN 在大批次大小下较少发生。您可以尝试通过设置 `args.seed` 更改随机种子并重新训练，或者检查环境是否可以通过使用更大的稀疏化比例（如 0.8 或 0.9）来避免此问题。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F27",{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},15011,"如何在单张 GPU 上训练模型？需要调整哪些超参数？","可以在单张 GPU 上训练，关键是要保持有效批次大小（effective batch size）不变。公式为：单卡批次大小 (batch_size per gpu) × GPU 数量 (num_gpu) × 更新频率 (update_freq) = 常数。例如，如果原命令是多卡训练，单卡训练时需要增大 `update_freq` 参数以补偿 GPU 数量的减少，同时保持总批次大小一致。注意命令行中的 `--batch_size` 指的是每张 GPU 的批次大小。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F41",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},15012,"学习率（Learning Rate）是如何根据批次大小计算的？代码中似乎没有体现论文公式？","学习率是通过命令行手动调整的，遵循线性缩放规则：lr = base_lr * (global_batch_size \u002F reference_batch_size)。例如，ConvNeXt-T 模型在 4x8-GPU 节点上训练（每卡批次 128），学习率设为 4e-3；如果在单节点训练，需调整 `update_frequency` 为 4 以保持有效批次大小相同。对于在单节点以全局批次大小 1024 训练的 DeiT-S 模型，命令行中学习率设为 1e-3。具体命令可在 README.md 中找到。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F23",{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},15013,"推理阶段是如何真正移除被剪枝 token 的连接以加速计算的？","在推理阶段，代码会根据分数直接移除 token。具体实现位于 `models\u002Fdyvit.py` 文件中：训练时使用 Gumbel-Softmax 产生的可导二值策略来消除连接（见第 168 行附近）；而在推理时（`model.eval()` 模式下），代码会根据分数直接移除 token（见第 443 行附近）。计算 FLOPs 时，需传入正确的剪枝比例并将模型设为评估模式。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F35",{"id":140,"question_zh":141,"answer_zh":142,"source_url":143},15014,"为什么 Attention Masking 实现中使用乘法而不是直接将 Mask 部分设为 -inf？","使用乘法（attention score * mask）而不是将 masked tokens 设为 -inf，主要是为了保持整个过程的可导性，从而能够通过梯度更新 prediction module 的参数，实现端到端的 token 稀疏化策略学习。直接设为 -inf 的操作是不可导的，会导致梯度无法回传到 prediction module。虽然训练时所有 token 都参与了 Self-Attention，但该机制是为了让网络学会剪枝策略，最终的加速效果体现在部署\u002F推理阶段。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F3",{"id":145,"question_zh":146,"answer_zh":147,"source_url":148},15015,"在分层结构（如 Swin Transformer 或 ConvNeXt）中，AdaSwinTransformerBlock 里的 x1 和 x2 代表什么？","这是针对分层结构（Swin\u002FConvNeXt）设计的扩展版本功能（参考论文 Eq.13）。由于原始 DynamicViT 框架无法直接处理分层结构，因此新设计了该方法。其中，x1 和 x2 分别表示特征中被选为“快速路径”（fast）和“慢速路径”（slow）的部分。相关代码位于 `models\u002Fdyswin.py` 中。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F28",{"id":150,"question_zh":151,"answer_zh":152,"source_url":153},15016,"如果想迁移到 CIFAR-100 数据集，是否需要修改模型的 nb_classes 参数？","如果您想利用预训练的权重进行分类器微调，建议不要直接修改 `nb_classes` 或其他模型配置。您应该保持 ImageNet 的类别 ID 不变。例如，如果您从原始的 1000 类中选择了 200 类组成新的 CIFAR-100 子集，那么这些类的 ID 应严格对应原始 ImageNet 中的 ID（如第 200 类在原始数据集中 ID 为 199）。直接修改 `nb_classes` 会导致无法正确加载和使用预训练权重。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F39",{"id":155,"question_zh":156,"answer_zh":157,"source_url":158},15017,"如果不设定预定比例且不使用 ratio loss，模型学到的裁剪比例会是什么样？如何防止模型裁剪掉所有 token？","建议在各种情况下都加入 ratio loss 以约束剪枝比例。计算方法可以是对整个 batch 的平均剪枝比例进行约束：先对 batch 内的剪枝比例取平均，再监督其均方误差（MSE），或者设计其他约束方式。如果不加约束，模型可能会倾向于裁剪掉所有 token。即使您的应用场景只关心 batch size=1 的情况，也需要通过 loss 函数来平衡准确率和剪枝率。","https:\u002F\u002Fgithub.com\u002Fraoyongming\u002FDynamicViT\u002Fissues\u002F15",[]]