[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-OFA-Sys--OFA":3,"tool-OFA-Sys--OFA":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},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,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},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 真正成长为懂上",159636,2,"2026-04-17T23:33:34",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":72,"owner_avatar_url":73,"owner_bio":74,"owner_company":75,"owner_location":75,"owner_email":75,"owner_twitter":75,"owner_website":75,"owner_url":76,"languages":77,"stars":109,"forks":110,"last_commit_at":111,"license":112,"difficulty_score":10,"env_os":113,"env_gpu":114,"env_ram":114,"env_deps":115,"category_tags":121,"github_topics":123,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":135,"updated_at":136,"faqs":137,"releases":166},8972,"OFA-Sys\u002FOFA","OFA","Official repository of OFA (ICML 2022). Paper: OFA: Unifying Architectures, Tasks, and Modalities Through a Simple Sequence-to-Sequence Learning Framework","OFA 是一个强大的多模态预训练模型，旨在通过统一的“序列到序列”学习框架，打破视觉与语言之间的壁垒。它不仅能处理图像描述、视觉问答、图文定位等跨模态任务，还能胜任文本分类、生成以及图像分类等传统单模态任务，甚至支持文生图和中英文 OCR 识别。\n\n过去，开发者往往需要为不同任务训练独立的模型，导致资源浪费且维护复杂。OFA 的出现解决了这一痛点，它将多种架构、任务和模态整合进同一个模型中，用户只需微调或调整提示词（Prompt），即可让模型适应各种下游应用。其核心亮点在于“统一性”：一套权重即可通吃多种场景，且在多项国际基准测试（如 MSCOCO 图像描述）中取得了领先成绩。此外，OFA 原生支持中英文双语，并提供了详细的预训练与微调指南及现成的模型检查点。\n\n这款工具非常适合人工智能研究人员、算法工程师以及希望快速构建多模态应用的开发者使用。无论是需要探索前沿多模态技术的学术团队，还是寻求高效解决方案的企业开发组，都能利用 OFA 简化工作流程，降低研发门槛。项目社区活跃，同时兼容 Hugging Face Transformers 生态，方便大家直接上手体验。","\u003C!---\nCopyright 2022 The OFA-Sys Team. \nAll rights reserved.\nThis source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory.\n-->\n\n\u003Cp align=\"center\">\n    \u003Cbr>\n    \u003Cimg src=\"examples\u002FOFA_logo_tp_path.svg\" width=\"150\" \u002F>\n    \u003Cbr>\n\u003Cp>\n\u003Cbr>\n\n\u003Cp align=\"center\">\n        \u003Ca href=\"modelscope.md\">ModelScope\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"checkpoints.md\">Checkpoints\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"colab.md\">Colab\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fofa-sys\">Demo\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"http:\u002F\u002Farxiv.org\u002Fabs\u002F2202.03052\">Paper \u003C\u002Fa>&nbsp ｜ &nbspBlog\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n    \u003Cbr>\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_a6cac7c5ba3e.gif\" width=\"800\" \u002F>\n    \u003Cbr>\n\u003Cp>\n\n[colab]: \u003Chttps:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg>\n\nOFA is a unified sequence-to-sequence pretrained model (support **English** and **Chinese**) that unifies modalities (i.e., cross-modality, vision, language) and tasks (**finetuning** and **prompt tuning** are supported): image captioning (1st at the [MSCOCO Leaderboard](https:\u002F\u002Fcompetitions.codalab.org\u002Fcompetitions\u002F3221#results)), VQA ([link](https:\u002F\u002Feval.ai\u002Fweb\u002Fchallenges\u002Fchallenge-page\u002F830\u002Fleaderboard\u002F2278)), visual grounding, text-to-image generation, text classification, text generation, image classification, etc. We provide **step-by-step** instructions for pretraining and finetuning and corresponding checkpoints (check official ckpt \\[[EN](checkpoints.md)|[CN](checkpoints_cn.md)\\] or [Hugging Face ckpt](https:\u002F\u002Fhuggingface.co\u002FOFA-Sys)).\n\nWe sincerely welcome contributions to our project. Feel free to contact us or send us issues \u002F PRs!\n\u003Cbr>\u003C\u002Fbr>\n\n\n# Online Demos\nWe provide online demo via Hugging Face Spaces for you to interact with our pretrained and finetuned models. Below are the links to the demos:\n* Image Captioning \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_image-caption_coco_large_en\u002Fsummary)  |  [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Image_Caption)\\]\n* Visual Grounding \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_visual-grounding_refcoco_large_en\u002Fsummary) | [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Visual_Grounding)\\]\n* Visual Question Answering \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_visual-question-answering_pretrain_large_en\u002Fsummary) | [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Visual_Question_Answering)\\]\n* Text-to-Image Generation \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_text-to-image-synthesis_coco_large_en\u002Fsummary) | [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Text2Image_Generation)\\]\n* Generic Interface \\[[Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Generic_Interface)\\]\n* Chinese OCR \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002Fstudios\u002Fdamo\u002Fofa_ocr_pipeline\u002Fsummary)  |  [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-OCR)\\]\n\n\nAlso we provide Colab notebooks for you to better perceive the procedures. Click [here](colab.md) to check them out!\n\u003Cbr>\u003C\u002Fbr>\n\n# Use in Hugging Face Transformers\nWe support the inference of OFA in Hugging Face Transformers. Check the [README](transformers.md) and [Colab Notebook](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1Ho81RBV8jysZ7e0FhsSCk_v938QeDuy3?usp=sharing) for more information. Codes are released in this branch https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Ftree\u002Ffeature\u002Fadd_transformers\n\u003Cbr>\u003Cbr>\n\n\n# News\n* 2023.5.11: Two papers ([OFA-OCR](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.09297) and [OFA-prompt](https:\u002F\u002Farxiv.org\u002Fabs\u002F2208.02532)) are accepted by ACL. The evaluation scripts and checkpoints of OFA-OCR are released.\n* 2023.1.11: Released MuE (https:\u002F\u002Farxiv.org\u002Fabs\u002F2211.11152), which significantly accelerates OFA with little performance degradation. Many thanks to the first author, Shengkun Tang (@Tangshengku). See the branch `feature\u002FMuE` and [PR](https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fpull\u002F336) for more information.\n* 2022.12.20: Released OFA-OCR, a model for Chinese text recognition based on OFA. Check our [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.09297) and [demo](https:\u002F\u002Fmodelscope.cn\u002Fstudios\u002Fdamo\u002Fofa_ocr_pipeline\u002Fsummary).\n* 2022.12.7: Released the MMSpeech an ASR pre-training method based on OFA. Check our paper [here](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.00500)! Please see the [README_mmspeech.md](README_mmspeech.md) for further details.\n* 2022.8.16: Released the **Chinese** version of OFA. **OFA-CN** needs only switching to `bpe_dir=..\u002F..\u002Futils\u002FBERT_CN_dict` and `bpe=bert` and using our provided Chinese checkpoints in [checkpoints_cn.md](checkpoints_cn.md). Temporarily, we only provide base-size and large-size pretrained checkpoints and finetuned checkpoints on [MUGE Caption](https:\u002F\u002Ftianchi.aliyun.com\u002Fmuge) and the Chinese version of RefCOCO(-\u002F+\u002Fg) (to release soon). \n* 2022.8.5: Released support of **prompt tuning** for OFA. Check our paper [here](https:\u002F\u002Farxiv.org\u002Fabs\u002F2208.02532)! Please see the [prompt_tuning.md](prompt_tuning.md) for further details.\n* 2022.7.7: Updated support of OFA on **Hugging Face transformers** (fixed bugs in forward, add sequence generator from Fairseq to ensure performance, etc.). Refer to the doc [transformers.md](transformers.md) and the branch `feature\u002Fadd_transformers`. \n* 2022.6.17: Released the pretrained checkpoint of **OFA-Huge**. To use it, set `--arch=ofa_huge` in the script.\n* 2022.5.15: OFA was accepted by **ICML 2022**\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>More News\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        \u003Cul>\n            \u003Cli>2022.4.28: Add support of inference on **Hugging Face transformers**. For how to use it, please refer to the doc [transformers.md](transformers.md) and our [Hugging Face models](https:\u002F\u002Fhuggingface.co\u002FOFA-Sys).\u003C\u002Fli>\n            \u003Cli>2022.4.16: Released lightweight pretrained models **OFA-Medium** (~93M params) and **OFA-Tiny** (~33M params) in [checkpoints.md](checkpoints.md). To use them, you just need to load the corresponding checkpoint and set `--arch=ofa_medium` or `--arch=ofa_tiny` in the scripts.\u003C\u002Fli>\n            \u003Cli>2022.3.23: Added [Encouraging Loss](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2110.06537.pdf) as a feature. See [README_EncouragingLoss.md](README_EncouragingLoss.md). Leveraging this feature, OFA-Large has achieved improved results in both VQA (**test-std acc: 80.67**) and Image Classification (**test acc: 85.6**) recently.\u003C\u002Fli>\n            \u003Cli>2022.3.21: Released codes for pretraining OFA.\u003C\u002Fli>\n            \u003Cli>2022.3.18: Released the finetuned \u003Cb>OFA-Base\u003C\u002Fb> (~180M parameters) checkpoints and running scripts for vision & language tasks, including: \u003Cb>Caption (146.4 CIDEr), VQA (78.07 on test-std), SNLI-VE (89.3 on dev), RefCOCO (90.67 on testA), RefCOCO+ (87.15 on testA) and RefCOCOg (82.31 on test-u)\u003C\u002Fb>.\u003C\u002Fli>\n            \u003Cli>2022.3.11: Released the finetuning & inference code\u002Fcheckpoints for \u003Cb>Gigaword\u003C\u002Fb>.\u003C\u002Fli>\n            \u003Cli>2022.3.08: Released the pretrained checkpoint of \u003Cb>OFA-Base\u003C\u002Fb> in \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fblob\u002Fmain\u002Fcheckpoints.md\">checkpoints.md\u003C\u002Fa>. To use OFA-Base, you just need to load \u003Ccode>ofa_base.pt\u003C\u002Fcode> and change \u003Ccode>--arch=ofa_large\u003C\u002Fcode> to \u003Ccode>--arch=ofa_base\u003C\u002Fcode> in the training scripts.\u003C\u002Fli>\n            \u003Cli>2022.3.07: Released the finetuning & inference code\u002Fcheckpoints for \u003Cb>Image Classification\u003C\u002Fb>, which achieves \u003Cb>85.0\u003C\u002Fb> accuracy on ImageNet-1K, slightly better than reported in OFA paper.\u003C\u002Fli>\n            \u003Cli>2022.3.04: Released the finetuning & inference code\u002Fcheckpoints for \u003Cb>Text-to-Image Generation\u003C\u002Fb>.\u003C\u002Fli>\n            \u003Cli>2022.3.03: Released the finetuning & inference code\u002Fcheckpoints for \u003Cb>SNLI-VE\u003C\u002Fb> and \u003Cb>GLUE\u003C\u002Fb>.\u003C\u002Fli>\n            \u003Cli>2022.2.22: Released the finetuning & inference code\u002Fcheckpoints for \u003Cb>Visual Question Answering\u003C\u002Fb>, which can reproduce \u003Cb>the reported VQA accuracy in OFA paper (80.02 on test-std)\u003C\u002Fb>. Check our results on the \u003Ca href=\"https:\u002F\u002Feval.ai\u002Fweb\u002Fchallenges\u002Fchallenge-page\u002F830\u002Fleaderboard\u002F2278\">VQA Challenge\u003C\u002Fa>.\u003C\u002Fli>\n            \u003Cli>2022.2.15: Released finetuning & inference code\u002Fcheckpoints for \u003Cb>Referring Expression Comprehension\u003C\u002Fb>\u003C\u002Fli>\n            \u003Cli>2022.2.10: Released the inference code & finetuned checkpoint for \u003Cb>Image captioning\u003C\u002Fb>, which can reproduce \u003Cb>the results on COCO Karparthy test split (149.6 CIDEr)\u003C\u002Fb>. OFA also achieves No.1 on the COCO image captioning online leaderboard \u003Ca href='https:\u002F\u002Fcompetitions.codalab.org\u002Fcompetitions\u002F3221#results'>Link\u003C\u002Fa> (marked as M6-Team).\u003C\u002Fli>\n        \u003C\u002Ful>\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cbr>\u003C\u002Fbr>\n\n\n# Model Card\nWe list the parameters and pretrained checkpoints of OFAs below. For finetuned checkpoints, please refer to [checkpoints.md](checkpoints.md). \n\n\u003Ctable border=\"1\" width=\"100%\">\n    \u003Ctr align=\"center\">\n        \u003Cth>Model\u003C\u002Fth>\u003Cth>Ckpt\u003C\u002Fth>\u003Cth>Params\u003C\u002Fth>\u003Cth>Backbone\u003C\u002Fth>\u003Cth>Hidden size\u003C\u002Fth>\u003Cth>Intermediate size\u003C\u002Fth>\u003Cth>Num. of heads\u003C\u002Fth>\u003Cth>Enc layers\u003C\u002Fth>\u003Cth>Dec layers\u003C\u002Fth>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Tiny\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_tiny.pt\">Download\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>33M\u003C\u002Ftd>\u003Ctd>ResNet50\u003C\u002Ftd>\u003Ctd>256\u003C\u002Ftd>\u003Ctd>1024\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Medium\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_medium.pt\">Download\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>93M\u003C\u002Ftd>\u003Ctd>ResNet101\u003C\u002Ftd>\u003Ctd>512\u003C\u002Ftd>\u003C\u002Ftd>\u003Ctd>2048\u003C\u002Ftd>\u003Ctd>8\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Base\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_base.pt\">Download\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>180M\u003C\u002Ftd>\u003Ctd>ResNet101\u003C\u002Ftd>\u003Ctd>768\u003C\u002Ftd>\u003C\u002Ftd>\u003Ctd>3072\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\u003Ctd>6\u003C\u002Ftd>\u003Ctd>6\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Large\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_large.pt\">Download\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>470M\u003C\u002Ftd>\u003Ctd>ResNet152\u003C\u002Ftd>\u003Ctd>1024\u003C\u002Ftd>\u003C\u002Ftd>\u003Ctd>4096\u003C\u002Ftd>\u003Ctd>16\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Huge\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_huge.pt\">Download\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>930M\u003C\u002Ftd>\u003Ctd>ResNet152\u003C\u002Ftd>\u003Ctd>1280\u003C\u002Ftd>\u003C\u002Ftd>\u003Ctd>5120\u003C\u002Ftd>\u003Ctd>16\u003C\u002Ftd>\u003Ctd>24\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\n    \u003C\u002Ftr>\n\u003C\u002Ftable>\n\u003Cbr>\u003C\u002Fbr>\n\n# Results\nBelow we demonstrate the results of OFAs on cross-modal understanding and generation. \n\n\u003Ctable border=\"1\" width=\"100%\">\n    \u003Ctr align=\"center\">\n        \u003Cth>Task\u003C\u002Fth>\u003Cth>Image Captioning\u003C\u002Fth>\u003Cth>VQA\u003C\u002Fth>\u003Cth>Visual Entailment\u003C\u002Fth>\u003Cth colspan=\"3\">Referring Expression Comprehension\u003C\u002Fth>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>Dataset\u003C\u002Ftd>\u003Ctd>COCO\u003C\u002Ftd>\u003Ctd>VQA v2\u003C\u002Ftd>\u003Ctd>SNLI-VE\u003C\u002Ftd>\u003Ctd>RefCOCO\u003C\u002Ftd>\u003Ctd>RefCOCO+\u003C\u002Ftd>\u003Ctd>RefCOCOg\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>Split\u003C\u002Ftd>\u003Ctd>Karpathy test (CE\u002FCIDEr)\u003C\u002Ftd>\u003Ctd>test-dev\u002Ftest-std\u003C\u002Ftd>\u003Ctd>val\u002Ftest\u003C\u002Ftd>\u003Ctd>val\u002Ftest-a\u002Ftest-b\u003C\u002Ftd>\u003Ctd>val\u002Ftest-a\u002Ftest-b\u003C\u002Ftd>\u003Ctd>val-u\u002Ftest-u\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>Metric\u003C\u002Ftd>\u003Ctd>CIDEr\u003C\u002Ftd>\u003Ctd>Acc.\u003C\u002Ftd>\u003Ctd>Acc.\u003C\u002Ftd>\u003Ctd colspan=\"3\">Acc.\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Tiny\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>119.0 \u002F 128.7\u003C\u002Ftd>\u003Ctd>70.3 \u002F 70.4\u003C\u002Ftd>\u003Ctd>85.3 \u002F 85.2\u003C\u002Ftd>\u003Ctd>80.20 \u002F 84.07 \u002F 75.00\u003C\u002Ftd>\u003Ctd>68.22 \u002F 75.13 \u002F 57.66\u003C\u002Ftd>\u003Ctd>72.02 \u002F 69.74\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Medium\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>130.4 \u002F 140.3\u003C\u002Ftd>\u003Ctd>75.4 \u002F 75.5\u003C\u002Ftd>\u003Ctd>86.6 \u002F 87.0\u003C\u002Ftd>\u003Ctd>85.34 \u002F 87.68 \u002F 77.92\u003C\u002Ftd>\u003Ctd>76.09 \u002F 83.04 \u002F 66.25\u003C\u002Ftd>\u003Ctd>78.76 \u002F 78.58\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Base\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>138.2 \u002F 146.7\u003C\u002Ftd>\u003Ctd>78.0 \u002F 78.1\u003C\u002Ftd>\u003Ctd>89.3 \u002F 89.2\u003C\u002Ftd>\u003Ctd>88.48 \u002F 90.67 \u002F 83.30\u003C\u002Ftd>\u003Ctd>81.39 \u002F 87.15 \u002F 74.29\u003C\u002Ftd>\u003Ctd>82.29 \u002F 82.31\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Large\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>142.2 \u002F 150.7\u003C\u002Ftd>\u003Ctd>80.4 \u002F 80.7\u003C\u002Ftd>\u003Ctd>90.3 \u002F 90.2\u003C\u002Ftd>\u003Ctd>90.05 \u002F 92.93 \u002F 85.26\u003C\u002Ftd>\u003Ctd>85.80 \u002F 89.87 \u002F 79.22\u003C\u002Ftd>\u003Ctd>85.89 \u002F 86.55\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Huge\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>145.3 \u002F 154.9\u003C\u002Ftd>\u003Ctd>82.0 \u002F 82.0\u003C\u002Ftd>\u003Ctd>91.0 \u002F 91.2\u003C\u002Ftd>\u003Ctd>92.04 \u002F 94.03 \u002F 88.44\u003C\u002Ftd>\u003Ctd>87.86 \u002F 91.70 \u002F 80.71\u003C\u002Ftd>\u003Ctd>88.07 \u002F 88.78\u003C\u002Ftd>\n    \u003C\u002Ftr>\n\u003C\u002Ftable>\n\u003Cbr>\u003C\u002Fbr>\n\n# Requirements\n* python 3.7.4\n* pytorch 1.8.1\n* torchvision 0.9.1\n* JAVA 1.8 (for COCO evaluation)\n\u003Cbr>\u003C\u002Fbr>\n\n# Installation\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\npip install -r requirements.txt\n```\n\u003Cbr>\u003C\u002Fbr>\n\n# Datasets and Checkpoints\nSee [datasets.md](datasets.md) and [checkpoints.md](checkpoints.md).\n\u003Cbr>\u003C\u002Fbr>\n\n# Training & Inference\nBelow we provide methods for training and inference on different tasks. We provide both pretrained OFA-Large and OFA-Base in [checkpoints.md](checkpoints.md). The scripts mentioned in this section are prepared for OFA-Large. For reproducing the downstreaming results of OFA-Base, we have also provided the corresponding finetuning and inference scripts for OFA-Base in the `run_scripts\u002F` folder.\n\nWe recommend that your workspace directory should be organized like this: \n```\nOFA\u002F\n├── checkpoints\u002F\n│   ├── ofa_base.pt\n│   ├── ofa_large.pt\n│   ├── caption_large_best_clean.pt\n│   └── ...\n├── criterions\u002F\n├── data\u002F\n├── dataset\u002F\n│   ├── caption_data\u002F\n│   ├── gigaword_data\u002F\n│   └── ...\n├── fairseq\u002F\n├── models\u002F\n├── run_scripts\u002F\n├── tasks\u002F\n├── train.py\n├── trainer.py\n└── utils\u002F\n```\n\n\n## Image Processing\nTo ensure the efficiency of processing data, we did not store images with small files, but instead we encode them to base64 strings.\nTransforming image files to base64 strings is simple. Run the following code:\n```python\nfrom PIL import Image\nfrom io import BytesIO\nimport base64\n\nimg = Image.open(file_name) # path to file\nimg_buffer = BytesIO()\nimg.save(img_buffer, format=img.format)\nbyte_data = img_buffer.getvalue()\nbase64_str = base64.b64encode(byte_data) # bytes\nbase64_str = base64_str.decode(\"utf-8\") # str\n```\n\n## Pretraining\nBelow we provide methods for pretraining OFA.\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        To pretrain OFA, you should first download the dataset we provide (\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fdatasets\u002Fpretrain_data\u002Fpretrain_data_examples.zip\">pretrain_data_examples.zip\u003C\u002Fa>, a small subset of the original pretraining data). For your customed pretraining datasets, please prepare your training samples into the same format. \u003Ccode>pretrain_data_examples.zip\u003C\u002Fcode> contains 4 TSV files: \u003Ccode>vision_language_examples.tsv\u003C\u002Fcode>, \u003Ccode>text_examples.tsv\u003C\u002Fcode>, \u003Ccode>image_examples.tsv\u003C\u002Fcode> and \u003Ccode>detection_examples.tsv\u003C\u002Fcode>. Details of these files are as follows: \n        \u003Cbr \u002F>\n        \u003Cul type=\"circle\">\n            \u003Cli>\u003Cb>vision_language_examples.tsv\u003C\u002Fb>:\n    Each line contains uniq-id, image (base64 string), caption, question, answer, ground-truth objects (objects appearing in the caption or question), dataset name (source of the data) and task type (caption, qa or visual gronunding). Prepared for the pretraining tasks of visual grounding, grounded captioning, image-text matching, image captioning and visual question answering. \u003C\u002Fli>\n            \u003Cli>\u003Cb>text_examples.tsv\u003C\u002Fb>: Each line contains uniq-id and text. Prepared for the pretraining task of text infilling. \u003C\u002Fli> \n            \u003Cli>\u003Cb>image_examples.tsv\u003C\u002Fb>: Each line contains uniq-id, image (base64 string, should be resized to 256*256 resolution) and image-code (generate the sparse codes for the central part of image through VQ-GAN). Prepared for the pretraining task of image infilling. \u003C\u002Fli>\n            \u003Cli>\u003Cb>detection_examples.tsv\u003C\u002Fb>: Each line contains uniq-id, image (base64 string) and bounding box annotations (contains the top-left and bottom-right coordinates of the bounding box, object_id and object_name, seperated by commas). Prepared for the pretraining task of detection. \u003C\u002Fli>\n        \u003C\u002Ful>\n        In addition, the folder negative_sample in pretrain_data_examples.zip contains three files \u003Ccode>all_captions.txt\u003C\u002Fcode>, \u003Ccode>object.txt\u003C\u002Fcode> and \u003Ccode>type2ans.json\u003C\u002Fcode>. The data in these files are used as negative samples for the image-text matching (ITM) task.\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Pretraining\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        By default, the pretraining script will attempt to restore the released pretrained checkpoints of OFA-Base or OFA-Large and perform continuous pretraining. Continuous pretraining is more recommended, which achieves much better results compared with pretraining from scratch. For continuous pretraining, please download the pretrained weights in advance (see \u003Ca href='checkpoints.md'>checkpoints.md\u003C\u002Fa>) and put them in the correct directory \u003Ccode>OFA\u002Fcheckpoints\u002F\u003C\u002Fcode>. If not, the pretraining will begin from scratch.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fpretraining\nbash pretrain_ofa_large.sh # Pretrain OFA-Large. For OFA-Base, use pretrain_ofa_base.sh\n\u003C\u002Fpre>\n    \u003Cp>\n        If the pretrained OFA checkpoint is restored successfully, you will see the following information in the log:\n    \u003C\u002Fp>\n\u003Cpre>\nINFO: Loaded checkpoint ..\u002F..\u002Fcheckpoints\u002Fofa_large.pt\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Image Captioning\nWe provide procedures to reproduce our results of image captioning on our paper below.\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href='datasets.md'>datasets.md\u003C\u002Fa>) and models (see \u003Ca href='checkpoints.md'>checkpoints.md\u003C\u002Fa>) and put them in the correct directory. The dataset zipfile \u003Ccode>caption_data.zip\u003C\u002Fcode> contains caption_stage1_train.tsv, caption_stage2_train.tsv, caption_val.tsv and caption_test.tsv. Each image corresponds to only 1 caption in \u003Ccode>caption_stage1_train.tsv\u003C\u002Fcode> and corresponds to multiple captions in other TSV files (about 5 captions per image). Each line of the dataset represents a caption sample with the following format. The information of uniq-id, image-id, caption, predicted object labels (taken from \u003Ca href='https:\u002F\u002Fgithub.com\u002Fpzzhang\u002FVinVL'>VinVL\u003C\u002Fa>, not used), image base64 string are separated by tabs.\n    \u003C\u002Fp>\n\u003Cpre>\n162365  12455   the sun sets over the trees beyond some docks.  sky&&water&&dock&&pole  \u002F9j\u002F4AAQSkZJ....UCP\u002F2Q==\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Following previous standard practice, we divide the finetuning process of image captioning into two stages. In stage 1, we finetune OFA with cross-entropy loss on 4 NVIDIA-V100 GPUs with 32GB memory (expected to obtain ~139.5 CIDEr on the validation set at this stage). In stage 2, we select the best checkpoint of stage 1 and train with CIDEr optimization on 8 NVIDIA-V100 GPUs. \u003Cb>Note that CIDEr optimization is very unstable and requires careful hyperparameter tuning. If you encounter training errors in the stage2 finetuning, you can increase the batch size or reduce the learning rate. If neither of these works, you can directly set \u003C\u002Fb>\u003Ccode>--freeze-resnet\u003C\u002Fcode>\u003Cb> to freeze the inner states of batch normalization.\u003C\u002Fb>\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fcaption\nnohup sh train_caption_stage1.sh > train_stage1.out &  # stage 1, train with cross-entropy loss\nnohup sh train_caption_stage2.sh > train_stage2.out &  # stage 2, load the best ckpt of stage1 and train with CIDEr optimization \n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Run the following commands to get your results and evaluate your model.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fcaption ; sh evaluate_caption.sh  # inference & evaluate\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Text-to-Image Generation \nThis part provides procedures for the finetuning and inference of text-to-image generation. See below.\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) and models (see \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>) and put them in the correct directory. The dataset zipfile \u003Ccode>coco_image_gen.zip\u003C\u002Fcode> contains \u003Ccode>coco_vqgan_train.tsv\u003C\u002Fcode>, \u003Ccode>coco_vqgan_dev.tsv\u003C\u002Fcode> and \u003Ccode>coco_vqgan_full_test.tsv\u003C\u002Fcode>. Each line of the dataset represents a sample with the following format. The information of uniq-id, image-code (produced by \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FCompVis\u002Ftaming-transformers\">vqgan\u003C\u002Fa>, a list of integers separated by single-whitespaces), lowercased caption are separated by tabs.\n    \u003C\u002Fp>\n\u003Cpre>\n1\t6674 4336 4532 5334 3251 5461 3615 2469 ...4965 4190 1846\tthe people are posing for a group photo.\n\u003C\u002Fpre>\n    \u003Cp>\n        The checkpoint zipfile \u003Ccode>image_gen_large_best.zip\u003C\u002Fcode> contains \u003Ccode>image_gen_large_best.pt\u003C\u002Fcode>, \u003Ccode>vqgan\u002Flast.ckpt\u003C\u002Fcode>, \u003Ccode>vqgan\u002Fmodel.yaml\u003C\u002Fcode> and \u003Ccode>clip\u002FVit-B-16.pt\u003C\u002Fcode>. \n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Shuffle the Training Data\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        (Optional, but achieves better result): If the disk storage is sufficient, we recommend to prepare the shuffled training data for each epoch in advance. \n    \u003C\u002Fp>\n\u003Cpre>\ncd dataset\u002Fimage_gen\nln coco_vqgan_train.tsv coco_vqgan_train_1.tsv\nfor idx in `seq 1 9`;do shuf coco_vqgan_train_${idx}.tsv > coco_vqgan_train_$[${idx}+1].tsv;done # each file is used for an epoch\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Following previous practice, we divide the finetuning process of image generating into two stages. In stage 1, we finetune OFA with cross-entropy loss on 4 8-V100-32G-GPU servers (expected to obtain ~32.5+ CLIP Score on the validation set at this stage). In stage 2, we select the last checkpoint of stage 1 and train with CLIP Score optimization on 4 8-V100-32G-GPU servers (expected to obtain ~34.0+ CLIP Score on the validation set at this stage). During the validation, the generated image will be dumped into \u003Ccode>_GEN_IMAGE_PATH_\u003C\u002Fcode>. \n    \u003C\u002Fp>\n\u003Cpre>\n# run on each worker after the distributed and data configs have been correctly set following the guide in train_image_gen_stage1_distributed.sh \ncd run_scripts\u002Fimage_gen\nnohup sh train_image_gen_stage1_distributed.sh # stage 1, train with cross-entropy loss\nnohup sh train_image_gen_stage2_distributed.sh # stage 2, load the last ckpt of stage1 and train with CLIP Score optimization \n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>4. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Run the command below to generate your images. \n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fimage_gen ; sh evaluate_image_gen.sh  # inference & evaluate (FID, IS and CLIP Score)\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Visual Question Answering\nHere we provide the finetuning and inference codes to reproduce the VQAv2 result reported in our paper (**test-std 80.02**). We believe much improvement on accuracy can still be achieved based on this codebase :)\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) and models (see \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>) and put them in the correct directory. The dataset zipfile \u003Ccode>vqa_data.zip\u003C\u002Fcode> is around 100G and the decompressed data costs around 135G disk storage, which contains the training, validation and testing samples together with other necessary data resources. (Since \u003Ccode>vqa_data.zip\u003C\u002Fcode> is large in size, we have also provided chunked parts of the dataset files for more convenient and stable downloading. Please refer to \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F68#issuecomment-1096837349\">issue #68\u003C\u002Fa>.) Following common practice, VG-QA samples are also included in the training data. To adapt to the seq2seq paradigm of OFA, we transform original VQA training questions with multiple golden answers into multiple training samples. For the original VQA validation set, we keep around 10k samples for our validation and utilize the other samples for training. Each line of the dataset represents a VQA sample with the following format. The information of question-id, image-id, question, answer (with confidence), predicted object labels (taken from \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fpzzhang\u002FVinVL\">VinVL\u003C\u002Fa>, slightly brings around +0.1 accuracy improvement), image base64 string are separated by tabs. \n    \u003C\u002Fp>\n\u003Cpre>\n79459   79459   is this person wearing shorts?  0.6|!+no    house&&short&&...&&sky  \u002F9j\u002F4AAQS...tigZ\u002F9k=\n\u003C\u002Fpre>\n    \u003Cp>\n        For fine-tuning on customed VQA-formulated tasks, please refer to issue \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F76\">#76\u003C\u002Fa>, \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F105\">#105\u003C\u002Fa> and \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F73\">#73\u003C\u002Fa> for more information.\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Shuffle the Training Data\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        (Optional, but achieves better finetuning accuracy): If the disk storage is sufficient, we recommend to prepare the shuffled training data for each epoch in advance. In our experiments, we use shuffling which brings around \u003Cb>+0.3\u003C\u002Fb> improvement on VQA accuracy.\n    \u003C\u002Fp>\n\u003Cpre>\ncd dataset\u002Fvqa_data\nln vqa_train.tsv vqa_train_1.tsv\nfor idx in `seq 1 9`;do shuf vqa_train_${idx}.tsv > vqa_train_$[${idx}+1].tsv;done # each file is used for an epoch\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        In our experiments, the VQA finetuning is performed on 4 8-A100-GPU servers (\u003Ci>with RDMA\u003C\u002Fi>). Here provides the finetuning script \u003Ccode>train_vqa_distributed.sh\u003C\u002Fcode>, which supports multi-server distributed training (as well as single-server training). Please refer to the comments in the beginning of the script and set the configs correctly according to your distribution environment. If you have shuffled the training data in the previous step, please correctly specify the training data path following the guide in the script comments. \u003Cb>The command should be run on each worker.\u003C\u002Fb> \n    \u003C\u002Fp>\n\u003Cpre>\n# run on each worker after the distributed and data configs have been correctly set following the guide in train_vqa_distributed.sh \ncd run_scripts\u002Fvqa\nbash train_vqa_distributed.sh \n\u003C\u002Fpre>\n    \u003Cp>\n        In our experiments, the finetuning costs around 36 hours (for 12 epochs). After each epoch, an evaluation on validation set is performed. The best validation accuracy during finetuning will be around 80.8. The log is saved in \u003Ccode>${log_dir}\u003C\u002Fcode>.\n    \u003C\u002Fp>\n    \u003Cp>\n        \u003Ci>(Update on validation time-cost)\u003C\u002Fi> As will be mentioned in the \u003Ci>4. Inference\u003C\u002Fi> section, we prepare 2 types of inference: beam-search and all-candidate inference. By default, all-candidate inference is used for validation during fine-tuning, which achieves better accuracy but costs much time. Now we have added a new option in the training scripts called \u003Ccode>--val-inference-type\u003C\u002Fcode> to switch the validation inference type during fine-tuning. If you feel the validation takes too long, you can refer to \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fpull\u002F79\">PR #79\u003C\u002Fa> to activate beam-search validation, which significantly takes much less time, with around 0.5-0.6 validation score degradation compared with all-candidate validation.\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>4. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        We provide 2 types of inference, \u003Cb>beam-search\u003C\u002Fb> (much faster but gets sub-optimal accuracy) and \u003Cb>all-candidate evaluation\u003C\u002Fb> (slower but best accuracy). \u003Cbr>\u003C\u002Fbr>\n        For beam-search inference, use the script \u003Ccode>evaluate_vqa_beam.sh\u003C\u002Fcode>. Refer to the command below. The inference on test set costs around 16 GPU hours. After inference on test set, the result JSON file will be dumped in the \u003Ccode>${result_path}\u003C\u002Fcode> defined in the shell script. You can submit the result \u003Ccode>test_predict.json\u003C\u002Fcode> to \u003Ca href=\"https:\u002F\u002Feval.ai\u002Fweb\u002Fchallenges\u002Fchallenge-page\u002F830\u002Foverview\">EvalAI\u003C\u002Fa>. Using our released finetuned checkpoint, beam-search inference will get 80.15 validation accuracy, 79.36 test-dev accuracy and 79.48 test-std accuracy (around 0.6 lower than all-candidate evaluation).\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fvqa\nbash evaluate_vqa_beam.sh val # specify 'val' or 'test'\n\u003C\u002Fpre>\n    \u003Cp>\n        For all-candidate evaluation, we recommend to use the distributed script \u003Ccode>evaluate_vqa_allcand_distributed.sh\u003C\u002Fcode>. Please refer to the guide in the script to set the distributed configs before running. The result JSON file will be dumped in the \u003Ccode>${result_path}\u003C\u002Fcode> defined in the shell script of rank-0 server. All-candidate evaluation computes scores on all the candidate answers in the VQA dataset, which achieves \u003Cb>80.82\u003C\u002Fb> validation accuracy, \u003Cb>79.87\u003C\u002Fb> test-dev accuracy and \u003Cb>80.02\u003C\u002Fb> test-std accuracy, reproducing our reported results in the paper. However, the inference on test set costs around 1k GPU hours, which is much slower.\n    \u003C\u002Fp>\n\u003Cpre>\n# run on each worker after the distributed configs have been correctly set following the guide in evaluate_vqa_allcand_distributed.sh\ncd run_scripts\u002Fvqa\nbash evaluate_vqa_allcand_distributed.sh val # specify 'val' or 'test'\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Visual Grounding (Referring Expression Comprehension)\nHere provides procedures for you to prepare data, train, and evaluate your model on visual grounding. \n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href='datasets.md'>datasets.md\u003C\u002Fa>) and models (see \u003Ca href='checkpoints.md'>checkpoints.md\u003C\u002Fa>) and put them in the correct directory. We provide RefCOCO (split by UNC), RefCOCO+ (split by UNC) and RefCOCOg (split by UMD) datasets. See \u003Ca href='https:\u002F\u002Fwww.tensorflow.org\u002Fdatasets\u002Fcatalog\u002Fref_coco'>RefCOCO\u003C\u002Fa> and \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Flichengunc\u002Frefer\">Refer\u003C\u002Fa> for more details. Note that in the original dataset, each region-coord (or bounding box) may corresponds to multiple descriptive texts. We split these texts into multiple samples so that the region-coord in each sample corresponds to only one text. Each line of the processed dataset represents a sample with the following format. The information of uniq-id, image-id, text, region-coord (separated by commas), image base64 string are separated by tabs.\n    \u003C\u002Fp>\n\u003Cpre>\n79_1    237367  A woman in a white blouse holding a glass of wine.  230.79,121.75,423.66,463.06 9j\u002F4AAQ...1pAz\u002F9k=\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Unlike the original paper, we finetune OFA with a drop-path rate of 0.2, and found that training with this hyper-parameter achieves better results. We will update the reported results of the paper later.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Frefcoco\nnohup sh train_refcoco.sh > train_refcoco.out &  # finetune for refcoco\nnohup sh train_refcocoplus.sh > train_refcocoplus.out &  # finetune for refcoco+\nnohup sh train_refcocog.sh > train_refcocog.out &  # finetune for refcocog\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Run the following commands for the evaluation. \n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Frefcoco ; sh evaluate_refcoco.sh  # inference & evaluate for refcoco\u002Frefcoco+\u002Frefcocog\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Visual Entailment\nWe provide steps for you to reproduce our results in visual entailment. See the details below.\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) and models (see \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>) and put them in the correct directory. Each line of the processed dataset represents a sample with the following format. The information of uniq-id, image-id, image base64 string, hypothesis, caption (or text premise), label are separated by tabs.\n    \u003C\u002Fp>\n\u003Cpre>\n252244149.jpg#1r1n  252244149   \u002F9j\u002F4AAQ...MD\u002F2Q==   a man in pink and gold is chewing on a wooden toothpick.   a man in pink is chewing a toothpick on the subway.   neutral \n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        In our experiments, the SNLI-VE finetuning is performed on 8 NVIDIA-V100 GPUs with 32GB memory. In this task, we experimented with only a few sets of hyperparameters. We believe that proper hyperparameter tuning can lead to further accuracy improvement.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fsnli_ve\nnohup sh train_snli_ve.sh > train_snli_ve.out &  # finetune for snli_ve\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Run the following command to obtain the results.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fsnli_ve ; sh evaluate_snli_ve.sh dev  # specify 'dev' or 'test'\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n   \n## GLUE\nHere we provide steps for you to finetune and evaluate our model on language understanding tasks. We demonstrate our practice for the GLUE benchmark. \n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) and models (see \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>) and put them in the correct directory. we provide 7 language understanding datasets from GLUE benchmark, including COLA, MNLI, MRPC, QNLI, QQP, RTE and SST2. More details about these datasets can be found in this \u003Ca href=\"https:\u002F\u002Fopenreview.net\u002Fpdf?id=rJ4km2R5t7\">link\u003C\u002Fa>.\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        For each task, we have tried multiple sets of hyperparameters (including learning rate, batch size, training epochs). The results under different sets of hyperparameters can be found in \u003Ccode>${log_dir}\u003C\u002Fcode>.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fglue\nnohup sh train_cola.sh > train_cola.out &  # finetune for cola\nnohup sh train_mnli.sh > train_mnli.out &  # finetune for mnli\nnohup sh train_mrpc.sh > train_mrpc.out &  # finetune for mrpc\nnohup sh train_qnli.sh > train_qnli.out &  # finetune for qnli\nnohup sh train_qqp.sh > train_qqp.out &  # finetune for qqp\nnohup sh train_rte.sh > train_rte.out &  # finetune for rte\nnohup sh train_sst2.sh > train_sst2.out &  # finetune for sst2\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Image Classification on ImageNet-1K\nWe provide the finetuning and inference codes which reproduce **85.0 ImageNet-1K accuracy**, slightly better than reported in our paper. \n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) and models (see \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>) and put them in the correct directory. Our provided data is derived from the original \u003Ca href=\"http:\u002F\u002Fimage-net.org\u002F\">ImageNet-1K\u003C\u002Fa> (ILSVRC2012 train & validation) dataset and shares the same data split with it. To formulate the classification task into seq2seq paradigm, we use the \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FHoldenCaulfieldRye\u002Fcaffe\u002Fblob\u002Fmaster\u002Fdata\u002Filsvrc12\u002Fsynset_words.txt\">synset words\u003C\u002Fa> provided by Caffe as the generation target for each image class. Each line of the processed dataset represents a sample with the following format. The information of image base64 string, classification label (1-indexed, conform to the order in \u003Ccode>synset_words.txt\u003C\u002Fcode>), synset words of the label are separated by tabs.\n    \u003C\u002Fp>\n\u003Cpre>\n_9j_4AAQS...fzX__Z  769 rugby ball\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Shuffle the Training Data\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        (Optional, but achieves better finetuning accuracy): If the disk storage is sufficient, we recommend to prepare the shuffled training data for each epoch in advance. In our experiments, we use shuffling which brings around \u003Cb>+0.2\u003C\u002Fb> improvement on ImageNet-1K accuracy.\n    \u003C\u002Fp>\n\u003Cpre>\ncd dataset\u002Fimagenet_1k_data\nln imagenet_1k_train.tsv imagenet_1k_train_1.tsv\nfor idx in `seq 1 9`;do shuf imagenet_1k_train_${idx}.tsv > imagenet_1k_train_$[${idx}+1].tsv;done # each file is used for an epoch one by one\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        In our experiments, the ImageNet-1K finetuning is performed on 2 8-A100-GPU servers (\u003Ci>with RDMA\u003C\u002Fi>). Here provides the finetuning script \u003Ccode>train_imagenet_distributed.sh\u003C\u002Fcode>, which supports multi-server distributed training (as well as single-server training). Please refer to the comments in the beginning of the script and set the configs correctly according to your distribution environment. If you have shuffled the training data in the previous step, please correctly specify the training data path following the guide in the script comments. \u003Cb>The command should be run on each worker.\u003C\u002Fb> For quick evaluation during finetuning, by default we sample 20% of the original validation split and report accuracy on this subset after each epoch. The accuracy on the validation subset is generally ±0.1 relative to accuracy on the whole validation split.\n    \u003C\u002Fp>\n\u003Cpre>\n# run on each worker after the distributed and data configs have been correctly set following the guide in train_imagenet_distributed.sh\ncd run_scripts\u002Fimage_classify\nbash train_imagenet_distributed.sh\n\u003C\u002Fpre>\n    \u003Cp>\n        In our experiments, the finetuning costs around 80 hours (for 32 epochs). The best accuracy on validation subset during finetuning will be around 85.0. The log is saved in \u003Ccode>${log_dir}\u003C\u002Fcode>.\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>4. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        To get the validation accuracy on the whole ImageNet-1K validation set, run the following command. The evaluation costs around 10 GPU hours. The accuracy will be reported in the stdout (expected to be around \u003Cb>85.0\u003C\u002Fb>).\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fimage_classify ; sh evaluate_imagenet.sh  # inference & evaluate for imagenet-1k\n\u003C\u002Fpre>\n\u003C\u002Fdetails> \n\n## Gigaword\nWe provide steps for you to reproduce our results in Gigaword. See the details below.\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. Prepare the Dataset & Checkpoints\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Download data (see \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) and models (see \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>) and put them in the correct directory. The original dataset is taken from \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Funilm\u002F\">UniLM\u003C\u002Fa> and we organized the data into the tsv format. Each line of the processed dataset represents a sample with the following format. The information of source and target texts are separated by tabs.\n    \u003C\u002Fp>\n\u003Cpre>\nfactory orders for manufactured goods rose #.# percent in september...  us september factory orders up #.# percent\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. Finetuning\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Run the following command to train the model.\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fgigaword\nnohup sh train_gigaword.sh > train_gigaword.out &  # finetune for gigaword\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. Inference\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        Run the following command to obtain the results (~36.43 rougeL).\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fgigaword ; sh evaluate_gigaword.sh  # inference & evaluate for gigaword\n\u003C\u002Fpre>\n\u003C\u002Fdetails> \n\n\u003Cbr>\u003C\u002Fbr>\n\n# Gallery\nBelow we provide examples of OFA in text-to-image generation and open-ended VQA. Also, we demonstrate its performance in unseen task (Grounded QA) as well as unseen domain (Visual Grounding on images from unseen domains). \n\n## Text-to-Image Generation\n\n![case1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_a116a7bacfd7.png)\n\n\n## Open-Ended VQA\n![open_vqa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_a869889f4a70.png)\n\n## Grounded QA (unseen task)\n![grounded_qa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_ef406dd0055a.png)\n\n## Visual Grounding (unseen domain)\n![vg](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_865522ee0471.png)\n\u003Cbr>\u003C\u002Fbr>\n\n# Related Codebase\n* [Fairseq](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Ffairseq)\n* [taming-transformers](https:\u002F\u002Fgithub.com\u002FCompVis\u002Ftaming-transformers)\n\u003Cbr>\u003C\u002Fbr>\n\n\n# Getting Involved\nFeel free to submit Github issues or pull requests. Welcome to contribute to our project!\n\nTo contact us, never hestitate to send an email to `zheluo.wp@alibaba-inc.com` or `junyang.ljy@alibaba-inc.com`!\n\u003Cbr>\u003C\u002Fbr>\n\n\n# Citation\nPlease cite our papers if you find them helpful :)\n\n```\n@article{wang2022ofa,\n  author    = {Peng Wang and\n               An Yang and\n               Rui Men and\n               Junyang Lin and\n               Shuai Bai and\n               Zhikang Li and\n               Jianxin Ma and\n               Chang Zhou and\n               Jingren Zhou and\n               Hongxia Yang},\n  title     = {OFA: Unifying Architectures, Tasks, and Modalities Through a Simple Sequence-to-Sequence\n               Learning Framework},\n  journal   = {CoRR},\n  volume    = {abs\u002F2202.03052},\n  year      = {2022}\n}\n```\n\u003Cbr>\u003C\u002Fbr>\n```\n@article{ofa_ocr,\n  author       = {Junyang Lin and\n                  Xuancheng Ren and\n                  Yichang Zhang and\n                  Gao Liu and\n                  Peng Wang and\n                  An Yang and\n                  Chang Zhou},\n  title        = {Transferring General Multimodal Pretrained Models to Text Recognition},\n  journal      = {CoRR},\n  volume       = {abs\u002F2212.09297},\n  year         = {2022}\n}\n```\n\u003Cbr>\u003Cbr>\n```\n@article{ofa_prompt,\n  author       = {Hao Yang and\n                  Junyang Lin and\n                  An Yang and\n                  Peng Wang and\n                  Chang Zhou and\n                  Hongxia Yang},\n  title        = {Prompt Tuning for Generative Multimodal Pretrained Models},\n  journal      = {CoRR},\n  volume       = {abs\u002F2208.02532},\n  year         = {2022}\n}\n```\n\u003Cbr>\u003Cbr>\n```\n@article{mmspeech,\n  title={MMSpeech: Multi-modal Multi-task Encoder-Decoder Pre-training for Speech Recognition},\n  author={Zhou, Xiaohuan and Wang, Jiaming and Cui, Zeyu and Zhang, Shiliang and Yan, Zhijie and Zhou, Jingren and Zhou, Chang},\n  journal={arXiv preprint arXiv:2212.00500},\n  year={2022}\n}\n```\n","\u003C!---\n版权所有 © 2022 OFA-Sys 团队。\n保留所有权利。\n本源代码根据根目录下的 LICENSE 文件中所载的 Apache 2.0 许可证进行授权。\n-->\n\n\u003Cp align=\"center\">\n    \u003Cbr>\n    \u003Cimg src=\"examples\u002FOFA_logo_tp_path.svg\" width=\"150\" \u002F>\n    \u003Cbr>\n\u003Cp>\n\u003Cbr>\n\n\u003Cp align=\"center\">\n        \u003Ca href=\"modelscope.md\">ModelScope\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"checkpoints.md\">检查点\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"colab.md\">Colab\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fofa-sys\">演示\u003C\u002Fa>&nbsp ｜ &nbsp\u003Ca href=\"http:\u002F\u002Farxiv.org\u002Fabs\u002F2202.03052\">论文 \u003C\u002Fa>&nbsp ｜ &nbsp博客\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n    \u003Cbr>\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_a6cac7c5ba3e.gif\" width=\"800\" \u002F>\n    \u003Cbr>\n\u003Cp>\n\n[colab]: \u003Chttps:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg>\n\nOFA 是一个统一的序列到序列预训练模型（支持 **英语** 和 **中文**），它能够统一多种模态（即跨模态、视觉、语言）和任务（支持 **微调** 和 **提示调优**）：图像字幕生成（在 [MSCOCO 排行榜](https:\u002F\u002Fcompetitions.codalab.org\u002Fcompetitions\u002F3221#results) 上排名第一）、VQA（[链接](https:\u002F\u002Feval.ai\u002Fweb\u002Fchallenges\u002Fchallenge-page\u002F830\u002Fleaderboard\u002F2278)）、视觉定位、文本到图像生成、文本分类、文本生成、图像分类等。我们提供了关于预训练和微调的 **分步** 指导说明，以及相应的检查点（请查看官方检查点 \\[[EN](checkpoints.md)|[CN](checkpoints_cn.md)\\] 或 [Hugging Face 检查点](https:\u002F\u002Fhuggingface.co\u002FOFA-Sys))。\n\n我们诚挚地欢迎各位为我们的项目贡献力量。欢迎您随时与我们联系或提交问题\u002F拉取请求！\n\u003Cbr>\u003C\u002Fbr>\n\n\n# 在线演示\n我们通过 Hugging Face Spaces 提供在线演示，方便您与我们的预训练和微调模型进行交互。以下是各个演示的链接：\n* 图像字幕生成 \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_image-caption_coco_large_en\u002Fsummary)  |  [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Image_Caption)\\]\n* 视觉定位 \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_visual-grounding_refcoco_large_en\u002Fsummary) | [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Visual_Grounding)\\]\n* 视觉问答 \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_visual-question-answering_pretrain_large_en\u002Fsummary) | [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Visual_Question_Answering)\\]\n* 文本到图像生成 \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_text-to-image-synthesis_coco_large_en\u002Fsummary) | [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Text2Image_Generation)\\]\n* 通用接口 \\[[Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Generic_Interface)\\]\n* 中文 OCR \\[[ModelScope](https:\u002F\u002Fmodelscope.cn\u002Fstudios\u002Fdamo\u002Fofa_ocr_pipeline\u002Fsummary)  |  [Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-OCR)\\]\n\n\n此外，我们还提供了 Colab 笔记本，帮助您更好地理解操作流程。点击 [这里](colab.md) 即可查看！\n\u003Cbr>\u003C\u002Fbr>\n\n# 在 Hugging Face Transformers 中使用\n我们支持在 Hugging Face Transformers 中对 OFA 进行推理。更多信息请参阅 [README](transformers.md) 和 [Colab 笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1Ho81RBV8jysZ7e0FhsSCk_v938QeDuy3?usp=sharing)。相关代码已发布在此分支：https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Ftree\u002Ffeature\u002Fadd_transformers\n\u003Cbr>\u003Cbr>\n\n# 新闻\n* 2023年5月11日：两篇论文（[OFA-OCR](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.09297) 和 [OFA-prompt](https:\u002F\u002Farxiv.org\u002Fabs\u002F2208.02532)）被 ACL 接收。OFA-OCR 的评估脚本和检查点已发布。\n* 2023年1月11日：发布了 MuE（https:\u002F\u002Farxiv.org\u002Fabs\u002F2211.11152），该方法在性能损失很小的情况下显著加速了 OFA。特别感谢第一作者唐圣坤 (@Tangshengku)。更多信息请参阅 `feature\u002FMuE` 分支及 [PR](https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fpull\u002F336)。\n* 2022年12月20日：发布了基于 OFA 的中文文本识别模型 OFA-OCR。请查看我们的 [论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.09297) 和 [演示](https:\u002F\u002Fmodelscope.cn\u002Fstudios\u002Fdamo\u002Fofa_ocr_pipeline\u002Fsummary)。\n* 2022年12月7日：发布了基于 OFA 的 ASR 预训练方法 MMSpeech。请在此处查看我们的论文 [这里](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.00500)! 更多详情请参阅 [README_mmspeech.md](README_mmspeech.md)。\n* 2022年8月16日：发布了 OFA 的 **中文**版本。使用 **OFA-CN** 只需将 `bpe_dir=..\u002F..\u002Futils\u002FBERT_CN_dict` 和 `bpe=bert` 进行切换，并使用我们在 [checkpoints_cn.md](checkpoints_cn.md) 中提供的中文检查点即可。目前我们仅提供基础尺寸和大型预训练检查点，以及在 [MUGE Caption](https:\u002F\u002Ftianchi.aliyun.com\u002Fmuge) 和中文版 RefCOCO(-\u002F+\u002Fg) 数据集上的微调检查点（即将发布）。\n* 2022年8月5日：发布了 OFA 对 **提示调优** 的支持。请在此处查看我们的论文 [这里](https:\u002F\u002Farxiv.org\u002Fabs\u002F2208.02532)! 更多细节请参阅 [prompt_tuning.md](prompt_tuning.md)。\n* 2022年7月7日：更新了 OFA 在 **Hugging Face transformers** 上的支持（修复了 forward 中的 bug，添加了来自 Fairseq 的序列生成器以确保性能等）。请参考文档 [transformers.md](transformers.md) 和分支 `feature\u002Fadd_transformers`。\n* 2022年6月17日：发布了 **OFA-Huge** 的预训练检查点。使用时，在脚本中设置 `--arch=ofa_huge` 即可。\n* 2022年5月15日：OFA 被 **ICML 2022** 接收。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>更多新闻\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        \u003Cul>\n            \u003Cli>2022年4月28日：增加了对 **Hugging Face transformers** 推理的支持。使用方法请参阅文档 [transformers.md](transformers.md) 和我们的 [Hugging Face 模型](https:\u002F\u002Fhuggingface.co\u002FOFA-Sys)。\u003C\u002Fli>\n            \u003Cli>2022年4月16日：在 [checkpoints.md](checkpoints.md) 中发布了轻量级预训练模型 **OFA-Medium**（约 9300 万参数）和 **OFA-Tiny**（约 3300 万参数）。使用时，只需加载相应的检查点，并在脚本中设置 `--arch=ofa_medium` 或 `--arch=ofa_tiny` 即可。\u003C\u002Fli>\n            \u003Cli>2022年3月23日：新增了 [鼓励损失](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2110.06537.pdf) 功能。详情请参阅 [README_EncouragingLoss.md](README_EncouragingLoss.md)。利用此功能，OFA-Large 最近在 VQA（测试标准准确率：80.67%）和图像分类（测试准确率：85.6%）任务上均取得了更好的成绩。\u003C\u002Fli>\n            \u003Cli>2022年3月21日：发布了 OFA 预训练的代码。\u003C\u002Fli>\n            \u003Cli>2022年3月18日：发布了经过微调的 \u003Cb>OFA-Base\u003C\u002Fb>（约 1.8 亿参数）检查点及视觉与语言任务的运行脚本，包括：\u003Cb>Caption（146.4 CIDEr）、VQA（测试标准数据集上为 78.07）、SNLI-VE（开发集上为 89.3）、RefCOCO（测试 A 子集上为 90.67）、RefCOCO+（测试 A 子集上为 87.15）和 RefCOCOg（测试 u 子集上为 82.31）\u003C\u002Fb>。\u003C\u002Fli>\n            \u003Cli>2022年3月11日：发布了用于 \u003Cb>Gigaword\u003C\u002Fb> 任务的微调与推理代码\u002F检查点。\u003C\u002Fli>\n            \u003Cli>2022年3月8日：在 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fblob\u002Fmain\u002Fcheckpoints.md\">checkpoints.md\u003C\u002Fa> 中发布了 \u003Cb>OFA-Base\u003C\u002Fb> 的预训练检查点。使用 OFA-Base 时，只需加载 \u003Ccode>ofa_base.pt\u003C\u002Fcode>,并将训练脚本中的 \u003Ccode>--arch=ofa_large\u003C\u002Fcode> 改为 \u003Ccode>--arch=ofa_base\u003C\u002Fcode> 即可。\u003C\u002Fli>\n            \u003Cli>2022年3月7日：发布了用于 \u003Cb>图像分类\u003C\u002Fb> 任务的微调与推理代码\u002F检查点，其在 ImageNet-1K 数据集上的准确率为 \u003Cb>85.0%\u003C\u002Fb>,略高于 OFA 论文中报告的结果。\u003C\u002Fli>\n            \u003Cli>2022年3月4日：发布了用于 \u003Cb>文本到图像生成\u003C\u002Fb> 任务的微调与推理代码\u002F检查点。\u003C\u002Fli>\n            \u003Cli>2022年3月3日：发布了用于 \u003Cb>SNLI-VE\u003C\u002Fb> 和 \u003Cb>GLUE\u003C\u002Fb> 任务的微调与推理代码\u002F检查点。\u003C\u002Fli>\n            \u003Cli>2022年2月22日：发布了用于 \u003Cb>视觉问答\u003C\u002Fb> 任务的微调与推理代码\u002F检查点，能够复现 \u003Cb>OFA 论文中报告的 VQA 准确率（测试标准数据集上为 80.02%）\u003C\u002Fb>。请查看我们在 \u003Ca href=\"https:\u002F\u002Feval.ai\u002Fweb\u002Fchallenges\u002Fchallenge-page\u002F830\u002Fleaderboard\u002F2278\">VQA 挑战赛\u003C\u002Fa> 上的成绩。\u003C\u002Fli>\n            \u003Cli>2022年2月15日：发布了用于 \u003Cb>指代表达理解\u003C\u002Fb> 任务的微调与推理代码\u002F检查点。\u003C\u002Fli>\n            \u003Cli>2022年2月10日：发布了用于 \u003Cb>图像字幕生成\u003C\u002Fb> 任务的推理代码及微调检查点，能够复现 \u003Cb>COCO Karparthy 测试集上的结果（149.6 CIDEr）\u003C\u002Fb>。OFA 还在 COCO 图像字幕在线排行榜上排名第一 \u003Ca href='https:\u002F\u002Fcompetitions.codalab.org\u002Fcompetitions\u002F3221#results'>链接\u003C\u002Fa>（标记为 M6-Team）。\u003C\u002Fli>\n        \u003C\u002Ful>\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cbr>\u003C\u002Fbr>\n\n\n# 模型卡片\n以下列出了 OFA 各个模型的参数及预训练检查点。关于微调后的检查点，请参阅 [checkpoints.md](checkpoints.md)。\n\n\u003Ctable border=\"1\" width=\"100%\">\n    \u003Ctr align=\"center\">\n        \u003Cth>模型\u003C\u002Fth>\u003Cth>检查点\u003C\u002Fth>\u003Cth>参数\u003C\u002Fth>\u003Cth>骨干网络\u003C\u002Fth>\u003Cth>隐藏层大小\u003C\u002Fth>\u003Cth>中间层大小\u003C\u002Fth>\u003Cth>注意力头数\u003C\u002Fth>\u003Cth>编码器层数\u003C\u002Fth>\u003Cth>解码器层数\u003C\u002Fth>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Tiny\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_tiny.pt\">下载\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>3300 万\u003C\u002Ftd>\u003Ctd>ResNet50\u003C\u002Ftd>\u003Ctd>256\u003C\u002Ftd>\u003Ctd>1024\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Medium\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_medium.pt\">下载\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>9300 万\u003C\u002Ftd>\u003Ctd>ResNet101\u003C\u002Ftd>\u003Ctd>512\u003C\u002Ftd>\u003Ctd>2048\u003C\u002Ftd>\u003Ctd>8\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\u003Ctd>4\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Base\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_base.pt\">下载\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>1.8 亿\u003C\u002Ftd>\u003Ctd>ResNet101\u003C\u002Ftd>\u003Ctd>768\u003C\u002Ftd>\u003Ctd>3072\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\u003Ctd>6\u003C\u002Ftd>\u003Ctd>6\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Large\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_large.pt\">下载\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>4.7 亿\u003C\u002Ftd>\u003Ctd>ResNet152\u003C\u002Ftd>\u003Ctd>1024\u003C\u002Ftd>\u003Ctd>4096\u003C\u002Ftd>\u003Ctd>16\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Huge\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_huge.pt\">下载\u003C\u002Fa>\u003C\u002Ftd>\u003Ctd>9.3 亿\u003C\u002Ftd>\u003Ctd>ResNet152\u003C\u002Ftd>\u003Ctd>1280\u003C\u002Ftd>\u003Ctd>5120\u003C\u002Ftd>\u003Ctd>16\u003C\u002Ftd>\u003Ctd>24\u003C\u002Ftd>\u003Ctd>12\u003C\u002Ftd>\n    \u003C\u002Ftr>\n\u003C\u002Ftable>\n\u003Cbr>\u003C\u002Fbr>\n\n# 结果\n下面我们展示了 OFA 在跨模态理解和生成任务上的结果。\n\n\u003Ctable border=\"1\" width=\"100%\">\n    \u003Ctr align=\"center\">\n        \u003Cth>任务\u003C\u002Fth>\u003Cth>图像字幕生成\u003C\u002Fth>\u003Cth>VQA\u003C\u002Fth>\u003Cth>视觉蕴含\u003C\u002Fth>\u003Cth colspan=\"3\">指代表达理解\u003C\u002Fth>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>数据集\u003C\u002Ftd>\u003Ctd>COCO\u003C\u002Ftd>\u003Ctd>VQA v2\u003C\u002Ftd>\u003Ctd>SNLI-VE\u003C\u002Ftd>\u003Ctd>RefCOCO\u003C\u002Ftd>\u003Ctd>RefCOCO+\u003C\u002Ftd>\u003Ctd>RefCOCOg\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>划分\u003C\u002Ftd>\u003Ctd>Karpathy 测试集 (CE\u002FCIDEr)\u003C\u002Ftd>\u003Ctd>test-dev\u002Ftest-std\u003C\u002Ftd>\u003Ctd>val\u002Ftest\u003C\u002Ftd>\u003Ctd>val\u002Ftest-a\u002Ftest-b\u003C\u002Ftd>\u003Ctd>val\u002Ftest-a\u002Ftest-b\u003C\u002Ftd>\u003Ctd>val-u\u002Ftest-u\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>指标\u003C\u002Ftd>\u003Ctd>CIDEr\u003C\u002Ftd>\u003Ctd>准确率\u003C\u002Ftd>\u003Ctd>准确率\u003C\u002Ftd>\u003Ctd colspan=\"3\">准确率\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Tiny\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>119.0 \u002F 128.7\u003C\u002Ftd>\u003Ctd>70.3 \u002F 70.4\u003C\u002Ftd>\u003Ctd>85.3 \u002F 85.2\u003C\u002Ftd>\u003Ctd>80.20 \u002F 84.07 \u002F 75.00\u003C\u002Ftd>\u003Ctd>68.22 \u002F 75.13 \u002F 57.66\u003C\u002Ftd>\u003Ctd>72.02 \u002F 69.74\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Medium\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>130.4 \u002F 140.3\u003C\u002Ftd>\u003Ctd>75.4 \u002F 75.5\u003C\u002Ftd>\u003Ctd>86.6 \u002F 87.0\u003C\u002Ftd>\u003Ctd>85.34 \u002F 87.68 \u002F 77.92\u003C\u002Ftd>\u003Ctd>76.09 \u002F 83.04 \u002F 66.25\u003C\u002Ftd>\u003Ctd>78.76 \u002F 78.58\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Base\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>138.2 \u002F 146.7\u003C\u002Ftd>\u003Ctd>78.0 \u002F 78.1\u003C\u002Ftd>\u003Ctd>89.3 \u002F 89.2\u003C\u002Ftd>\u003Ctd>88.48 \u002F 90.67 \u002F 83.30\u003C\u002Ftd>\u003Ctd>81.39 \u002F 87.15 \u002F 74.29\u003C\u002Ftd>\u003Ctd>82.29 \u002F 82.31\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Large\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>142.2 \u002F 150.7\u003C\u002Ftd>\u003Ctd>80.4 \u002F 80.7\u003C\u002Ftd>\u003Ctd>90.3 \u002F 90.2\u003C\u002Ftd>\u003Ctd>90.05 \u002F 92.93 \u002F 85.26\u003C\u002Ftd>\u003Ctd>85.80 \u002F 89.87 \u002F 79.22\u003C\u002Ftd>\u003Ctd>85.89 \u002F 86.55\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr align=\"center\">\n        \u003Ctd>OFA\u003Csub>Huge\u003C\u002Fsub>\u003C\u002Ftd>\u003Ctd>145.3 \u002F 154.9\u003C\u002Ftd>\u003Ctd>82.0 \u002F 82.0\u003C\u002Ftd>\u003Ctd>91.0 \u002F 91.2\u003C\u002Ftd>\u003Ctd>92.04 \u002F 94.03 \u002F 88.44\u003C\u002Ftd>\u003Ctd>87.86 \u002F 91.70 \u002F 80.71\u003C\u002Ftd>\u003Ctd>88.07 \u002F 88.78\u003C\u002Ftd>\n    \u003C\u002Ftr>\n\u003C\u002Ftable>\n\u003Cbr>\u003C\u002Fbr>\n\n# 需求\n* python 3.7.4\n* pytorch 1.8.1\n* torchvision 0.9.1\n* JAVA 1.8（用于 COCO 评估）\n\u003Cbr>\u003C\u002Fbr>\n\n# 安装\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\npip install -r requirements.txt\n```\n\u003Cbr>\u003C\u002Fbr>\n\n# 数据集和检查点\n请参阅 [datasets.md](datasets.md) 和 [checkpoints.md](checkpoints.md)。\n\u003Cbr>\u003C\u002Fbr>\n\n# 训练与推理\n下面我们提供了在不同任务上进行训练和推理的方法。我们在 [checkpoints.md](checkpoints.md) 中提供了预训练的 OFA-Large 和 OFA-Base 模型。本节中提到的脚本是为 OFA-Large 准备的。为了复现 OFA-Base 的下游任务结果，我们也在 `run_scripts\u002F` 文件夹中提供了相应的微调和推理脚本。\n\n我们建议您的工作目录应按以下方式组织：\n```\nOFA\u002F\n├── checkpoints\u002F\n│   ├── ofa_base.pt\n│   ├── ofa_large.pt\n│   ├── caption_large_best_clean.pt\n│   └── ...\n├── criterions\u002F\n├── data\u002F\n├── dataset\u002F\n│   ├── caption_data\u002F\n│   ├── gigaword_data\u002F\n│   └── ...\n├── fairseq\u002F\n├── models\u002F\n├── run_scripts\u002F\n├── tasks\u002F\n├── train.py\n├── trainer.py\n└── utils\u002F\n```\n\n\n## 图像处理\n为了确保数据处理的效率，我们没有存储小文件大小的图像，而是将其编码为 base64 字符串。\n将图像文件转换为 base64 字符串非常简单。运行以下代码：\n```python\nfrom PIL import Image\nfrom io import BytesIO\nimport base64\n\nimg = Image.open(file_name) # 文件路径\nimg_buffer = BytesIO()\nimg.save(img_buffer, format=img.format)\nbyte_data = img_buffer.getvalue()\nbase64_str = base64.b64encode(byte_data) # 字节\nbase64_str = base64_str.decode(\"utf-8\") # 字符串\n```\n\n## 预训练\n下面我们提供了 OFA 的预训练方法。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        要预训练 OFA，您首先需要下载我们提供的数据集（\u003Ca href=\"https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fdatasets\u002Fpretrain_data\u002Fpretrain_data_examples.zip\">pretrain_data_examples.zip\u003C\u002Fa>, 是原始预训练数据的一个小子集）。对于您自定义的预训练数据集，请将您的训练样本准备成相同的格式。\u003Ccode>pretrain_data_examples.zip\u003C\u002Fcode> 包含 4 个 TSV 文件： \u003Ccode>vision_language_examples.tsv\u003C\u002Fcode>, \u003Ccode>text_examples.tsv\u003C\u002Fcode>, \u003Ccode>image_examples.tsv\u003C\u002Fcode> 和 \u003Ccode>detection_examples.tsv\u003C\u002Fcode>。这些文件的详细信息如下：\n        \u003Cbr \u002F>\n        \u003Cul type=\"circle\">\n            \u003Cli>\u003Cb>vision_language_examples.tsv\u003C\u002Fb>:\n每行包含唯一 ID、图像（base64 字符串）、字幕、问题、答案、真实物体（出现在字幕或问题中的物体）、数据来源名称以及任务类型（字幕、问答或视觉定位）。适用于视觉定位、基于上下文的字幕生成、图文匹配、图像字幕生成和视觉问答等预训练任务。\u003C\u002Fli>\n            \u003Cli>\u003Cb>text_examples.tsv\u003C\u002Fb>: 每行包含唯一 ID 和文本。适用于文本填充任务的预训练。\u003C\u002Fli> \n            \u003Cli>\u003Cb>image_examples.tsv\u003C\u002Fb>: 每行包含唯一 ID、图像（base64 字符串，需调整为 256*256 分辨率）和图像码（通过 VQ-GAN 为图像中心部分生成稀疏码）。适用于图像填充任务的预训练。\u003C\u002Fli>\n            \u003Cli>\u003Cb>detection_examples.tsv\u003C\u002Fb>: 每行包含唯一 ID、图像（base64 字符串）和边界框标注（包含边界框的左上角和右下角坐标、物体 ID 和物体名称，用逗号分隔）。适用于目标检测任务的预训练。\u003C\u002Fli>\n        \u003C\u002Ful>\n        此外，pretrain_data_examples.zip 中的 negative_sample 文件夹包含三个文件 \u003Ccode>all_captions.txt\u003C\u002Fcode>, \u003Ccode>object.txt\u003C\u002Fcode> 和 \u003Ccode>type2ans.json\u003C\u002Fcode>。这些文件中的数据被用作图文匹配（ITM）任务的负样本。\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 预训练\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        默认情况下，预训练脚本会尝试恢复已发布的 OFA-Base 或 OFA-Large 预训练检查点，并继续进行预训练。建议采用持续预训练的方式，相比从零开始预训练，效果要好得多。对于持续预训练，请提前下载预训练权重（见 \u003Ca href='checkpoints.md'>checkpoints.md\u003C\u002Fa>) 并将其放置在正确的目录 \u003Ccode>OFA\u002Fcheckpoints\u002F\u003C\u002Fcode> 中。否则，预训练将从零开始。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fpretraining\nbash pretrain_ofa_large.sh # 预训练 OFA-Large。对于 OFA-Base，使用 pretrain_ofa_base.sh\n\u003C\u002Fpre>\n    \u003Cp>\n        如果成功恢复了预训练的 OFA 检查点，您将在日志中看到以下信息：\n    \u003C\u002Fp>\n\u003Cpre>\nINFO: Loaded checkpoint ..\u002F..\u002Fcheckpoints\u002Fofa_large.pt\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## 图像字幕生成\n我们在下文的论文中提供了复现图像字幕生成结果的步骤。\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href='datasets.md'>datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href='checkpoints.md'>checkpoints.md\u003C\u002Fa>)，并将其放置到正确的目录中。数据集压缩包 \u003Ccode>caption_data.zip\u003C\u002Fcode> 包含 caption_stage1_train.tsv、caption_stage2_train.tsv、caption_val.tsv 和 caption_test.tsv。在 \u003Ccode>caption_stage1_train.tsv\u003C\u002Fcode> 中，每张图片仅对应 1 条字幕；而在其他 TSV 文件中，每张图片则对应多条字幕（平均每张图片约 5 条）。数据集中的每一行代表一个字幕样本，格式如下：唯一 ID、图片 ID、字幕、预测的物体标签（来自 \u003Ca href='https:\u002F\u002Fgithub.com\u002Fpzzhang\u002FVinVL'>VinVL\u003C\u002Fa>,未使用）、图片 Base64 字符串，各字段之间用制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n162365  12455   太阳从码头后的树林上落下。天空&&水&&码头&&杆  \u002F9j\u002F4AAQSkZJ....UCP\u002F2Q==\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        按照以往的标准做法，我们将图像字幕生成的微调过程分为两个阶段。在第一阶段，我们使用交叉熵损失在 4 张配备 32GB 显存的 NVIDIA-V100 GPU 上对 OFA 进行微调（预计在此阶段可在验证集上获得约 139.5 的 CIDEr 分数）。在第二阶段，我们选择第一阶段的最佳检查点，并在 8 张 NVIDIA-V100 GPU 上以 CIDEr 优化目标进行训练。\u003Cb>请注意，CIDEr 优化非常不稳定，需要仔细调整超参数。如果在第二阶段的微调过程中遇到训练错误，可以尝试增大批量大小或降低学习率。若仍无效，可以直接设置\u003C\u002Fb>\u003Ccode>--freeze-resnet\u003C\u002Fcode>\u003Cb>来冻结批归一化的内部状态。\u003C\u002Fb>\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fcaption\nnohup sh train_caption_stage1.sh > train_stage1.out &  # 第一阶段，使用交叉熵损失训练\nnohup sh train_caption_stage2.sh > train_stage2.out &  # 第二阶段，加载第一阶段的最佳检查点，并以 CIDEr 优化目标训练 \n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        运行以下命令以获取您的结果并评估您的模型。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fcaption ; sh evaluate_caption.sh  # 推理与评估\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## 文本到图像生成\n本部分提供了文本到图像生成的微调和推理步骤。详情如下。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa)，并将其放置到正确的目录中。数据集压缩包 \u003Ccode>coco_image_gen.zip\u003C\u002Fcode> 包含 \u003Ccode>coco_vqgan_train.tsv\u003C\u002Fcode>、\u003Ccode>coco_vqgan_dev.tsv\u003C\u002Fcode> 和 \u003Ccode>coco_vqgan_full_test.tsv\u003C\u002Fcode>。数据集中的每一行代表一个样本，格式如下：唯一 ID、图像编码（由 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FCompVis\u002Ftaming-transformers\">vqgan\u003C\u002Fa> 生成，由单个空格分隔的整数列表）、小写形式的字幕，各字段之间用制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n1\t6674 4336 4532 5334 3251 5461 3615 2469 ...4965 4190 1846\t人们正在摆姿势合影。\n\u003C\u002Fpre>\n    \u003Cp>\n        检查点压缩包 \u003Ccode>image_gen_large_best.zip\u003C\u002Fcode> 包含 \u003Ccode>image_gen_large_best.pt\u003C\u002Fcode>、\u003Ccode>vqgan\u002Flast.ckpt\u003C\u002Fcode>、\u003Ccode>vqgan\u002Fmodel.yaml\u003C\u002Fcode> 和 \u003Ccode>clip\u002FVit-B-16.pt\u003C\u002Fcode>。\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 打乱训练数据\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        （可选，但效果更好）：如果磁盘存储空间充足，建议提前为每个 epoch 准备打乱后的训练数据。\n    \u003C\u002Fp>\n\u003Cpre>\ncd dataset\u002Fimage_gen\nln coco_vqgan_train.tsv coco_vqgan_train_1.tsv\nfor idx in `seq 1 9`;do shuf coco_vqgan_train_${idx}.tsv > coco_vqgan_train_$[${idx}+1].tsv;done # 每个文件用于一个 epoch\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        按照以往的做法，我们将图像生成的微调过程分为两个阶段。在第一阶段，我们使用交叉熵损失在 4 台 8 张 V100-32G-GPU 的服务器上对 OFA 进行微调（预计在此阶段可在验证集上获得约 32.5+ 的 CLIP 分数）。在第二阶段，我们选择第一阶段的最后一份检查点，并在 4 台 8 张 V100-32G-GPU 的服务器上以 CLIP 分数优化目标进行训练（预计在此阶段可在验证集上获得约 34.0+ 的 CLIP 分数）。在验证过程中，生成的图像将被保存到 \u003Ccode>_GEN_IMAGE_PATH_\u003C\u002Fcode>。\n    \u003C\u002Fp>\n\u003Cpre>\n# 在按照 train_image_gen_stage1_distributed.sh 中的指南正确设置分布式和数据配置后，在每个工作节点上运行\ncd run_scripts\u002Fimage_gen\nnohup sh train_image_gen_stage1_distributed.sh # 第一阶段，使用交叉熵损失训练\nnohup sh train_image_gen_stage2_distributed.sh # 第二阶段，加载第一阶段的最后一份检查点，并以 CLIP 分数优化目标训练 \n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>4. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        运行下方命令以生成您的图像。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fimage_gen ; sh evaluate_image_gen.sh  # 推理与评估（FID、IS 和 CLIP 分数）\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## 视觉问答\n在这里，我们提供了微调和推理代码，以复现我们论文中报告的 VQAv2 结果（**test-std 80.02**）。我们相信，基于这个代码库，准确率还有很大的提升空间 :)\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>）和模型（参见 \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>），并将它们放置在正确的目录中。数据集压缩包 \u003Ccode>vqa_data.zip\u003C\u002Fcode> 大约 100G，解压后占用约 135G 的磁盘空间，其中包含了训练、验证和测试样本以及其他必要的数据资源。（由于 \u003Ccode>vqa_data.zip\u003C\u002Fcode> 文件较大，我们还提供了分块的数据文件，以便更方便、更稳定地下载。请参考 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F68#issuecomment-1096837349\">issue #68\u003C\u002Fa>。）按照惯例，VG-QA 样本也被纳入了训练数据。为了适配 OFA 的序列到序列范式，我们将原始 VQA 训练问题中包含多个正确答案的情况转换为多个训练样本。对于原始的 VQA 验证集，我们保留大约 1 万个样本用于验证，并将其他样本用于训练。数据集中的每一行代表一个 VQA 样本，格式如下：question-id、image-id、问题、答案（带置信度）、预测的物体标签（来自 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fpzzhang\u002FVinVL\">VinVL\u003C\u002Fa>, 可带来约 +0.1 的准确率提升）、图像 base64 字符串，各字段之间用制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n79459   79459   这个人穿短裤吗？  0.6|!+no    house&&short&&...&&sky  \u002F9j\u002F4AAQS...tigZ\u002F9k=\n\u003C\u002Fpre>\n    \u003Cp>\n        如果需要针对自定义的 VQA 任务进行微调，请参阅 issue \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F76\">#76\u003C\u002Fa>、\u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F105\">#105\u003C\u002Fa> 和 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F73\">#73\u003C\u002Fa> 获取更多信息。\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 打乱训练数据\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        （可选，但能提高微调准确率）：如果磁盘空间充足，我们建议提前为每个 epoch 准备打乱后的训练数据。在我们的实验中，使用打乱数据的方法可以使 VQA 准确率提升约 \u003Cb>+0.3\u003C\u002Fb>。\n    \u003C\u002Fp>\n\u003Cpre>\ncd dataset\u002Fvqa_data\nln vqa_train.tsv vqa_train_1.tsv\nfor idx in `seq 1 9`;do shuf vqa_train_${idx}.tsv > vqa_train_$[${idx}+1].tsv;done # each file is used for an epoch\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        在我们的实验中，VQA 微调是在 4 台配备 8 张 A100 GPU 的服务器上进行的（\u003Ci>带有 RDMA\u003C\u002Fi>）。这里提供了微调脚本 \u003Ccode>train_vqa_distributed.sh\u003C\u002Fcode>,支持多机分布式训练（也支持单机训练）。请参考脚本开头的注释，并根据您的分布式环境正确设置配置。如果您在上一步中已经打乱了训练数据，请按照脚本注释中的指南正确指定训练数据路径。\u003Cb>该命令应在每台工作节点上执行。\u003C\u002Fb>\n    \u003C\u002Fp>\n\u003Cpre>\n# 在按照 train_vqa_distributed.sh 中的指南正确设置分布式和数据配置后，在每台工作节点上运行\ncd run_scripts\u002Fvqa\nbash train_vqa_distributed.sh \n\u003C\u002Fpre>\n    \u003Cp>\n        在我们的实验中，微调大约耗时 36 小时（共 12 个 epoch）。每个 epoch 结束后都会在验证集上进行评估。微调过程中最佳的验证准确率约为 80.8。日志会保存在 \u003Ccode>${log_dir}\u003C\u002Fcode> 中。\n    \u003C\u002Fp>\n    \u003Cp>\n        \u003Ci>（关于验证耗时的更新）\u003C\u002Fi> 如将在 \u003Ci>4. 推理\u003C\u002Fi> 节中提到的那样，我们准备了两种推理方式：束搜索和全候选推理。默认情况下，微调期间的验证采用全候选推理，这种方式虽然准确率更高，但耗时较长。现在我们在训练脚本中增加了一个名为 \u003Ccode>--val-inference-type\u003C\u002Fcode> 的新选项，用于切换微调期间的验证推理类型。如果您觉得验证耗时过长，可以参考 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fpull\u002F79\">PR #79\u003C\u002Fa> 启用束搜索验证，这样可以显著减少时间消耗，不过相比全候选验证，准确率会下降约 0.5–0.6。\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>4. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        我们提供两种推理方式：\u003Cb>束搜索\u003C\u002Fb>（速度更快，但准确率稍低）和 \u003Cb>全候选评估\u003C\u002Fb>（速度较慢，但准确率最高）。\u003Cbr>\u003C\u002Fbr>\n        对于束搜索推理，使用脚本 \u003Ccode>evaluate_vqa_beam.sh\u003C\u002Fcode>。请参考以下命令。在测试集上的推理大约需要 16 个 GPU 小时。推理完成后，结果 JSON 文件会保存在 shell 脚本中定义的 \u003Ccode>${result_path}\u003C\u002Fcode> 目录下。您可以将结果文件 \u003Ccode>test_predict.json\u003C\u002Fcode> 提交到 \u003Ca href=\"https:\u002F\u002Feval.ai\u002Fweb\u002Fchallenges\u002Fchallenge-page\u002F830\u002Foverview\">EvalAI\u003C\u002Fa>。使用我们发布的微调检查点，束搜索推理可以获得 80.15 的验证准确率、79.36 的 test-dev 准确率以及 79.48 的 test-std 准确率（比全候选评估低约 0.6）。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fvqa\nbash evaluate_vqa_beam.sh val # 指定 'val' 或 'test'\n\u003C\u002Fpre>\n    \u003Cp>\n        对于全候选评估，我们建议使用分布式脚本 \u003Ccode>evaluate_vqa_allcand_distributed.sh\u003C\u002Fcode>。请在运行前参考脚本中的说明设置分布式配置。结果 JSON 文件会保存在 rank-0 服务器的 shell 脚本中定义的 \u003Ccode>${result_path}\u003C\u002Fcode> 目录下。全候选评估会计算 VQA 数据集中所有候选答案的得分，从而达到 \u003Cb>80.82\u003C\u002Fb> 的验证准确率、\u003Cb>79.87\u003C\u002Fb> 的 test-dev 准确率以及 \u003Cb>80.02\u003C\u002Fb> 的 test-std 准确率，复现我们论文中报告的结果。然而，对测试集的推理大约需要 1000 个 GPU 小时，速度较慢。\n    \u003C\u002Fp>\n\u003Cpre>\n# 在按照 evaluate_vqa_allcand_distributed.sh 中的指南正确设置分布式配置后，在每台工作节点上运行\ncd run_scripts\u002Fvqa\nbash evaluate_vqa_allcand_distributed.sh val # 指定 'val' 或 'test'\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## 视觉定位（指代表达理解）\n这里提供了在视觉定位任务上准备数据、训练和评估模型的步骤。\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href='datasets.md'>datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href='checkpoints.md'>checkpoints.md\u003C\u002Fa>)，并将其放置到正确的目录中。我们提供了 RefCOCO（UNC 分割）、RefCOCO+（UNC 分割）和 RefCOCOg（UMD 分割）数据集。更多详情请参阅 \u003Ca href='https:\u002F\u002Fwww.tensorflow.org\u002Fdatasets\u002Fcatalog\u002Fref_coco'>RefCOCO\u003C\u002Fa> 和 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Flichengunc\u002Frefer\">Refer\u003C\u002Fa>。请注意，在原始数据集中，每个区域坐标（或边界框）可能对应多个描述性文本。我们将这些文本拆分为多个样本，使得每个样本中的区域坐标仅对应一个文本。处理后的数据集每行代表一个样本，格式如下：uniq-id、image-id、文本、区域坐标（以逗号分隔）以及图像的 Base64 编码字符串，各字段之间用制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n79_1    237367  一位身穿白色衬衫的女子手持一杯葡萄酒。  230.79,121.75,423.66,463.06 9j\u002F4AAQ...1pAz\u002F9k=\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        与原论文不同，我们使用 0.2 的丢弃路径率对 OFA 进行微调，并发现采用该超参数进行训练可以获得更好的效果。我们将在稍后更新论文中报告的结果。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Frefcoco\nnohup sh train_refcoco.sh > train_refcoco.out &  # 针对 refcoco 进行微调\nnohup sh train_refcocoplus.sh > train_refcocoplus.out &  # 针对 refcoco+ 进行微调\nnohup sh train_refcocog.sh > train_refcocog.out &  # 针对 refcocog 进行微调\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        运行以下命令进行评估。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Frefcoco ; sh evaluate_refcoco.sh  # 针对 refcoco\u002Frefcoco+\u002Frefcocog 进行推理与评估\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## 视觉蕴含\n我们提供了复现视觉蕴含任务结果的步骤，具体如下。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>)，并将其放置到正确的目录中。处理后的数据集每行代表一个样本，格式如下：uniq-id、image-id、图像 Base64 编码字符串、假设、标题（或文本前提）以及标签，各字段之间用制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n252244149.jpg#1r1n  252244149   \u002F9j\u002F4AAQ...MD\u002F2Q==   一位身穿粉金色衣服的男子正在咀嚼一根木制牙签。   地铁上，一位身穿粉色衣服的男子正在咀嚼牙签。   中性 \n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        在我们的实验中，SNLI-VE 的微调是在 8 张配备 32GB 显存的 NVIDIA-V100 GPU 上进行的。在此任务中，我们仅尝试了几组超参数。我们认为，适当的超参数调优可以进一步提升准确率。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fsnli_ve\nnohup sh train_snli_ve.sh > train_snli_ve.out &  # 针对 snli_ve 进行微调\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        运行以下命令以获取结果。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fsnli_ve ; sh evaluate_snli_ve.sh dev  # 指定 'dev' 或 'test'\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n   \n## GLUE\n这里提供了在语言理解任务上对我们的模型进行微调和评估的步骤。我们以 GLUE 基准测试为例展示了具体实践。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>)，并将其放置到正确的目录中。我们提供了来自 GLUE 基准测试的 7 个语言理解数据集，包括 COLA、MNLI、MRPC、QNLI、QQP、RTE 和 SST2。有关这些数据集的更多详细信息，请参阅此 \u003Ca href=\"https:\u002F\u002Fopenreview.net\u002Fpdf?id=rJ4km2R5t7\">链接\u003C\u002Fa>。\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        对于每个任务，我们尝试了多组超参数（包括学习率、批量大小、训练轮数）。不同超参数设置下的结果可在 \u003Ccode>${log_dir}\u003C\u002Fcode> 中找到。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fglue\nnohup sh train_cola.sh > train_cola.out &  # 针对 cola 进行微调\nnohup sh train_mnli.sh > train_mnli.out &  # 针对 mnli 进行微调\nnohup sh train_mrpc.sh > train_mrpc.out &  # 针对 mrpc 进行微调\nnohup sh train_qnli.sh > train_qnli.out &  # 针对 qnli 进行微调\nnohup sh train_qqp.sh > train_qqp.out &  # 针对 qqp 进行微调\nnohup sh train_rte.sh > train_rte.out &  # 针对 rte 进行微调\nnohup sh train_sst2.sh > train_sst2.out &  # 针对 sst2 进行微调\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## ImageNet-1K 上的图像分类\n我们提供了微调和推理代码，能够复现 **85.0 的 ImageNet-1K 准确率**，略高于我们在论文中报告的结果。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa>)，并将它们放置到正确的目录中。我们提供的数据源自原始的 \u003Ca href=\"http:\u002F\u002Fimage-net.org\u002F\">ImageNet-1K\u003C\u002Fa> (ILSVRC2012 训练集与验证集) 数据集，并与其保持相同的数据划分。为了将分类任务转化为序列到序列范式，我们使用 Caffe 提供的 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FHoldenCaulfieldRye\u002Fcaffe\u002Fblob\u002Fmaster\u002Fdata\u002Filsvrc12\u002Fsynset_words.txt\">synset 词汇\u003C\u002Fa> 作为每个图像类别的生成目标。处理后的数据集中，每行代表一个样本，格式如下：图像的 base64 编码字符串、分类标签（从 1 开始计数，与 \u003Ccode>synset_words.txt\u003C\u002Fcode> 中的顺序一致）以及该标签对应的 synset 词汇，三者之间以制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n_9j_4AAQS...fzX__Z  769 橄榄球\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 打乱训练数据\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        （可选，但能提升微调准确率）：如果磁盘存储空间充足，我们建议提前为每个 epoch 准备好打乱顺序的训练数据。在我们的实验中，采用打乱顺序的方式使 ImageNet-1K 准确率提升了约 \u003Cb>+0.2\u003C\u002Fb>。\n    \u003C\u002Fp>\n\u003Cpre>\ncd dataset\u002Fimagenet_1k_data\nln imagenet_1k_train.tsv imagenet_1k_train_1.tsv\nfor idx in `seq 1 9`;do shuf imagenet_1k_train_${idx}.tsv > imagenet_1k_train_$[${idx}+1].tsv;done # 每个文件依次用于一个 epoch\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        在我们的实验中，ImageNet-1K 的微调是在两台配备 8 张 A100 GPU 的服务器上进行的（\u003Ci>支持 RDMA\u003C\u002Fi>)。这里提供微调脚本 \u003Ccode>train_imagenet_distributed.sh\u003C\u002Fcode>,它支持多机分布式训练（同时也支持单机训练）。请参考脚本开头的注释，并根据您的分布式环境正确设置配置。如果您在上一步中已经对训练数据进行了打乱，请按照脚本注释中的指引正确指定训练数据路径。\u003Cb>该命令应在每台工作节点上执行。\u003C\u002Fb> 为了在微调过程中快速评估，我们默认会从原始验证集划分出 20% 的子集，并在每个 epoch 结束后报告该子集上的准确率。验证子集上的准确率通常与完整验证集上的准确率相差 ±0.1。\n    \u003C\u002Fp>\n\u003Cpre>\n# 在按照 train_imagenet_distributed.sh 中的指南正确设置分布式及数据配置后，在每台工作节点上运行\ncd run_scripts\u002Fimage_classify\nbash train_imagenet_distributed.sh\n\u003C\u002Fpre>\n    \u003Cp>\n        在我们的实验中，微调大约耗时 80 小时（共 32 个 epoch）。微调过程中验证子集上的最佳准确率约为 85.0。日志会保存在 \u003Ccode>${log_dir}\u003C\u002Fcode> 目录下。\n    \u003C\u002Fp>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>4. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        若要获得完整的 ImageNet-1K 验证集上的准确率，请运行以下命令。评估大约需要 10 个 GPU 小时。准确率将在标准输出中显示（预计约为 \u003Cb>85.0\u003C\u002Fb>)。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fimage_classify ; sh evaluate_imagenet.sh  # 对 ImageNet-1K 进行推理与评估\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n## Gigaword\n我们提供了复现 Gigaword 数据集上结果的步骤，详情如下。\n\n\u003Cdetails>\n    \u003Csummary>\u003Cb>1. 准备数据集与检查点\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        下载数据（参见 \u003Ca href=\"datasets.md\">datasets.md\u003C\u002Fa>) 和模型（参见 \u003Ca href=\"checkpoints.md\">checkpoints.md\u003C\u002Fa)，并将它们放置到正确的目录中。原始数据集来自 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Funilm\u002F\">UniLM\u003C\u002Fa>，我们将其整理为 tsv 格式。处理后的数据集中，每行代表一个样本，格式如下：源文本和目标文本之间以制表符分隔。\n    \u003C\u002Fp>\n\u003Cpre>\n工厂订单在九月份增长了 #.#%... 美国九月份工厂订单增长了 #.#%\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>2. 微调\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        运行以下命令来训练模型。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fgigaword\nnohup sh train_gigaword.sh > train_gigaword.out &  # 为 Gigaword 进行微调\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\u003Cdetails>\n    \u003Csummary>\u003Cb>3. 推理\u003C\u002Fb>\u003C\u002Fsummary>\n    \u003Cp>\n        运行以下命令以获取结果（约 36.43 的 rougeL 分数）。\n    \u003C\u002Fp>\n\u003Cpre>\ncd run_scripts\u002Fgigaword ; sh evaluate_gigaword.sh  # 对 Gigaword 进行推理与评估\n\u003C\u002Fpre>\n\u003C\u002Fdetails>\n\n\u003Cbr>\u003C\u002Fbr>\n\n# 图库\n下面我们展示了 OFA 在文本到图像生成和开放式 VQA 方面的示例。此外，我们还演示了它在未见过的任务（Grounded QA）以及未见过的领域（来自未知领域的图像视觉定位）中的表现。\n\n## 文本到图像生成\n\n![case1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_a116a7bacfd7.png)\n\n\n## 开放式 VQA\n![open_vqa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_a869889f4a70.png)\n\n## Grounded QA（未见过的任务）\n![grounded_qa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_ef406dd0055a.png)\n\n## 视觉定位（未见过的领域）\n![vg](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_readme_865522ee0471.png)\n\u003Cbr>\u003C\u002Fbr>\n\n# 相关代码库\n* [Fairseq](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Ffairseq)\n* [taming-transformers](https:\u002F\u002Fgithub.com\u002FCompVis\u002Ftaming-transformers)\n\u003Cbr>\u003C\u002Fbr>\n\n\n# 参与方式\n欢迎提交 GitHub 问题或拉取请求。我们非常欢迎各位为本项目贡献力量！\n\n如需联系我们，请随时发送邮件至 `zheluo.wp@alibaba-inc.com` 或 `junyang.ljy@alibaba-inc.com`！\n\u003Cbr>\u003C\u002Fbr>\n\n# 引用\n如果您觉得我们的论文有帮助，请引用它们 :)\n\n```\n@article{wang2022ofa,\n  author    = {Peng Wang and\n               An Yang and\n               Rui Men and\n               Junyang Lin and\n               Shuai Bai and\n               Zhikang Li and\n               Jianxin Ma and\n               Chang Zhou and\n               Jingren Zhou and\n               Hongxia Yang},\n  title     = {OFA: 通过一个简单的序列到序列学习框架统一架构、任务和模态},\n  journal   = {CoRR},\n  volume    = {abs\u002F2202.03052},\n  year      = {2022}\n}\n```\n\u003Cbr>\u003C\u002Fbr>\n```\n@article{ofa_ocr,\n  author       = {Junyang Lin and\n                  Xuancheng Ren and\n                  Yichang Zhang and\n                  Gao Liu and\n                  Peng Wang and\n                  An Yang and\n                  Chang Zhou},\n  title        = {将通用多模态预训练模型迁移到文本识别},\n  journal      = {CoRR},\n  volume       = {abs\u002F2212.09297},\n  year         = {2022}\n}\n```\n\u003Cbr>\u003Cbr>\n```\n@article{ofa_prompt,\n  author       = {Hao Yang and\n                  Junyang Lin and\n                  An Yang and\n                  Peng Wang and\n                  Chang Zhou and\n                  Hongxia Yang},\n  title        = {面向生成式多模态预训练模型的提示调优},\n  journal      = {CoRR},\n  volume       = {abs\u002F2208.02532},\n  year         = {2022}\n}\n```\n\u003Cbr>\u003Cbr>\n```\n@article{mmspeech,\n  title={MMSpeech: 面向语音识别的多模态多任务编码器-解码器预训练},\n  author={Zhou, Xiaohuan and Wang, Jiaming and Cui, Zeyu and Zhang, Shiliang and Yan, Zhijie and Zhou, Jingren and Zhou, Chang},\n  journal={arXiv 预印本 arXiv:2212.00500},\n  year={2022}\n}\n```","# OFA 快速上手指南\n\nOFA 是一个统一的序列到序列预训练模型，支持**中文**和**英文**。它能够统一处理多模态（跨模态、视觉、语言）和多任务（支持微调和提示微调），涵盖图像描述、视觉问答、视觉定位、文生图、文本分类等任务。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux (推荐 Ubuntu 18.04+)\n- **Python**: 3.7 - 3.9\n- **GPU**: 支持 CUDA 的 NVIDIA GPU (显存建议 16GB+ 以运行 Large\u002FHuge 模型)\n- **CUDA**: 10.2 或更高版本\n\n### 前置依赖\n确保已安装以下基础库：\n- PyTorch >= 1.8.0\n- Fairseq (OFA 基于此框架)\n- torchvision\n- PIL (Pillow)\n- regex\n- sacrebleu\n\n## 安装步骤\n\n### 1. 克隆代码仓库\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA.git\ncd OFA\n```\n\n### 2. 安装依赖\n推荐使用国内镜像源加速安装：\n\n```bash\n# 创建虚拟环境 (可选但推荐)\npython -m venv ofa_env\nsource ofa_env\u002Fbin\u002Factivate\n\n# 使用 pip 安装依赖 (使用清华源加速)\npip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n\n# 如果 requirements.txt 未包含 fairseq，请手动安装指定版本\npip install fairseq==0.12.2 -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n> **注意**：部分旧版依赖可能需要根据具体报错调整 PyTorch 和 Fairseq 的版本兼容性。\n\n### 3. 下载预训练模型\nOFA 提供多种尺寸的模型（Tiny, Medium, Base, Large, Huge）。您可以从官方链接或 Hugging Face 下载。\n\n**下载地址参考：**\n- **官方 OSS (国内访问较快)**: [查看 checkpoints.md](checkpoints.md)\n- **Hugging Face**: https:\u002F\u002Fhuggingface.co\u002FOFA-Sys\n\n例如，下载 **OFA-Large** 英文预训练权重：\n```bash\nwget https:\u002F\u002Fofa-beijing.oss-cn-beijing.aliyuncs.com\u002Fcheckpoints\u002Fofa_large.pt\n```\n\n若需使用**中文模型**，请下载 [checkpoints_cn.md](checkpoints_cn.md) 中提供的权重，并在运行时配置 `bpe_dir=..\u002F..\u002Futils\u002FBERT_CN_dict` 和 `bpe=bert`。\n\n## 基本使用\n\n以下以**图像描述生成 (Image Captioning)** 为例，展示如何使用微调后的模型进行推理。\n\n### 1. 准备数据\n确保你有一张测试图片，例如 `example.jpg`。\n\n### 2. 运行推理脚本\n使用提供的 `generate.sh` 或 Python 脚本进行推理。以下是基于命令行调用的简化示例：\n\n```bash\n# 设置变量\nCHECKPOINT_PATH=\"ofa_large.pt\" # 替换为你下载的权重路径\nDATA_DIR=\"coco_caption\"        # 数据集目录 (推理时可指向包含单张图片的目录结构)\nRESULT_PATH=\"caption_result.txt\"\n\n# 执行推理命令\npython generate.py \\\n    --path=${CHECKPOINT_PATH} \\\n    --task=image_captioning \\\n    --gen-subset=test \\\n    --beam=5 \\\n    --max-len-b=20 \\\n    --seed=7 \\\n    --data=${DATA_DIR} \\\n    --results-path=${RESULT_PATH} \\\n    --batch-size=10 \\\n    --fp16\n```\n\n### 3. 使用 Hugging Face Transformers (替代方案)\nOFA 已集成到 Hugging Face `transformers` 库中，使用更为便捷：\n\n```python\nfrom transformers import OFAForConditionalGeneration, AutoTokenizer\nfrom PIL import Image\nimport torch\n\n# 加载模型和分词器\nmodel = OFAForConditionalGeneration.from_pretrained(\"OFA-Sys\u002Fofa-large-caption\")\ntokenizer = AutoTokenizer.from_pretrained(\"OFA-Sys\u002Fofa-large-caption\")\n\n# 准备图片\nimage = Image.open(\"example.jpg\").convert(\"RGB\")\n\n# 构建输入\nprompt = \" what does the image describe?\"\ninputs = tokenizer(images=[image], text=prompt, return_tensors=\"pt\")\n\n# 生成描述\ngenerated_ids = model.generate(**inputs, max_length=20)\ncaption = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]\n\nprint(caption)\n```\n\n### 4. 在线体验\n如果不方便本地部署，可直接访问以下在线 Demo 进行测试：\n- **图像描述**: [Hugging Face Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Image_Caption) | [ModelScope](https:\u002F\u002Fmodelscope.cn\u002F#\u002Fmodels\u002Fdamo\u002Fofa_image-caption_coco_large_en\u002Fsummary)\n- **视觉问答**: [Hugging Face Spaces](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FOFA-Sys\u002FOFA-Visual_Question_Answering)\n- **中文 OCR**: [ModelScope](https:\u002F\u002Fmodelscope.cn\u002Fstudios\u002Fdamo\u002Fofa_ocr_pipeline\u002Fsummary)","某电商平台的智能运营团队需要快速构建一套能同时处理商品图片描述生成、视觉问答客服以及多语言文本分类的综合系统。\n\n### 没有 OFA 时\n- **模型堆砌严重**：团队需分别训练和维护图像描述（Image Captioning）、视觉问答（VQA）和文本分类三个独立模型，导致显存占用高且部署架构复杂。\n- **数据孤岛效应**：不同任务的数据格式不统一，无法利用跨模态数据（如图文对）进行联合预训练，限制了模型在少样本场景下的泛化能力。\n- **开发迭代缓慢**：每新增一个任务（如视觉定位），都需要重新设计网络结构并从头训练，研发周期长达数周。\n- **多语言支持困难**：原有英文模型难以直接迁移到中文场景，需额外收集大量中文标注数据并单独训练中文版模型。\n\n### 使用 OFA 后\n- **统一架构部署**：利用 OFA 的序列到序列（Sequence-to-Sequence）框架，将图像描述、VQA 和分类任务整合进同一个预训练模型，显著降低推理成本和运维复杂度。\n- **跨模态知识共享**：通过统一的预训练机制，模型自动学习图文之间的深层关联，即使在特定任务标注数据较少时，也能凭借跨模态知识保持高精度。\n- **敏捷任务扩展**：新增视觉定位或文生图任务时，只需调整提示词（Prompt）或进行轻量级微调，无需改动核心架构，新功能上线时间缩短至几天。\n- **原生中英双语支持**：直接调用 OFA 内置的中英文双语能力，无需重复训练即可无缝切换语言场景，大幅提升了全球化业务的响应速度。\n\nOFA 通过“一个模型解决所有任务”的统一范式，彻底打破了模态与任务的壁垒，让多模态 AI 应用的开发从繁琐的“造轮子”转变为高效的“搭积木”。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOFA-Sys_OFA_a869889f.png","OFA-Sys","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FOFA-Sys_9eeb4d18.jpg","Unlocking the power of multimodal general AI. See more recent works of our group at https:\u002F\u002Fgithub.com\u002FQwenLM",null,"https:\u002F\u002Fgithub.com\u002FOFA-Sys",[78,82,86,90,94,98,102,106],{"name":79,"color":80,"percentage":81},"Python","#3572A5",92.8,{"name":83,"color":84,"percentage":85},"Shell","#89e051",5.9,{"name":87,"color":88,"percentage":89},"Cuda","#3A4E3A",0.6,{"name":91,"color":92,"percentage":93},"C++","#f34b7d",0.4,{"name":95,"color":96,"percentage":97},"Cython","#fedf5b",0.2,{"name":99,"color":100,"percentage":101},"Lua","#000080",0.1,{"name":103,"color":104,"percentage":105},"Batchfile","#C1F12E",0,{"name":107,"color":108,"percentage":105},"Makefile","#427819",2558,249,"2026-04-08T16:51:11","Apache-2.0","","未说明",{"notes":116,"python":114,"dependencies":117},"README 中未明确列出具体的运行环境配置（如操作系统、GPU 型号、显存大小、Python 版本及具体依赖库版本）。该项目基于 Fairseq 框架，支持 Hugging Face Transformers 推理，提供从 Tiny 到 Huge 多种参数量级的模型（33M-930M），不同模型规模对硬件资源需求差异较大。建议参考项目提供的 Colab 笔记本或 transformers.md 文档获取更详细的运行指南。",[118,119,120],"fairseq","torch","transformers",[122,35,14,15],"其他",[124,125,126,127,128,129,130,131,132,133,134],"multimodal","pretraining","image-captioning","text-to-image-synthesis","visual-question-answering","referring-expression-comprehension","vision-language","pretrained-models","prompt","prompt-tuning","chinese","2026-03-27T02:49:30.150509","2026-04-18T16:25:06.951349",[138,143,148,153,158,162],{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},40270,"是否支持通过 Hugging Face Transformers 库进行推理？","是的，OFA 已添加对 Transformers 的支持。目前仅支持推理，训练功能仍需进一步测试。您可以查看 \"feature\u002Fadd_transformers\" 分支下的 \"transformers\" 目录，并在 [Models](https:\u002F\u002Fhuggingface.co\u002FOFA-Sys) 下载对应的检查点。注意：部分用户反馈 Fairseq 版本与 HF 版本的推理结果可能存在差异（例如图像描述不一致），建议优先使用 Fairseq 版本以获得最佳效果，或仔细对比权重配置。","https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F15",{"id":144,"question_zh":145,"answer_zh":146,"source_url":147},40271,"微调 OFA-large 进行图像描述任务时，性能未达到预期怎么办？","如果微调后的 CIDEr 分数低于论文报告值（如阶段一约为 139.3 而非 139.5），请尝试将 batch size 设置为 512。此外，确保验证和保存间隔合理，避免仅在 epoch 结束时验证而错过最佳检查点。对于 SNLI-VE 等任务，若性能仍偏低（约 82~83），请检查超参数设置是否与官方脚本一致，特别是学习率、warmup_ratio 和 drop_path_rate 等参数。","https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F300",{"id":149,"question_zh":150,"answer_zh":151,"source_url":152},40272,"如何评估经过 Prompt Tuning 训练的模型？","直接使用 `run_scripts\u002Fvqa\u002Fevaluate_vqa_beam.sh` 可能会报错。解决关键是正确处理 `key_padding_mask`。该参数用于指定注意力层中应忽略的填充元素：若提供二进制掩码，值为 True 的位置将被忽略；若为字节掩码，非零值将被忽略。请确保 key padding mask 的长度与键（key）保持一致，并用原始值填充。调整后即可正常运行评估脚本。","https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F313",{"id":154,"question_zh":155,"answer_zh":156,"source_url":157},40273,"加载预训练检查点时出现 ConfigAttributeError 错误如何解决？","该错误通常由于配置文件缺少特定属性（如 `scst`）导致。在加载模型时，需通过 `arg_overrides` 显式补充缺失配置。例如：\n```python\noverrides = {\"bpe_dir\": \"utils\u002FBPE\", \"scst\": False}\nmodels, cfg, task = checkpoint_utils.load_model_ensemble_and_task(\n    utils.split_paths('checkpoints\u002Frefcocog.pt'),\n    arg_overrides=overrides\n)\n```\n确保 overrides 中包含任务所需的所有配置项，尤其是自定义任务（如 refcoco）中新增的参数。","https:\u002F\u002Fgithub.com\u002FOFA-Sys\u002FOFA\u002Fissues\u002F78",{"id":159,"question_zh":160,"answer_zh":161,"source_url":142},40274,"Fairseq 版本与 Hugging Face 版本的推理结果为何不一致？","多个用户报告同一图像在 Fairseq 和 HF 版本下生成不同的描述（如“navy trousers”vs“blue and green”）。这可能源于两版本权重未完全对齐或预处理流程差异。目前官方尚未确认两者权重完全一致。建议在对结果一致性要求高的场景中优先使用 Fairseq 版本，并关注官方后续关于 HF 版本权重的更新说明。",{"id":163,"question_zh":164,"answer_zh":165,"source_url":147},40275,"SNLI-VE 任务微调后性能远低于论文数值，可能原因是什么？","性能偏低（如 82~83 而非更高）可能与以下因素有关：1) Batch size 过小（建议设为 512）；2) 验证频率太低，导致错过最佳检查点（不要仅在 epoch 结束时验证）；3) 超参数未复现论文设置，如学习率（3e-5）、warmup_ratio（0.06）、drop_path_rate 等。请参考官方提供的完整训练脚本，并逐步比对自身配置。",[]]