Skip to content

Official implementation of "ResAdapter: Domain Consistent Resolution Adapter for Diffusion Models".

License

Notifications You must be signed in to change notification settings

Polyphron/res-adapter

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ResAdapter: Domain Consistent Resolution Adapter for Diffusion Models

Jiaxiang Cheng, Pan Xie*, Xin Xia, Jiashi Li, Jie Wu, Yuxi Ren, Huixia Li, Xuefeng Xiao, Min Zheng, Lean Fu (*Corresponding author)

AutoML, ByteDance Inc.

GitHub Org's stars

Replicate

We propose ResAdapter, a plug-and-play resolution adapter for enabling diffusion models of arbitrary style domains to generate resolution-free images: no additional training, no additional inference and no style transfer.

The above images are generated by ResAdapter with dreamlike-diffusion-1.0

πŸš€ Release

πŸ”₯ Standalone Example with SDXL-Lightning

[ResAdapter] The following 512x512 images are generated by ResAdapter with SDXL-Lightning-Step4

[Baseline] The following 512x512 images are generated by SDXL-Lightning-Step4

Prompt: A girl smiling.
# pip install diffusers, transformers, accelerate, safetensors, huggingface_hub
import torch
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from torchvision.utils import save_image

generator = torch.manual_seed(12638721376)
width, height = 512, 512

base = "stabilityai/stable-diffusion-xl-base-1.0"
repo = "ByteDance/SDXL-Lightning"
ckpt = "sdxl_lightning_4step_unet.safetensors"  # Use the correct ckpt for your step setting!

# Load SDXL-Lighting.
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")

# Inference SDXL-Lighting
images = pipe(
    "A girl smiling",
    width=width,
    height=height,
    num_inference_steps=4,
    guidance_scale=0,
    num_images_per_prompt=5,
    output_type="pt",
    generator=generator,
).images
save_image(images, f"/baseline_{width}.png", normalize=True, padding=0)

# Load ResAdapter
pipe.load_lora_weights(
    hf_hub_download(
        repo_id="jiaxiangc/res-adapter",
        subfolder="sdxl-i",
        filename="resolution_lora.safetensors",
    ),
    adapter_name="res_adapter",
)
pipe.set_adapters(["res_adapter"], adapter_weights=[1.0])

# Inference ResAdapter
images = pipe(
    "A girl smiling",
    width=width,
    height=height,
    num_inference_steps=4,
    guidance_scale=0,
    num_images_per_prompt=5,
    output_type="pt",
    generator=generator,
).images
save_image(images, f"resadapter_{width}.png", normalize=True, padding=0)

πŸŽ‰ Use ResAdapter in Gradio

πŸ”₯ [Update at 2024/03/12] We are happy to provide demos in replicate.com.

Relicate demo: bytedance/res-adapter, by (@chenxiwh)

πŸŽ‰ Use ResAdapter in ComfyUI

We will support ComfyUI within a week.

⏬ Installation

# Step1: Enter to res-adapter directory
cd res-adapter

# Step2: Install dependency
pip install -r requirements.txt

# Step3: Download diffusion models, and make the directory structure as follows:
models
β”œβ”€β”€ res_adapter
β”‚   β”œβ”€β”€ res_adapter-v1.5
β”‚   β”œβ”€β”€ res_adapter-xl
β”œβ”€β”€ diffusion_models
β”‚   β”œβ”€β”€ ...
β”œβ”€β”€ controlnet
β”‚   β”œβ”€β”€ ...
β”œβ”€β”€ ip_adapter
β”‚   β”œβ”€β”€ ...
└── lcm-lora
    └──  ...

⏬ Download Models

1️⃣ Download ResAdapter

πŸŽ‰ [Update at 2024/03/12] We release resadapter-sd1.5 that supports 128~1024.

Models Parameters Resolution Range Links
resadapter-v1.5-i 0.8M 128<= x <= 512 Download
resadapter-xl-i 0.4M 256 <= x <= 1024 Download
resadapter-v1.5 0.9M 128 <= x <= 1024 Download
resadapter-xl 0.5M 256 <= x <= 1536 Coming soon

2️⃣ Download Diffusion Models

We provide some personalized models for sampling style images with ResAdapter. More personalized models can be found in CivitAI.

Models Structure Type Domain Type Links
Base model
SDv1.5 - General Download
SDXL1.0 - General Download
Personalized model
RealisticVision SDv1.5 Realism Download
Dreamlike SDv1.5 Fantasy Download
DreamshaperXL SDXL 2.5D Download
AnimeartXL SDXL Anime Download

3️⃣ Download Other Modules

We support demos about ControlNet, IP-Adapter, LCM-LoRA.

Modules Name Type Links
ControlNet lllyasviel/sd-controlnet-canny SD1.5 Download
ControlNet diffusers/controlnet-canny-sdxl-1.0 SDXL Download
IP-Adapter h94/IP-Adapter SD1.5/SDXL Download
LCM-LoRA latent-consistency/lcm-lora-sdv1-5 SD1.5 Download
LCM-LoRA latent-consistency/lcm-lora-sdxl SDXL Download

🏠 ResAdapter in Inference Scripts

We provide simple scripts for sampling images of resadapter and baseline.

# Step1: Choose a task example of config file.
# Step2: Run the following script.
python main.py --config /path/to/file

0️⃣ Best Practice

πŸ˜„ For better image generation, we provide two advice:

  • For text to image tasks, please use personalized models instead of base models.
  • For other tasks, use base models.

1️⃣ ResAdapter with Diffusion Models

[ResAdapter] The following 960x1104 images are generated by ResAdapter with Dreamshaper-7.
[Baseline] The following 960x1104 images are generated by Dreamshaper-7
Text to image tasks.

Prompt: (masterpiece), (extremely intricate), (realistic), portrait of a girl, the most beautiful in the world, (medieval armor), metal reflections, upper body, outdoors, intense sunlight, far away castle, professional photograph of a stunning woman detailed, sharp focus, dramatic, award winning, cinematic lighting, octane render unreal engine, volumetrics dtx, (film grain, blurry background, blurry foreground, bokeh, depth of field, sunset, motion blur), chainmail.

2️⃣ ResAdapter with ControlNet

[ResAdapter] The following 840x1246 images are generated by ResAdapter with ControlNet(SDv15).
[Baseline] The following 840x1246 images are generated by ControlNet(SDv15).
Image to image tasks.

Prompt: A bird.

3️⃣ ResAdapter with ControlNet-XL

[ResAdapter] The following 336x504 images are generated by ResAdapter with ControlNet-XL(SDXL1.0).
[Baseline] The above 336x504 images are generated by ControlNet-XL(SDXL1.0).
Image to image tasks. The first column represents condition image.

Prompt: A man.

4️⃣ ResAdapter with IP-Adapter

[ResAdapter] The following 864x1024 images are generated by ResAdapter with IP-Adapter(SDv15).
[Baseline] The following 864x1204 images are generated by IP-Adapter(SDv15).
Face variation tasks. The first column represents face image.

5️⃣ ResAdapter with LCM-LoRA

[ResAdapter] The following 512x512 images are generated by ResAdapter, LCM-XL-LoRA with Dreamshaper-XL.
[Baseline] The following 512x512 images are generated by LCM-XL-LoRA with Dreamshaper-XL.
Text to image task. Step=4, CFG=1.5.

Prompt: portrait, action pose, slow motion, (old male human wizard) old male human wizard wearing yellow and black robes (majestic evoker cloth armor), (wrinkles, steampunk), (archmage robes, runic patterns), (insanely detailed, bloom), (analog), (high sharpness), (detailed pupils), (painting), (digital painting), detailed face and eyes, Masterpiece, best quality, (highly detailed photo), 8k, photorealistic, very long straight white and grey hair, grey streaks, ecstatic, (60-year old Austrian male), sharp, (older body), stocky, realistic, real shadow 3d, (highest quality), (concept art, 4k), (wizard labratory in backgound), by Michelangelo and Alessandro Casagrande and Greg Rutkowski and Sally Mann and jeremy mann and sandra chevrier and maciej kuciara, inspired by (arnold schwarzenegger) and (Dolph Lundgren) and (Albert Einstien)

πŸ”¨ TODO

  • Provide weights of resadapter-sdv15-i that supports 128~512.
  • Provide weights of resadapter-sdv15-i that supports 128~1024.
  • Provide weights of resadapter-xl-i that supports 256~1024.
  • Provide weights of resadapter-xl-i that supports 256~1536.
  • Supporting resadapter in ComfyUI during mid to late March.

🌟 Star History

Our target about the number of star: 1k+. We will keep maintain our repository.

Star History Chart

✈️ Citation

@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}
}

About

Official implementation of "ResAdapter: Domain Consistent Resolution Adapter for Diffusion Models".

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%