CoolFace
Modelpublic

TencentARC/t2i-adapter-canny-sdxl-1.0

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
54likes2.7kdownloads
Model Card

T2I-Adapter-SDXL - Canny

T2I Adapter is a network providing additional conditioning to stable diffusion. Each t2i checkpoint takes a different type of conditioning as input and is used with a specific base stable diffusion checkpoint.

This checkpoint provides conditioning on canny for the StableDiffusionXL checkpoint. This was a collaboration between Tencent ARC and **Hugging Face**.

Model Details

  • Developed by: T2I-Adapter: Learning Adapters to Dig out More Controllable Ability for Text-to-Image Diffusion Models
  • Model type: Diffusion-based text-to-image generation model
  • Language(s): English
  • License: Apache 2.0
  • Resources for more information: GitHub Repository, Paper.
  • Model complexity: | | SD-V1.4/1.5 | SD-XL | T2I-Adapter | T2I-Adapter-SDXL | | --- | --- |--- |--- |--- | | Parameters | 860M | 2.6B |77 M | 77/79 M | |
  • Cite as:

@misc{ title={T2I-Adapter: Learning Adapters to Dig out More Controllable Ability for Text-to-Image Diffusion Models}, author={Chong Mou, Xintao Wang, Liangbin Xie, Yanze Wu, Jian Zhang, Zhongang Qi, Ying Shan, Xiaohu Qie}, year={2023}, eprint={2302.08453}, archivePrefix={arXiv}, primaryClass={cs.CV} }

Checkpoints

Model NameControl Image OverviewControl Image ExampleGenerated Image Example
TencentARC/t2i-adapter-canny-sdxl-1.0<br/> Trained with canny edge detectionA monochrome image with white edges on a black background.<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condcanny.png"><img width="64" style="margin:0;padding:0;" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condcanny.png"/></a><a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/rescanny.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/rescanny.png"/></a>
TencentARC/t2i-adapter-sketch-sdxl-1.0<br/> Trained with [PidiNet](https://github.com/zhuoinoulu/pidinet) edge detectionA hand-drawn monochrome image with white outlines on a black background.<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condsketch.png"><img width="64" style="margin:0;padding:0;" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condsketch.png"/></a><a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/ressketch.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/ressketch.png"/></a>
TencentARC/t2i-adapter-lineart-sdxl-1.0<br/> Trained with lineart edge detectionA hand-drawn monochrome image with white outlines on a black background.<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condlin.png"><img width="64" style="margin:0;padding:0;" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condlin.png"/></a><a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/reslin.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/reslin.png"/></a>
TencentARC/t2i-adapter-depth-midas-sdxl-1.0<br/> Trained with Midas depth estimationA grayscale image with black representing deep areas and white representing shallow areas.<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/conddepthmid.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/conddepthmid.png"/></a><a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/resdepthmid.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/resdepthmid.png"/></a>
TencentARC/t2i-adapter-depth-zoe-sdxl-1.0<br/> Trained with Zoe depth estimationA grayscale image with black representing deep areas and white representing shallow areas.<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/conddepthzeo.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/conddepthzeo.png"/></a><a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/resdepthzeo.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/resdepthzeo.png"/></a>
TencentARC/t2i-adapter-openpose-sdxl-1.0<br/> Trained with OpenPose bone imageA OpenPose bone image.<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/openpose.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/openpose.png"/></a><a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/respose.png"><img width="64" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/respose.png"/></a>

Example

To get started, first install the required dependencies:

bash
pip install -U git+https://github.com/huggingface/diffusers.git
pip install -U controlnet_aux==0.0.7 # for conditioning models and detectors  
pip install transformers accelerate safetensors
  1. 1.Images are first downloaded into the appropriate control image format.
  2. 2.The control image and prompt are passed to the `StableDiffusionXLAdapterPipeline`.

Let's have a look at a simple example using the Canny Adapter.

  • Dependency
py
from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, EulerAncestralDiscreteScheduler, AutoencoderKL
from diffusers.utils import load_image, make_image_grid
from controlnet_aux.canny import CannyDetector
import torch

# load adapter
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", torch_dtype=torch.float16, varient="fp16").to("cuda")

# load euler_a scheduler
model_id = 'stabilityai/stable-diffusion-xl-base-1.0'
euler_a = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
vae=AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
    model_id, vae=vae, adapter=adapter, scheduler=euler_a, torch_dtype=torch.float16, variant="fp16", 
).to("cuda")
pipe.enable_xformers_memory_efficient_attention()

canny_detector = CannyDetector()
  • Condition Image
py
url = "https://huggingface.co/Adapter/t2iadapter/resolve/main/figs_SDXLV1.0/org_canny.jpg"
image = load_image(url)

# Detect the canny map in low resolution to avoid high-frequency details
image = canny_detector(image, detect_resolution=384, image_resolution=1024)#.resize((1024, 1024))

<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condcanny.png"><img width="480" style="margin:0;padding:0;" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condcanny.png"/></a>

  • Generation
py
prompt = "Mystical fairy in real, magic, 4k picture, high quality"
negative_prompt = "extra digit, fewer digits, cropped, worst quality, low quality, glitch, deformed, mutated, ugly, disfigured"

gen_images = pipe(
  prompt=prompt,
  negative_prompt=negative_prompt,
  image=image,
  num_inference_steps=30,
  guidance_scale=7.5, 
  adapter_conditioning_scale=0.8, 
  adapter_conditioning_factor=1
).images[0]
gen_images.save('out_canny.png')

<a href="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/condcanny.png"><img width="480" style="margin:0;padding:0;" src="https://huggingface.co/Adapter/t2iadapter/resolve/main/figsSDXLV1.0/rescanny.png"/></a>

Training

Our training script was built on top of the official training script that we provide here.

The model is trained on 3M high-resolution image-text pairs from LAION-Aesthetics V2 with

  • Training steps: 20000
  • Batch size: Data parallel with a single gpu batch size of 16 for a total batch size of 256.
  • Learning rate: Constant learning rate of 1e-5.
  • Mixed precision: fp16