[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-adobe-research--custom-diffusion":3,"tool-adobe-research--custom-diffusion":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":79,"owner_twitter":79,"owner_website":80,"owner_url":81,"languages":82,"stars":91,"forks":92,"last_commit_at":93,"license":94,"difficulty_score":95,"env_os":96,"env_gpu":97,"env_ram":98,"env_deps":99,"category_tags":112,"github_topics":113,"view_count":121,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":122,"updated_at":123,"faqs":124,"releases":159},424,"adobe-research\u002Fcustom-diffusion","custom-diffusion","Custom Diffusion: Multi-Concept Customization of Text-to-Image Diffusion (CVPR 2023)","Custom Diffusion 是一个用于个性化文本到图像生成的开源工具，源自 CVPR 2023 的研究成果。它允许用户仅用 4 到 20 张图片，快速微调 Stable Diffusion 等扩散模型，让模型学会新概念（如特定物品、宠物或艺术风格），并能将这些概念灵活组合使用——例如同时生成“某只猫坐在某把椅子上”或“用特定画风绘制新物体”。  \n\n传统方法往往需要大量数据或完整模型重训，而 Custom Diffusion 通过仅微调交叉注意力层中的键（key）和值（value）投影矩阵，在约 6 分钟内完成训练（使用 2 块 A100 GPU），每个新概念仅增加约 75MB 存储开销，并配合少量正则化图像防止过拟合。  \n\n该工具适合 AI 研究人员、开发者及创意工作者使用，尤其适用于希望高效定制多概念图像生成能力的场景。目前官方已集成至 Hugging Face 的 diffusers 库，支持包括 SDXL 在内的主流模型，降低了使用门槛。","# Custom Diffusion\n\n### [website](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002F)  | [paper](http:\u002F\u002Farxiv.org\u002Fabs\u002F2212.04488) \n\n\n**[NEW!]** Custom Diffusion is now supported in diffusers. Please [refer](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Ftree\u002Fmain\u002Fexamples\u002Fcustom_diffusion) here for training and inference details. \n\n**[NEW!]** CustomConcept101 dataset. We release a new dataset of 101 concepts along with their evaluation prompts. For more details please refer [here](customconcept101\u002FREADME.md).  \n\n**[NEW!]** Custom Diffusion with SDXL. Diffusers code now with updated diffusers==0.21.4. \n\n\u003Cbr>\n\u003Cdiv class=\"gif\">\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_6b19fb53293e.gif' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n[Custom Diffusion](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion) allows you to fine-tune text-to-image diffusion models, such as [Stable Diffusion](https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion), given a few images of a new concept (~4-20). Our method is fast (~6 minutes on 2 A100 GPUs) as it fine-tunes only a subset of model parameters, namely key and value projection matrices, in the cross-attention layers. This also reduces the extra storage for each additional concept to 75MB.\n\nOur method further allows you to use a combination of multiple concepts such as new object + new artistic style, multiple new objects, and new object + new category. See [multi-concept results](#multi-concept-results) for more visual results. \n\n***Multi-Concept Customization of Text-to-Image Diffusion*** \u003Cbr>\n[Nupur Kumari](https:\u002F\u002Fnupurkmr9.github.io\u002F), [Bingliang Zhang](https:\u002F\u002Fzhangbingliang2019.github.io), [Richard Zhang](https:\u002F\u002Frichzhang.github.io\u002F), [Eli Shechtman](https:\u002F\u002Fresearch.adobe.com\u002Fperson\u002Feli-shechtman\u002F), [Jun-Yan Zhu](https:\u002F\u002Fwww.cs.cmu.edu\u002F~junyanz\u002F)\u003Cbr>\nIn CVPR 2023 \u003Cbr>\n\n\n\n## Results\n\nAll our results are based on fine-tuning [stable-diffusion-v1-4](https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original) model.\nWe show results on various categories of images, including scene, pet, personal toy, and style, and with a varying number of training samples. \nFor more generations and comparisons with concurrent methods, please refer to our [webpage](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002F) and [gallery](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fresults.html).\n\n\n### Single-Concept Results\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_d3f9b8c86f15.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_de6f7e6ca9a7.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_2903f4a91f04.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_e33b37637070.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_86f18deab441.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_e450c1d421c6.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_1f7b9006f5a7.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_ef0101119257.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n\n\n### Multi-Concept Results\n\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_c3a9bf729dd6.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_d088c4f60e3e.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_a8b00733036a.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_499dce75fb39.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n\n\n\n## Method Details\n\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_f4ca0adc0bf8.jpg' align=\"center\" width=900>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n\nGiven the few user-provided images of a concept, our method augments a pre-trained text-to-image diffusion model, enabling new generations of the concept in unseen contexts. \nWe fine-tune a small subset of model weights, namely the key and value mapping from text to latent features in the cross-attention layers of the diffusion model. \nOur method also uses a small set of regularization images (200) to prevent overfitting. For personal categories, we add a new modifier token V* in front of the category name, e.g., V* dog. For multiple concepts, we jointly train on the dataset for the two concepts. Our method also enables the merging of two fine-tuned models using optimization. For more details, please refer to our [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.04488).  \n\n## Getting Started\n\n```\ngit clone https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion.git\ncd custom-diffusion\ngit clone https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion.git\ncd stable-diffusion\nconda env create -f environment.yaml\nconda activate ldm\npip install clip-retrieval tqdm\n```\n\nOur code was developed on the following commit `#21f890f9da3cfbeaba8e2ac3c425ee9e998d5229` of [stable-diffusion](https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion).\n\nDownload the stable-diffusion model checkpoint\n`wget https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original\u002Fresolve\u002Fmain\u002Fsd-v1-4.ckpt`\nFor more details, please refer [here](https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original).\n\n**Dataset:** we release some of the datasets used in paper [here](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fdata.zip). \nImages taken from UnSplash are under [UnSplash LICENSE](https:\u002F\u002Funsplash.com\u002Flicense).\n\n**Models:** all our models can be downloaded from [here](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fmodels\u002F). \n\n### Single-Concept Fine-tuning\n\n**Real images as regularization**\n```\n## download dataset\nwget https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fdata.zip\nunzip data.zip\n\n## run training (30 GB on 2 GPUs)\nbash scripts\u002Ffinetune_real.sh \"cat\" data\u002Fcat real_reg\u002Fsamples_cat  cat finetune_addtoken.yaml \u003Cpretrained-model-path>\n\n## save updated model weights\npython src\u002Fget_deltas.py --path logs\u002F\u003Cfolder-name> --newtoken 1\n\n## sample\npython sample.py --prompt \"\u003Cnew1> cat playing with a ball\" --delta_ckpt logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fdelta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\nThe `\u003Cpretrained-model-path>` is the path to the pretrained `sd-v1-4.ckpt` model. Our results in the paper are not based on the [clip-retrieval](https:\u002F\u002Fgithub.com\u002From1504\u002Fclip-retrieval) for retrieving real images as the regularization samples. But this also leads to similar results.\n\n**Generated images as regularization**\n```\nbash scripts\u002Ffinetune_gen.sh \"cat\" data\u002Fcat gen_reg\u002Fsamples_cat  cat finetune_addtoken.yaml \u003Cpretrained-model-path>\n```\n\n\n### Multi-Concept Fine-tuning\n\n**Joint training**\n\n```\n## run training (30 GB on 2 GPUs)\nbash scripts\u002Ffinetune_joint.sh \"wooden pot\" data\u002Fwooden_pot real_reg\u002Fsamples_wooden_pot \\\n                                    \"cat\" data\u002Fcat real_reg\u002Fsamples_cat  \\\n                                    wooden_pot+cat finetune_joint.yaml \u003Cpretrained-model-path>\n\n## save updated model weights\npython src\u002Fget_deltas.py --path logs\u002F\u003Cfolder-name> --newtoken 2\n\n## sample\npython sample.py --prompt \"the \u003Cnew2> cat sculpture in the style of a \u003Cnew1> wooden pot\" --delta_ckpt logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fdelta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\n**Optimization based weights merging**\n\nGiven two fine-tuned model weights `delta_ckpt1` and `delta_ckpt2` for any two categories, the weights can be merged to create a single model as shown below.  \n```\npython src\u002FcomposenW.py --paths \u003Cdelta_ckpt1>+\u003Cdelta_ckpt2> --categories  \"wooden pot+cat\"  --ckpt \u003Cpretrained-model-path> \n\n## sample\npython sample.py --prompt \"the \u003Cnew2> cat sculpture in the style of a \u003Cnew1> wooden pot\" --delta_ckpt optimized_logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fdelta_epoch\\=000000.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\n\n### Training using Diffusers library\n\n**[NEW!]** Custom Diffusion is also supported in diffusers now. Please [refer](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Ftree\u002Fmain\u002Fexamples\u002Fcustom_diffusion) here for training and inference details. \n\n\n```\n## install requirements \npip install accelerate>=0.24.1\npip install modelcards\npip install transformers>=4.31.0\npip install deepspeed\npip install diffusers==0.21.4\naccelerate config\nexport MODEL_NAME=\"CompVis\u002Fstable-diffusion-v1-4\"\n```\n\n**Single-Concept fine-tuning**\n\n```\n## launch training script (2 GPUs recommended, increase --max_train_steps to 500 if 1 GPU)\n\naccelerate launch src\u002Fdiffusers_training.py \\\n          --pretrained_model_name_or_path=$MODEL_NAME  \\\n          --instance_data_dir=.\u002Fdata\u002Fcat  \\\n          --class_data_dir=.\u002Freal_reg\u002Fsamples_cat\u002F \\\n          --output_dir=.\u002Flogs\u002Fcat  \\\n          --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\\n          --instance_prompt=\"photo of a \u003Cnew1> cat\"  \\\n          --class_prompt=\"cat\" \\\n          --resolution=512  \\\n          --train_batch_size=2  \\\n          --learning_rate=1e-5  \\\n          --lr_warmup_steps=0 \\\n          --max_train_steps=250 \\\n          --num_class_images=200 \\\n          --scale_lr --hflip  \\\n          --modifier_token \"\u003Cnew1>\"\n\n## sample \npython src\u002Fdiffusers_sample.py --delta_ckpt logs\u002Fcat\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat playing with a ball\"\n```\n\nYou can also use `--enable_xformers_memory_efficient_attention` and enable `fp16` during `accelerate config` for faster training with lower VRAM requirement. To train with SDXL use `diffusers_training_sdxl.py` with `MODEL_NAME=\"stabilityai\u002Fstable-diffusion-xl-base-1.0\"`.\n\n**Multi-Concept fine-tuning**\n\nProvide a [json](assets\u002Fconcept_list.json) file with the info about each concept, similar to [this](https:\u002F\u002Fgithub.com\u002FShivamShrirao\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fdreambooth\u002Ftrain_dreambooth.py).\n```\n## launch training script (2 GPUs recommended, increase --max_train_steps to 1000 if 1 GPU)\n\naccelerate launch src\u002Fdiffusers_training.py \\\n          --pretrained_model_name_or_path=$MODEL_NAME  \\\n          --output_dir=.\u002Flogs\u002Fcat_wooden_pot  \\\n          --concepts_list=.\u002Fassets\u002Fconcept_list.json \\\n          --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\\n          --resolution=512  \\\n          --train_batch_size=2  \\\n          --learning_rate=1e-5  \\\n          --lr_warmup_steps=0 \\\n          --max_train_steps=500 \\\n          --num_class_images=200 \\\n          --scale_lr --hflip  \\\n          --modifier_token \"\u003Cnew1>+\u003Cnew2>\" \n\n## sample \npython src\u002Fdiffusers_sample.py --delta_ckpt logs\u002Fcat_wooden_pot\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat sitting inside a \u003Cnew2> wooden pot and looking up\"\n```\n\n**Optimization based weights merging for Multi-Concept**\n\nGiven two fine-tuned model weights `delta1.bin` and `delta2.bin` for any two categories, the weights can be merged to create a single model as shown below.  \n```\npython src\u002Fdiffusers_composenW.py --paths \u003Cdelta1.bin>+\u003Cdelta2.bin> --categories  \"wooden pot+cat\"  --ckpt \"CompVis\u002Fstable-diffusion-v1-4\"\n\n## sample\npython src\u002Fdiffusers_sample.py --delta_ckpt optimized_logs\u002F\u003Cfolder-name>\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat sitting inside a \u003Cnew2> wooden pot and looking up\"\n```\n\nThe diffuser training code is modified from the following [DreamBooth]( https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fdreambooth\u002Ftrain_dreambooth.py), [Textual Inversion](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Ftextual_inversion\u002Ftextual_inversion.py) training scripts. For more details on how to setup accelarate please refer [here](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fdreambooth).\n\n### Fine-tuning on human faces\n\nFor fine-tuning on human faces, we recommend `learning_rate=5e-6` and `max_train_steps=750` in the above diffuser training script or using `finetune_face.yaml` config in stable-diffusion training script. \n\nWe observe better results with a lower learning rate, longer training, and more images for human faces compared to other categories shown in our paper. With fewer images, fine-tuning all parameters in the cross-attention is slightly better, which can be enabled with `--freeze_model \"crossattn\"`.  \nExample results on fine-tuning with 14 close-up photos of [Richard Zhang](https:\u002F\u002Frichzhang.github.io\u002F) with the diffusers training script. \n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_87bddca3c633.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n### Model compression\n\n```\npython src\u002Fcompress.py --delta_ckpt \u003Cfinetuned-delta-path> --ckpt \u003Cpretrained-model-path>\n\n## sample\npython sample.py --prompt \"\u003Cnew1> cat playing with a ball\" --delta_ckpt logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fcompressed_delta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path> --compress\n```\n\nSample generations with different level of compression. By default our code saves the low-rank approximation with top 60% singular values to result in ~15 MB models. \n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_fc07f239be59.jpg' align=\"center\" width=900>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n### Checkpoint conversions for stable-diffusion-v1-4\n\n* From diffusers `delta.bin` to CompVis `delta_model.ckpt`. \n```\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta.bin --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode diffuser-to-compvis                  \n# sample\npython sample.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta_model.ckpt --ckpt \u003Cpath-to-model-v1-4.ckpt> --prompt \u003Ctext-prompt> --config configs\u002Fcustom-diffusion\u002Ffinetune_addtoken.yaml\n```\n\n* From diffusers `delta.bin` to [stable-diffusion-webui](https:\u002F\u002Fgithub.com\u002FAUTOMATIC1111\u002Fstable-diffusion-webui) checkpoint. \n```\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta.bin --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode diffuser-to-webui                  \n# launch UI in stable-diffusion-webui directory\nbash webui.sh --embeddings-dir \u003Cpath-to-folder>\u002Fwebui\u002Fembeddings  --ckpt \u003Cpath-to-folder>\u002Fwebui\u002Fmodel.ckpt\n```\n\n* From CompVis `delta_model.ckpt` to diffusers `delta.bin`. \n```\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta_model.ckpt --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode compvis-to-diffuser                  \n# sample\npython src\u002Fdiffusers_sample.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \u003Ctext-prompt>\n```\n\n* From CompVis `delta_model.ckpt` [stable-diffusion-webui](https:\u002F\u002Fgithub.com\u002FAUTOMATIC1111\u002Fstable-diffusion-webui) checkpoint. \n```\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta_model.ckpt --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode compvis-to-webui                  \n# launch UI in stable-diffusion-webui directory\nbash webui.sh --embeddings-dir \u003Cpath-to-folder>\u002Fwebui\u002Fembeddings  --ckpt \u003Cpath-to-folder>\u002Fwebui\u002Fmodel.ckpt\n```\nConverted checkpoints are saved in the `\u003Cpath-to-folder>` of the original checkpoints. \n\n\n## References\n\n```\n@article{kumari2022customdiffusion,\n  title={Multi-Concept Customization of Text-to-Image Diffusion},\n  author={Kumari, Nupur and Zhang, Bingliang and Zhang, Richard and Shechtman, Eli and Zhu, Jun-Yan},\n  booktitle = {Proceedings of the IEEE\u002FCVF Conference on Computer Vision and Pattern Recognition (CVPR)},\n  year      = {2023}\n}\n```\n\n## Acknowledgments\nWe are grateful to Nick Kolkin, David Bau, Sheng-Yu Wang, Gaurav Parmar, John Nack, and Sylvain Paris for their helpful comments and discussion, and to Allie Chang, Chen Wu, Sumith Kulal, Minguk Kang, Yotam Nitzan, and Taesung Park for proofreading the draft. We also thank Mia Tang and Aaron Hertzmann for sharing their artwork. Some of the datasets are downloaded from Unsplash. This work was partly done by Nupur Kumari during the Adobe internship. The work is partly supported by Adobe Inc. \n","# Custom Diffusion（自定义扩散）\n\n### [网站](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002F)  | [论文](http:\u002F\u002Farxiv.org\u002Fabs\u002F2212.04488) \n\n\n**[新功能！]** Custom Diffusion 现已支持 Hugging Face 的 diffusers 库。训练和推理的详细信息请[参见此处](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Ftree\u002Fmain\u002Fexamples\u002Fcustom_diffusion)。\n\n**[新功能！]** CustomConcept101 数据集。我们发布了一个包含 101 个概念及其评估提示（evaluation prompts）的新数据集。更多详情请参见[此处](customconcept101\u002FREADME.md)。\n\n**[新功能！]** 支持 SDXL 的 Custom Diffusion。diffusers 代码现已更新至 diffusers==0.21.4 版本。\n\n\u003Cbr>\n\u003Cdiv class=\"gif\">\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_6b19fb53293e.gif' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n[Custom Diffusion](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion) 允许你使用少量（约 4–20 张）新概念的图像对文本到图像扩散模型（如 [Stable Diffusion](https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion)）进行微调（fine-tune）。我们的方法速度很快（在 2 块 A100 GPU 上仅需约 6 分钟），因为它只微调模型参数的一个子集，即交叉注意力（cross-attention）层中的键（key）和值（value）投影矩阵。这也使得每个新增概念所需的额外存储空间仅为 75MB。\n\n我们的方法还支持组合多个概念，例如新物体 + 新艺术风格、多个新物体、新物体 + 新类别等。更多可视化结果请参见[多概念结果](#multi-concept-results)部分。\n\n***文本到图像扩散模型的多概念定制化*** \u003Cbr>\n[Nupur Kumari](https:\u002F\u002Fnupurkmr9.github.io\u002F)、[Bingliang Zhang](https:\u002F\u002Fzhangbingliang2019.github.io)、[Richard Zhang](https:\u002F\u002Frichzhang.github.io\u002F)、[Eli Shechtman](https:\u002F\u002Fresearch.adobe.com\u002Fperson\u002Feli-shechtman\u002F)、[Jun-Yan Zhu](https:\u002F\u002Fwww.cs.cmu.edu\u002F~junyanz\u002F)\u003Cbr>\nCVPR 2023\u003Cbr>\n\n\n\n## 结果\n\n我们所有的结果均基于对 [stable-diffusion-v1-4](https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original) 模型的微调。  \n我们在多种类别的图像上展示了结果，包括场景、宠物、个人玩具和艺术风格，并使用了不同数量的训练样本。  \n如需查看更多生成结果以及与同期方法的对比，请访问我们的[项目网页](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002F)和[图库](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fresults.html)。\n\n\n### 单概念结果\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_d3f9b8c86f15.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_de6f7e6ca9a7.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_2903f4a91f04.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_e33b37637070.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_86f18deab441.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_e450c1d421c6.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_1f7b9006f5a7.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_ef0101119257.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n\n\n### 多概念结果\n\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_c3a9bf729dd6.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_d088c4f60e3e.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_a8b00733036a.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_499dce75fb39.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n\n\n\n## 方法细节\n\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_f4ca0adc0bf8.jpg' align=\"center\" width=900>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n\n给定用户提供的少量某概念图像，我们的方法对预训练的文本到图像扩散模型进行增强，使其能够在未见过的上下文中生成该新概念。  \n我们仅微调模型权重的一小部分，即扩散模型交叉注意力层中从文本到潜在特征（latent features）的键（key）和值（value）映射。  \n我们的方法还使用一小批正则化图像（200 张）来防止过拟合。对于个人类别，我们在类别名称前添加一个新的修饰符 token V*，例如 V* dog。对于多个概念，我们在两个概念的数据集上联合训练。我们的方法还支持通过优化合并两个微调后的模型。更多细节请参阅我们的[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F2212.04488)。  \n\n## 快速开始\n\n```\ngit clone https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion.git\ncd custom-diffusion\ngit clone https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion.git\ncd stable-diffusion\nconda env create -f environment.yaml\nconda activate ldm\npip install clip-retrieval tqdm\n```\n\n我们的代码基于 [stable-diffusion](https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion) 的以下提交版本开发：`#21f890f9da3cfbeaba8e2ac3c425ee9e998d5229`。\n\n下载 Stable Diffusion 模型检查点：\n`wget https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original\u002Fresolve\u002Fmain\u002Fsd-v1-4.ckpt`  \n更多详情请参见[此处](https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original)。\n\n**数据集：** 我们在[此处](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fdata.zip)发布了论文中使用的一些数据集。  \n其中来自 UnSplash 的图像遵循 [UnSplash 许可证](https:\u002F\u002Funsplash.com\u002Flicense)。\n\n**模型：** 所有我们的模型均可从[此处](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fmodels\u002F)下载。\n\n### 单概念微调\n\n**使用真实图像作为正则化样本**\n```\n## 下载数据集\nwget https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fdata.zip\nunzip data.zip\n\n## 开始训练（占用 2 块 GPU 共 30 GB 显存）\nbash scripts\u002Ffinetune_real.sh \"cat\" data\u002Fcat real_reg\u002Fsamples_cat  cat finetune_addtoken.yaml \u003Cpretrained-model-path>\n\n## 保存更新后的模型权重\npython src\u002Fget_deltas.py --path logs\u002F\u003Cfolder-name> --newtoken 1\n\n## 生成图像\npython sample.py --prompt \"\u003Cnew1> cat playing with a ball\" --delta_ckpt logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fdelta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\n`\u003Cpretrained-model-path>` 是预训练模型 `sd-v1-4.ckpt` 的路径。我们论文中的结果并未使用 [clip-retrieval](https:\u002F\u002Fgithub.com\u002From1504\u002Fclip-retrieval) 来检索真实图像作为正则化样本，但使用该方法也能得到类似效果。\n\n**使用生成图像作为正则化样本**\n```\nbash scripts\u002Ffinetune_gen.sh \"cat\" data\u002Fcat gen_reg\u002Fsamples_cat  cat finetune_addtoken.yaml \u003Cpretrained-model-path>\n```\n\n\n### 多概念微调\n\n**联合训练**\n\n```\n## 开始训练（占用 2 块 GPU 共 30 GB 显存）\nbash scripts\u002Ffinetune_joint.sh \"wooden pot\" data\u002Fwooden_pot real_reg\u002Fsamples_wooden_pot \\\n                                    \"cat\" data\u002Fcat real_reg\u002Fsamples_cat  \\\n                                    wooden_pot+cat finetune_joint.yaml \u003Cpretrained-model-path>\n\n## 保存更新后的模型权重\npython src\u002Fget_deltas.py --path logs\u002F\u003Cfolder-name> --newtoken 2\n```\n\n## 示例\n```bash\npython sample.py --prompt \"the \u003Cnew2> cat sculpture in the style of a \u003Cnew1> wooden pot\" --delta_ckpt logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fdelta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\n**基于优化的权重融合**\n\n给定任意两个类别对应的微调模型权重 `delta_ckpt1` 和 `delta_ckpt2`，可以按如下方式将它们融合为一个单一模型：\n```bash\npython src\u002FcomposenW.py --paths \u003Cdelta_ckpt1>+\u003Cdelta_ckpt2> --categories  \"wooden pot+cat\"  --ckpt \u003Cpretrained-model-path> \n\n## 示例\npython sample.py --prompt \"the \u003Cnew2> cat sculpture in the style of a \u003Cnew1> wooden pot\" --delta_ckpt optimized_logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fdelta_epoch\\=000000.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\n\n### 使用 Diffusers 库进行训练\n\n**[新增功能！]** Custom Diffusion 现已支持 [diffusers](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers)。有关训练和推理的详细信息，请参阅[此处](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Ftree\u002Fmain\u002Fexamples\u002Fcustom_diffusion)。\n\n```bash\n## 安装依赖\npip install accelerate>=0.24.1\npip install modelcards\npip install transformers>=4.31.0\npip install deepspeed\npip install diffusers==0.21.4\naccelerate config\nexport MODEL_NAME=\"CompVis\u002Fstable-diffusion-v1-4\"\n```\n\n**单概念微调（Single-Concept fine-tuning）**\n\n```bash\n## 启动训练脚本（推荐使用 2 块 GPU；若仅使用 1 块 GPU，请将 --max_train_steps 增加至 500）\n\naccelerate launch src\u002Fdiffusers_training.py \\\n          --pretrained_model_name_or_path=$MODEL_NAME  \\\n          --instance_data_dir=.\u002Fdata\u002Fcat  \\\n          --class_data_dir=.\u002Freal_reg\u002Fsamples_cat\u002F \\\n          --output_dir=.\u002Flogs\u002Fcat  \\\n          --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\\n          --instance_prompt=\"photo of a \u003Cnew1> cat\"  \\\n          --class_prompt=\"cat\" \\\n          --resolution=512  \\\n          --train_batch_size=2  \\\n          --learning_rate=1e-5  \\\n          --lr_warmup_steps=0 \\\n          --max_train_steps=250 \\\n          --num_class_images=200 \\\n          --scale_lr --hflip  \\\n          --modifier_token \"\u003Cnew1>\"\n\n## 生成示例\npython src\u002Fdiffusers_sample.py --delta_ckpt logs\u002Fcat\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat playing with a ball\"\n```\n\n你也可以在 `accelerate config` 配置中启用 `--enable_xformers_memory_efficient_attention` 和 `fp16`，以降低显存占用并加速训练。若要使用 SDXL 进行训练，请使用 `diffusers_training_sdxl.py` 并设置 `MODEL_NAME=\"stabilityai\u002Fstable-diffusion-xl-base-1.0\"`。\n\n**多概念微调（Multi-Concept fine-tuning）**\n\n提供一个包含每个概念信息的 [json](assets\u002Fconcept_list.json) 文件，格式参考 [DreamBooth 示例](https:\u002F\u002Fgithub.com\u002FShivamShrirao\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fdreambooth\u002Ftrain_dreambooth.py)。\n```bash\n## 启动训练脚本（推荐使用 2 块 GPU；若仅使用 1 块 GPU，请将 --max_train_steps 增加至 1000）\n\naccelerate launch src\u002Fdiffusers_training.py \\\n          --pretrained_model_name_or_path=$MODEL_NAME  \\\n          --output_dir=.\u002Flogs\u002Fcat_wooden_pot  \\\n          --concepts_list=.\u002Fassets\u002Fconcept_list.json \\\n          --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\\n          --resolution=512  \\\n          --train_batch_size=2  \\\n          --learning_rate=1e-5  \\\n          --lr_warmup_steps=0 \\\n          --max_train_steps=500 \\\n          --num_class_images=200 \\\n          --scale_lr --hflip  \\\n          --modifier_token \"\u003Cnew1>+\u003Cnew2>\" \n\n## 生成示例\npython src\u002Fdiffusers_sample.py --delta_ckpt logs\u002Fcat_wooden_pot\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat sitting inside a \u003Cnew2> wooden pot and looking up\"\n```\n\n**多概念的基于优化的权重融合**\n\n给定任意两个类别对应的微调模型权重 `delta1.bin` 和 `delta2.bin`，可以按如下方式将它们融合为一个单一模型：\n```bash\npython src\u002Fdiffusers_composenW.py --paths \u003Cdelta1.bin>+\u003Cdelta2.bin> --categories  \"wooden pot+cat\"  --ckpt \"CompVis\u002Fstable-diffusion-v1-4\"\n\n## 生成示例\npython src\u002Fdiffusers_sample.py --delta_ckpt optimized_logs\u002F\u003Cfolder-name>\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat sitting inside a \u003Cnew2> wooden pot and looking up\"\n```\n\n上述 diffusers 训练代码修改自以下 [DreamBooth](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fdreambooth\u002Ftrain_dreambooth.py) 和 [Textual Inversion](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Ftextual_inversion\u002Ftextual_inversion.py) 的训练脚本。有关如何配置 accelerate 的更多细节，请参阅[此处](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fdreambooth)。\n\n### 人脸微调\n\n对于人脸微调，我们建议在上述 diffusers 训练脚本中使用 `learning_rate=5e-6` 和 `max_train_steps=750`，或在 stable-diffusion 训练脚本中使用 `finetune_face.yaml` 配置文件。\n\n我们观察到，与论文中展示的其他类别相比，人脸微调需要更低的学习率、更长的训练步数以及更多的图像才能获得更好的效果。当图像数量较少时，对 cross-attention（交叉注意力）层的所有参数进行微调效果略好，可通过添加 `--freeze_model \"crossattn\"` 启用该选项。\n\n下图展示了使用 diffusers 训练脚本对 [Richard Zhang](https:\u002F\u002Frichzhang.github.io\u002F) 的 14 张特写照片进行微调的示例结果。\n\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_87bddca3c633.jpg' align=\"center\" width=800>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n### 模型压缩\n\n```bash\npython src\u002Fcompress.py --delta_ckpt \u003Cfinetuned-delta-path> --ckpt \u003Cpretrained-model-path>\n\n## 生成示例\npython sample.py --prompt \"\u003Cnew1> cat playing with a ball\" --delta_ckpt logs\u002F\u003Cfolder-name>\u002Fcheckpoints\u002Fcompressed_delta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path> --compress\n```\n\n不同压缩级别下的生成示例。默认情况下，我们的代码会保留前 60% 的奇异值进行低秩近似（low-rank approximation），从而生成约 15 MB 大小的模型。\n\u003Cdiv>\n\u003Cp align=\"center\">\n\u003Cimg src='https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_readme_fc07f239be59.jpg' align=\"center\" width=900>\n\u003C\u002Fp>\n\u003C\u002Fdiv>\n\n### stable-diffusion-v1-4 的检查点转换\n\n* 从 diffusers 的 `delta.bin` 转换为 CompVis 的 `delta_model.ckpt`：\n```bash\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta.bin --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode diffuser-to-compvis                  \n# 生成示例\npython sample.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta_model.ckpt --ckpt \u003Cpath-to-model-v1-4.ckpt> --prompt \u003Ctext-prompt> --config configs\u002Fcustom-diffusion\u002Ffinetune_addtoken.yaml\n```\n\n* 从 diffusers 的 `delta.bin` 转换为 [stable-diffusion-webui](https:\u002F\u002Fgithub.com\u002FAUTOMATIC1111\u002Fstable-diffusion-webui) 的检查点：\n```bash\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta.bin --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode diffuser-to-webui                  \n# 在 stable-diffusion-webui 目录下启动 UI\nbash webui.sh --embeddings-dir \u003Cpath-to-folder>\u002Fwebui\u002Fembeddings  --ckpt \u003Cpath-to-folder>\u002Fwebui\u002Fmodel.ckpt\n```\n\n* 从 CompVis 的 `delta_model.ckpt` 转换为 diffusers 的 `delta.bin`：\n```bash\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta_model.ckpt --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode compvis-to-diffuser\n```\n\n# sample\n```bash\npython src\u002Fdiffusers_sample.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \u003Ctext-prompt>\n```\n\n* 来自 CompVis 的 `delta_model.ckpt` [stable-diffusion-webui](https:\u002F\u002Fgithub.com\u002FAUTOMATIC1111\u002Fstable-diffusion-webui) checkpoint（检查点）。\n```bash\npython src\u002Fconvert.py --delta_ckpt \u003Cpath-to-folder>\u002Fdelta_model.ckpt --ckpt \u003Cpath-to-model-v1-4.ckpt> --mode compvis-to-webui                  \n# 在 stable-diffusion-webui 目录下启动 UI\nbash webui.sh --embeddings-dir \u003Cpath-to-folder>\u002Fwebui\u002Fembeddings  --ckpt \u003Cpath-to-folder>\u002Fwebui\u002Fmodel.ckpt\n```\n转换后的 checkpoints（检查点）将保存在原始 checkpoints 所在的 `\u003Cpath-to-folder>` 目录中。\n\n\n## References（参考文献）\n\n```\n@article{kumari2022customdiffusion,\n  title={Multi-Concept Customization of Text-to-Image Diffusion},\n  author={Kumari, Nupur and Zhang, Bingliang and Zhang, Richard and Shechtman, Eli and Zhu, Jun-Yan},\n  booktitle = {Proceedings of the IEEE\u002FCVF Conference on Computer Vision and Pattern Recognition (CVPR)},\n  year      = {2023}\n}\n```\n\n## Acknowledgments（致谢）\n我们感谢 Nick Kolkin、David Bau、Sheng-Yu Wang、Gaurav Parmar、John Nack 和 Sylvain Paris 提供的宝贵意见和讨论，也感谢 Allie Chang、Chen Wu、Sumith Kulal、Minguk Kang、Yotam Nitzan 和 Taesung Park 对初稿的校对。我们还要感谢 Mia Tang 和 Aaron Hertzmann 分享他们的艺术作品。部分数据集从 Unsplash 下载。本工作部分由 Nupur Kumari 在 Adobe 实习期间完成。该研究部分得到了 Adobe Inc. 的支持。","# Custom Diffusion 快速上手指南\n\n## 环境准备\n\n- **系统要求**：Linux 或 macOS（Windows 未官方支持）\n- **GPU**：推荐至少 2 张 A100 或等效显卡（单卡可运行，需调整训练步数）\n- **显存**：单次训练约需 30GB 显存（使用 `diffusers` + `fp16` 可降低需求）\n- **Python**：建议使用 Python 3.8+ 和 Conda 环境管理\n\n> 💡 国内用户建议配置 Hugging Face 镜像加速模型下载（如通过 `HF_ENDPOINT=https:\u002F\u002Fhf-mirror.com`）。\n\n## 安装步骤\n\n```bash\n# 克隆仓库\ngit clone https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion.git\ncd custom-diffusion\n\n# 克隆 Stable Diffusion（指定兼容版本）\ngit clone https:\u002F\u002Fgithub.com\u002FCompVis\u002Fstable-diffusion.git\ncd stable-diffusion\n\n# 创建 Conda 环境（使用官方 environment.yaml）\nconda env create -f environment.yaml\nconda activate ldm\n\n# 安装额外依赖\npip install clip-retrieval tqdm\n\n# 返回项目根目录\ncd ..\n```\n\n### 下载预训练模型\n\n```bash\n# 下载 Stable Diffusion v1.4 模型（国内用户建议使用镜像或代理）\nwget https:\u002F\u002Fhuggingface.co\u002FCompVis\u002Fstable-diffusion-v-1-4-original\u002Fresolve\u002Fmain\u002Fsd-v1-4.ckpt\n```\n\n> 📌 模型保存路径记为 `\u003Cpretrained-model-path>`，后续命令中替换为此路径。\n\n### （可选）使用 Diffusers 库（推荐新用户）\n\n```bash\n# 安装 diffusers 及依赖（支持 SDXL）\npip install accelerate>=0.24.1 modelcards transformers>=4.31.0 deepspeed\npip install diffusers==0.21.4\n\n# 配置 accelerate（按提示选择 GPU、混合精度等）\naccelerate config\n\n# 设置模型名称\nexport MODEL_NAME=\"CompVis\u002Fstable-diffusion-v1-4\"\n```\n\n## 基本使用\n\n### 单概念微调（以“猫”为例）\n\n#### 方法一：使用原始脚本\n\n```bash\n# 下载示例数据\nwget https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Fdata.zip\nunzip data.zip\n\n# 启动训练（替换 \u003Cpretrained-model-path> 为实际路径）\nbash scripts\u002Ffinetune_real.sh \"cat\" data\u002Fcat real_reg\u002Fsamples_cat cat finetune_addtoken.yaml \u003Cpretrained-model-path>\n\n# 提取微调权重\npython src\u002Fget_deltas.py --path logs\u002Fcat --newtoken 1\n\n# 生成图像\npython sample.py --prompt \"\u003Cnew1> cat playing with a ball\" --delta_ckpt logs\u002Fcat\u002Fcheckpoints\u002Fdelta_epoch\\=000004.ckpt --ckpt \u003Cpretrained-model-path>\n```\n\n#### 方法二：使用 Diffusers（更简洁）\n\n```bash\n# 启动训练（2 GPU 推荐）\naccelerate launch src\u002Fdiffusers_training.py \\\n  --pretrained_model_name_or_path=$MODEL_NAME \\\n  --instance_data_dir=.\u002Fdata\u002Fcat \\\n  --class_data_dir=.\u002Freal_reg\u002Fsamples_cat\u002F \\\n  --output_dir=.\u002Flogs\u002Fcat \\\n  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\\n  --instance_prompt=\"photo of a \u003Cnew1> cat\" \\\n  --class_prompt=\"cat\" \\\n  --resolution=512 \\\n  --train_batch_size=2 \\\n  --learning_rate=1e-5 \\\n  --max_train_steps=250 \\\n  --num_class_images=200 \\\n  --modifier_token \"\u003Cnew1>\"\n\n# 生成图像\npython src\u002Fdiffusers_sample.py --delta_ckpt logs\u002Fcat\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat playing with a ball\"\n```\n\n### 多概念微调（如“木盆 + 猫”）\n\n使用 Diffusers 方式（需准备 `concept_list.json`）：\n\n```bash\naccelerate launch src\u002Fdiffusers_training.py \\\n  --pretrained_model_name_or_path=$MODEL_NAME \\\n  --output_dir=.\u002Flogs\u002Fcat_wooden_pot \\\n  --concepts_list=.\u002Fassets\u002Fconcept_list.json \\\n  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\\n  --resolution=512 \\\n  --train_batch_size=2 \\\n  --learning_rate=1e-5 \\\n  --max_train_steps=500 \\\n  --num_class_images=200 \\\n  --modifier_token \"\u003Cnew1>+\u003Cnew2>\"\n\n# 生成图像\npython src\u002Fdiffusers_sample.py --delta_ckpt logs\u002Fcat_wooden_pot\u002Fdelta.bin --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --prompt \"\u003Cnew1> cat sitting inside a \u003Cnew2> wooden pot and looking up\"\n```\n\n> ✅ 提示：更多示例数据和预训练模型可从 [官网](https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002F) 下载。","一位独立游戏开发者正在制作一款以“会说话的复古玩具”为主题的冒险游戏，需要为多个原创角色（如一只穿背带裤的机械兔子、一个戴礼帽的木制小熊）生成大量不同场景下的高质量插图。\n\n### 没有 custom-diffusion 时\n- 只能依赖通用文生图模型（如 Stable Diffusion），但无法准确还原自己设计的独特玩具外观，每次生成的角色细节差异大，风格不统一。\n- 若使用 DreamBooth 等全模型微调方法，每新增一个角色需训练整个模型，耗时数小时且显存占用高，难以在消费级 GPU 上完成。\n- 每个角色模型体积超过 2GB，存储和管理多个角色定制模型成本高，项目扩展性差。\n- 无法在同一画面中同时调用两个自定义角色（如“机械兔子坐在木制小熊旁边”），因为现有方法不支持多概念组合生成。\n\n### 使用 custom-diffusion 后\n- 仅用 4~6 张角色参考图，6 分钟内即可完成单个角色的轻量微调，精准保留原创设计特征。\n- 仅更新交叉注意力层中的键值矩阵，每个角色新增参数仅 75MB，可在普通 24GB 显存 GPU 上高效训练与推理。\n- 所有定制角色可共用同一个基础模型，极大简化版本管理和部署流程。\n- 支持多概念联合提示，例如输入“V* rabbit playing chess with V* bear in a steampunk library”，即可生成两个自定义角色互动的连贯画面。\n\ncustom-diffusion 让小型团队也能高效、低成本地实现高度个性化的视觉内容生产，真正将创意控制权交还给创作者。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadobe-research_custom-diffusion_d3f9b8c8.jpg","adobe-research","Adobe Research","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fadobe-research_2a8169f2.png","",null,"https:\u002F\u002Fresearch.adobe.com\u002F","https:\u002F\u002Fgithub.com\u002Fadobe-research",[83,87],{"name":84,"color":85,"percentage":86},"Python","#3572A5",99.1,{"name":88,"color":89,"percentage":90},"Shell","#89e051",0.9,1970,141,"2026-04-03T03:51:47","NOASSERTION",4,"Linux","需要 NVIDIA GPU，推荐 2 张 A100（训练需约 30GB 显存），显存至少 8GB+，CUDA 版本未明确说明但需支持 PyTorch","未说明",{"notes":100,"python":101,"dependencies":102},"建议使用 conda 环境管理；首次运行需下载 Stable Diffusion v1-4 模型（约 5GB）及 regularization 数据集；支持通过 diffusers 库进行训练，也兼容 SDXL；多概念训练需准备 JSON 配置文件；人脸微调建议更低学习率和更多训练步数。","未明确说明，但根据 environment.yaml 和依赖推测为 3.8+",[103,104,105,106,107,108,109,110,111],"torch","transformers>=4.31.0","accelerate>=0.24.1","diffusers==0.21.4","clip-retrieval","tqdm","deepspeed","modelcards","xformers",[13,14],[114,115,116,117,118,119,120],"customization","fine-tuning","text-to-image-generation","computer-vision","diffusion-models","few-shot","pytorch",5,"2026-03-27T02:49:30.150509","2026-04-06T06:44:24.533357",[125,130,135,140,145,150,155],{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},1611,"如何正确使用 --ckpt 参数指定预训练模型路径？","应使用 Hugging Face 模型 ID（如 \"CompVis\u002Fstable-diffusion-v1-4\"）并添加 --diffuser 标志。例如：\n```\npython src\u002Fcompress.py --delta_ckpt='logs\u002Fperson\u002Fdelta.bin' --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --diffuser\n```\n若未加 --diffuser，程序会尝试从本地文件系统加载，导致 FileNotFoundError。","https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion\u002Fissues\u002F11",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},1612,"代码是否兼容新版 diffusers（0.13+）？遇到 CrossAttention 重构问题怎么办？","项目已更新以支持 diffusers 0.21.4。请确保使用官方指定的依赖版本（见 README）。若仍报错（如 save_attn_procs 失败），可能是 diffusers 内部 API 变更所致。建议严格按要求安装依赖，或回退到兼容版本（如 diffusers==0.14.0）以避免属性缺失问题。","https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion\u002Fissues\u002F49",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},1613,"训练时是否只优化目标 token（如 \u003Cnew1>）的嵌入，还是整个文本嵌入层？","实际上仅目标 token 的嵌入被优化。代码中通过 detach 其他嵌入（见 custom_modules.py 第 298 行）或在梯度回调中置零非目标 token 梯度来实现。这确保了只有自定义 token 的向量被更新，其余保持冻结。","https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion\u002Fissues\u002F52",{"id":141,"question_zh":142,"answer_zh":143,"source_url":144},1614,"遇到错误 'Attention' object has no attribute 'cross_attention_norm' 如何解决？","该错误源于 diffusers 版本不兼容。在较新版本中，cross_attention_norm 属性被重命名为 norm_cross。解决方法有两种：(1) 将代码中的 cross_attention_norm 替换为 norm_cross；(2) 安装兼容版本，如 `pip install diffusers==0.14.0`。","https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion\u002Fissues\u002F68",{"id":146,"question_zh":147,"answer_zh":148,"source_url":149},1615,"论文中 CLIP 文本对齐分数（~0.65）为何远高于原始 Textual Inversion（~0.26）？","这是因为计算方式不同：图像-图像相似度使用缩放因子 1.0，而图像-文本相似度（CLIPScore）使用缩放因子 2.5。因此分数不可直接比较。项目遵循 CLIPScore 标准，对文本对齐采用 2.5 缩放，导致数值更高。","https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion\u002Fissues\u002F56",{"id":151,"question_zh":152,"answer_zh":153,"source_url":154},1616,"在哪里可以下载论文中提到的失败案例模型（如 dog & cat、tortoise plushy & teddybear）？","这些模型已公开提供，可从 https:\u002F\u002Fwww.cs.cmu.edu\u002F~custom-diffusion\u002Fassets\u002Ffailure_case_models\u002F 下载。使用示例命令：\n```\npython sample.py --ckpt \u003Cpretrained-sd-1.4.ckpt> --prompt \"\u003Ctext-prompt>\" --delta_ckpt \u003Cpath-to-delta-ckpt> --modifier_token \"\u003Cnew1>+\u003Cnew2>\"\n```","https:\u002F\u002Fgithub.com\u002Fadobe-research\u002Fcustom-diffusion\u002Fissues\u002F43",{"id":156,"question_zh":157,"answer_zh":158,"source_url":129},1617,"使用 --freeze_model=crossattn 微调后，在压缩时遇到 KeyError: 'state_dict' 怎么办？","需在压缩命令中添加 --diffuser 参数。正确命令为：\n```\npython src\u002Fcompress.py --delta_ckpt='logs\u002Fperson\u002Fdelta.bin' --ckpt \"CompVis\u002Fstable-diffusion-v1-4\" --diffuser\n```\n否则程序无法正确解析模型状态字典结构。",[]]