
扩散模型的无缝分辨率适配器
ResAdapter是一款轻量级分辨率适配器,可集成至各类扩散模型中实现任意分辨率图像生成。无需额外训练和推理,ResAdapter通过少量参数(SD1.5为0.9M, SDXL为0.5M)支持广泛的分辨率范围。项目提供使用指南、预训练权重及与多种模型的集成示例,展示了其在文本生成图像和图像编辑等任务中的应用效果。
程家祥、谢盼*、夏鑫、李嘉实、吴杰、任宇熙、李慧霞、肖雪峰、郑敏、傅联(*通讯作者)
字节跳动自动机器学习部门
⭐ 如果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>
我们提出了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>[2024/04/07] 🔥 我们在Huggingface上发布了官方gradio空间。[2024/04/05] 🔥 我们发布了resadapter_v2权重。[2024/03/30] 🔥 我们发布了ComfyUI-ResAdapter。[2024/03/28] 🔥 我们发布了resadapter_v1权重。[2024/03/04] 🔥 我们发布了arxiv论文。我们提供了一个独立的示例代码,帮助您快速使用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.5 | 0.9M | 128 <= x <= 1024 | 0.28 <= r <= 3.5 | 下载 |
| resadapter_v2_sdxl | 0.5M | 256 <= x <= 1536 | 0.28 <= r <= 3.5 | 下载 |
| resadapter_v1_sd1.5 | 0.9M | 128 <= x <= 1024 | 0.5 <= r <= 2 | 下载 |
| resadapter_v1_sd1.5_extrapolation | 0.9M | 512 <= x <= 1024 | 0.5 <= r <= 2 | 下载 |
| resadapter_v1_sd1.5_interpolation | 0.9M | 128 <= x <= 512 | 0.5 <= r <= 2 | 下载 |
| resadapter_v1_sdxl | 0.5M | 256 <= x <= 1536 | 0.5 <= r <= 2 | 下载 |
| resadapter_v1_sdxl_extrapolation | 0.5M | 1024 <= x <= 1536 | 0.5 <= r <= 2 | 下载 |
| resadapter_v1_sdxl_interpolation | 0.5M | 256 <= x <= 1024 | 0.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
<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><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与diffusers/controlnet-canny-sdxl-1.0之间的对比示例(336x504)。上:使用resadapter,下:不使用resadapter。
</div>resadapter与h94/IP-Adapter之间的对比示例(864x1024)。上:使用resadapter,下:不使用resadapter。
</div><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>Hugging Face空间中关于res-adapter的文本到图像示例。更多信息请参考jiaxiangc/res-adapter。 <img src="https://yellow-cdn.veclightyear.com/835a84d5/2a8b2cdd-0956-4998-ba8f-b2b6e05e74c6.png">
这是一个关于ComfyUI-ResAdapter的文本到图像示例。更多关于lcm-lora、controlnet和ipadapter的示例可以在ComfyUI-ResAdapter中找到。
我正在学习如何制作WebUI扩展。
运行以下脚本:
# pip install peft, gradio, httpx==0.23.3 python app.py
如果您发现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.com或xiepan.01@bytedance.com与我们联系。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。


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


AI论文写作指导平台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号