res-adapter

res-adapter

扩散模型的无缝分辨率适配器

ResAdapter是一款轻量级分辨率适配器,可集成至各类扩散模型中实现任意分辨率图像生成。无需额外训练和推理,ResAdapter通过少量参数(SD1.5为0.9M, SDXL为0.5M)支持广泛的分辨率范围。项目提供使用指南、预训练权重及与多种模型的集成示例,展示了其在文本生成图像和图像编辑等任务中的应用效果。

ResAdapter扩散模型分辨率适配图像生成AI绘图Github开源项目
<div align="center"> <h1> ResAdapter: 扩散模型的域一致性分辨率适配器 </h1>

程家祥、谢盼*、夏鑫、李嘉实、吴杰、任宇熙、李慧霞、肖雪峰、郑敏、傅联(*通讯作者)

字节跳动自动机器学习部门

⭐ 如果ResAdapter对您的图像或项目有帮助,请给这个仓库点个星。谢谢!🤗

<a href='https://res-adapter.github.io/'><img src='https://img.shields.io/badge/项目-主页-green'></a> <a href='https://arxiv.org/abs/2403.02084'><img src='https://img.shields.io/badge/论文-Arxiv-red'></a> <a href='https://huggingface.co/papers/2403.02084'><img src='https://img.shields.io/badge/论文-Huggingface-blue'></a> GitHub 组织星标数

Hugging Face Replicate ComfyUI 访问量

我们提出了ResAdapter,一个即插即用的分辨率适配器,可以使任何扩散模型生成自由分辨率的图像:无需额外训练,无需额外推理,无需风格迁移。

<img src="https://yellow-cdn.veclightyear.com/835a84d5/7d1aaeda-3071-48c9-9a40-7aaeec63e34f.png" width="49.9%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/60d857ab-7356-4f03-be08-d95631c7f348.png" width="50%"> ResAdapter与dreamlike-diffusion-1.0的对比示例。

</div>

发布

快速上手

我们提供了一个独立的示例代码,帮助您快速使用ResAdapter与扩散模型。

<div align=center> <img src="https://yellow-cdn.veclightyear.com/835a84d5/6079af7b-b7ab-4122-9d91-2873d155632c.png" width="100%"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/80f98e9b-69d7-436b-90fc-1748c24df9ff.png" width="100%">

ResAdapter与dreamshaper-xl-1.0的对比示例(640x384)。上:使用ResAdapter。下:不使用ResAdapter。

</div>
# pip install diffusers, transformers, accelerate, safetensors, huggingface_hub import torch from torchvision.utils import save_image from safetensors.torch import load_file from huggingface_hub import hf_hub_download from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler generator = torch.manual_seed(0) prompt = "肌肉发达的胡子男子的肖像照片,穿着破旧的机甲装,轻微散景,复杂精致,钢铁质感,优雅,清晰聚焦,柔和光线,鲜艳色彩" width, height = 640, 384 # 加载基准管道 model_name = "lykon-models/dreamshaper-xl-1-0" pipe = AutoPipelineForText2Image.from_pretrained(model_name, torch_dtype=torch.float16, variant="fp16").to("cuda") pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++") # 基准管道推理 image = pipe(prompt, width=width, height=height, num_inference_steps=25, num_images_per_prompt=4, output_type="pt").images save_image(image, f"image_baseline.png", normalize=True, padding=0) # 为基准加载ResAdapter resadapter_model_name = "resadapter_v1_sdxl" pipe.load_lora_weights( hf_hub_download(repo_id="jiaxiangc/res-adapter", subfolder=resadapter_model_name, filename="pytorch_lora_weights.safetensors"), adapter_name="res_adapter", ) # 加载LoRA权重 pipe.set_adapters(["res_adapter"], adapter_weights=[1.0]) pipe.unet.load_state_dict( load_file(hf_hub_download(repo_id="jiaxiangc/res-adapter", subfolder=resadapter_model_name, filename="diffusion_pytorch_model.safetensors")), strict=False, ) # 加载归一化权重 # ResAdapter管道推理 image = pipe(prompt, width=width, height=height, num_inference_steps=25, num_images_per_prompt=4, output_type="pt").images save_image(image, f"image_resadapter.png", normalize=True, padding=0)

下载

模型

我们已发布所有ResAdapter权重,您可以从Huggingface下载ResAdapter模型。以下是我们的ResAdapter模型卡:

模型参数量分辨率范围比例范围链接
resadapter_v2_sd1.50.9M128 <= x <= 10240.28 <= r <= 3.5下载
resadapter_v2_sdxl0.5M256 <= x <= 15360.28 <= r <= 3.5下载
resadapter_v1_sd1.50.9M128 <= x <= 10240.5 <= r <= 2下载
resadapter_v1_sd1.5_extrapolation0.9M512 <= x <= 10240.5 <= r <= 2下载
resadapter_v1_sd1.5_interpolation0.9M128 <= x <= 5120.5 <= r <= 2下载
resadapter_v1_sdxl0.5M256 <= x <= 15360.5 <= r <= 2下载
resadapter_v1_sdxl_extrapolation0.5M1024 <= x <= 15360.5 <= r <= 2下载
resadapter_v1_sdxl_interpolation0.5M256 <= x <= 10240.5 <= r <= 2下载

提示1:我们根据controlnet更新了resadapter的命名格式。

提示2:如果你想将resadapter与个性化扩散模型一起使用,你应该从CivitAI下载它们。

提示3:如果你想将resadapter与ip-adapter、controlnet和lcm-lora一起使用,你应该从Huggingface下载它们。

提示4:这里有一个安装指南,用于准备环境和下载模型。

推理

如果你想在我们的推理脚本中生成图像,你应该按照安装指南安装依赖库并下载相关模型。在填写示例配置后,你可以直接运行这个脚本。

python main.py --config /path/to/file

ResAdapter与个性化模型用于文本到图像生成

<div align=center>

<img src="https://yellow-cdn.veclightyear.com/835a84d5/b3854f92-75c7-49ac-a9c8-2439445f338b.jpg" width="25%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/1b1982dc-874e-4065-b73d-bc00936c7aca.jpg" width="25%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/658e6094-8f8f-4cbc-b263-a00623c8f23f.jpg" width="25%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/86dcde3e-11ad-41e6-9a19-5d1e6cf6f0f7.jpg" width="25%"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/53998f8e-a3b2-46c3-b86c-c1ba4800d099.jpg" width="25%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e7b1fe48-e464-41c8-88c5-cca4b96c1108.jpg" width="25%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/71d7d6c4-012d-49c0-bba3-09ffd2410494.jpg" width="25%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/4d242760-bad1-4799-8681-78188fab4ce4.jpg" width="25%">

resadapter与dreamshaper-7的对比示例(960x1104)。上:使用resadapter。下:不使用resadapter。

</div>

ResAdapter与ControlNet用于图像到图像生成

<div align=center>

<img src="https://yellow-cdn.veclightyear.com/835a84d5/fe028df3-fda5-4c58-a7aa-45d063f7107b.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/2df31b61-879f-4545-afc7-69f2d0b872d3.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/92194734-d640-4113-a638-f2d43cce5e85.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/16fe9db8-6071-4371-9c36-023807e09909.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/8f83e800-bad4-4a0c-a7d1-59952bd21307.jpg" width="20%"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/fe028df3-fda5-4c58-a7aa-45d063f7107b.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e3ed8e0d-2125-4760-8d5b-0ebb08f542bd.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/1fa8ebf7-1812-4233-9ba7-b1d63bbc366c.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/49622a41-6c8f-49de-baf6-bac0be0ec833.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/59bee1d1-345d-4ca3-ada7-873ac6986aab.jpg" width="20%">

resadapter与lllyasviel/sd-controlnet-canny的对比示例(840x1264)。上:使用resadapter,下:不使用resadapter。

</div>

ResAdapter与ControlNet-XL用于图像到图像生成

<div align=center> <img src="https://yellow-cdn.veclightyear.com/835a84d5/ec309438-009a-44ad-afe9-87228d56e60b.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/392d9f8c-9e83-484c-b865-e115cd7da6bc.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/ab53dbbe-3359-43e2-80cc-4d0a8722e60f.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/da46c63a-1c99-4ec2-8485-3c9bdab3e95e.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/dc98192d-9158-449b-94f5-e571ef9b6615.jpg" width="20%"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/ec309438-009a-44ad-afe9-87228d56e60b.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/eb2b3c1e-11d2-4b6a-a143-0883ce2e2772.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/369f8245-3bf3-4556-ac59-5a68074da77c.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/25c9a0e6-7c0d-4fbf-a5e3-8ee8df3636d5.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/fa64b75c-4f46-418c-a708-3dcb095b3f9c.jpg" width="20%">

resadapter与diffusers/controlnet-canny-sdxl-1.0之间的对比示例(336x504)。上:使用resadapter,下:不使用resadapter。

</div>

ResAdapter与IP-Adapter结合实现人脸变化

<div align=center> <img src="https://yellow-cdn.veclightyear.com/835a84d5/c6635009-25b1-4b6b-8c7e-dc9178961c78.png" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e18131da-193e-4190-a61b-8b8d0cd72778.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/390e3633-dc85-4ad0-bd96-91e289eab767.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/6ef49bd5-fcd4-44bd-a61e-bef8e62975ec.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/46df2be0-b650-44f6-b725-a78cad32e442.jpg" width="20%"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/c6635009-25b1-4b6b-8c7e-dc9178961c78.png" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e5e94dfb-e187-4215-941b-5a2b3dc453b7.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/2e847708-30e0-4ec7-bfd2-fc9b9adaabd3.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/d0443203-efea-454c-9da1-ba403baab4dd.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/3bead4d6-7e17-4678-8d0f-2116f1ab04b9.jpg" width="20%">

resadapter与h94/IP-Adapter之间的对比示例(864x1024)。上:使用resadapter,下:不使用resadapter。

</div>

ResAdapter与LCM-LoRA结合实现加速

<div align=center>

<img src="https://yellow-cdn.veclightyear.com/835a84d5/5c08aa70-e083-4861-a0f1-fff5bdb2e20f.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/a7694e11-19a8-4c98-9f57-0f8b51203d1f.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/4c41f67f-a108-4856-a5a4-8bd5327288d9.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/efe48d56-a90c-45e4-b35b-292e93929753.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/fa62bcec-b769-473f-9031-05b9c2e4e5e0.jpg" width="20%"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/7db44a2d-8bdd-4506-9190-05dc90f918fb.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/5997a237-8240-440c-8cb5-146570d620c6.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/aa504ec8-2174-4670-8682-8aeee451dc08.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/63ad8ec0-f418-4fea-8f97-41d5335e1cff.jpg" width="20%"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e2b8d51a-e031-4637-88f8-035c0c82dd37.jpg" width="20%">

resadapter与dreamshaper-xl-1.0(使用lcm-sdxl-lora)之间的对比示例(512x512)。上:使用resadapter,下:不使用resadapter。

</div>

社区资源

Gradio

Hugging Face空间中关于res-adapter的文本到图像示例。更多信息请参考jiaxiangc/res-adapter<img src="https://yellow-cdn.veclightyear.com/835a84d5/2a8b2cdd-0956-4998-ba8f-b2b6e05e74c6.png">

ComfyUI

这是一个关于ComfyUI-ResAdapter的文本到图像示例。更多关于lcm-lora、controlnet和ipadapter的示例可以在ComfyUI-ResAdapter中找到。

https://github.com/jiaxiangc/ComfyUI-ResAdapter/assets/162297627/82453931-23de-4f72-8a9c-1053c4c8d81a

WebUI

我正在学习如何制作WebUI扩展。

本地Gradio演示

运行以下脚本:

# pip install peft, gradio, httpx==0.23.3 python app.py

使用技巧

  1. 如果对插值图像不满意,尝试将ResAdapter的alpha值增加到1.0。
  2. 如果对外推图像不满意,尝试选择ResAdapter的alpha值在0.3到0.7之间。
  3. 如果发现图像风格冲突,尝试降低ResAdapter的alpha值。
  4. 如果发现ResAdapter与其他加速LoRA不兼容,尝试将ResAdapter的alpha值降低到0.5到0.7之间。

致谢

Star历史

Star历史图表

引用

如果您发现ResAdapter对您的研究和应用有用,请使用以下BibTeX引用我们:

@article{cheng2024resadapter,
  title={ResAdapter: Domain Consistent Resolution Adapter for Diffusion Models},
  author={Cheng, Jiaxiang and Xie, Pan and Xia, Xin and Li, Jiashi and Wu, Jie and Ren, Yuxi and Li, Huixia and Xiao, Xuefeng and Zheng, Min and Fu, Lean},
  booktitle={arXiv preprint arxiv:2403.02084},
  year={2024}
}

如有任何问题,请随时通过chengjiaxiang@bytedance.comxiepan.01@bytedance.com与我们联系。

编辑推荐精选

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

Hunyuan3D-2

Hunyuan3D-2

高分辨率纹理 3D 资产生成

Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。

3FS

3FS

一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。

3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。

下拉加载更多