(WIP) WebUI extension for ControlNet
This extension is for AUTOMATIC1111's Stable Diffusion web UI, allows the Web UI to add ControlNet to the original Stable Diffusion model to generate images. The addition is on-the-fly, the merging is not required.
ControlNet is a neural network structure to control diffusion models by adding extra conditions.
Thanks & Inspired: kohya-ss/sd-webui-additional-networks
- Dragging large file on the Web UI may freeze the entire page. It is better to use the upload file option instead.
- Just like WebUI's hijack, we used some interpolate to accept arbitrary size configure (see
scripts/cldm.py
)
Some users may need to install the cv2 library before using it: pip install opencv-python
Upgrade gradio if any ui issues occured: pip install gradio==3.16.2
- Open "Extensions" tab.
- Open "Install from URL" tab in the tab.
- Enter URL of this repo to "URL for extension's git repository".
- Press "Install" button.
- Reload/Restart Web UI.
- Put the ControlNet models (
.pt
,.pth
,.ckpt
or.safetensors
) inside themodels/ControlNet
folder. - Open "txt2img" or "img2img" tab, write your prompts.
- Press "Refresh models" and select the model you want to use. (If nothing appears, try reload/restart the webui)
- Upload your image and select preprocessor, done.
Currently it supports both full models and trimmed models. Use extract_controlnet.py
to extract controlnet from original .pth
file.
Pretrained Models: https://huggingface.co/lllyasviel/ControlNet/tree/main/models
Two methods can be used to reduce the model's filesize:
-
Directly extract controlnet from original .pth file using
extract_controlnet.py
. -
Transfer control from original checkpoint by making difference using
extract_controlnet_diff.py
.
All type of models can be correctly recognized and loaded. The results of different extraction methods are discussed in lllyasviel/ControlNet#12 and Mikubill#73.
Pre-extracted model: https://huggingface.co/webui/ControlNet-modules-safetensors
Pre-extracted difference model: https://huggingface.co/kohya-ss/ControlNet-diff-modules
Currently support both sketch Adapter and image Adapter. Note that the impl is experimental, result may differ from original repo. See Adapter Examples
for reference.
To use these models:
- Download files from https://huggingface.co/TencentARC/T2I-Adapter
- Setup correct config in settings panel -
sketch_adapter_v14.yaml
for sketch model andimage_adapter_v14.yaml
for keypose and segmentation model. - It's better to use a slightly lower strength (t) when generating images with sketch model, such as 0.6-0.8. (ref: ldm/models/diffusion/plms.py)
- Don't forget to add some negative prompt, default negative prompt in ControlNet repo is "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality".
- Regarding canvas height/width: they are designed for canvas generation. If you want to upload images directly, you can safely ignore them.
Source | Input | Output |
---|---|---|
(no preprocessor) | ||
(no preprocessor) | ||
Input | Output |
---|---|
- (Windows) (NVIDIA: Ampere) 4gb - with
--xformers
enabled, andLow VRAM
mode ticked in the UI, goes up to 768x832
The original ControlNet applies control to both conditional (cond) and unconditional (uncond) parts. Enabling this option will make the control only apply to the cond part. Some experiments indicate that this approach improves image quality.
To enable this option, tick Enable CFG-Based guidance for ControlNet
in the settings.
Note that you need to use a low cfg scale/guidance scale (such as 3-5) and proper weight tuning to get good result.
Guess Mode is CFG Based ControlNet + Exponential decay in weighting.
See issue Mikubill#236 for more details.
Original introduction from controlnet:
The "guess mode" (or called non-prompt mode) will completely unleash all the power of the very powerful ControlNet encoder.
In this mode, you can just remove all prompts, and then the ControlNet encoder will recognize the content of the input control map, like depth map, edge map, scribbles, etc.
This mode is very suitable for comparing different methods to control stable diffusion because the non-prompted generating task is significantly more difficult than prompted task. In this mode, different methods' performance will be very salient.
For this mode, we recommend to use 50 steps and guidance scale between 3 and 5.
This option allows multiple ControlNet inputs for a single generation. To enable this option, change Multi ControlNet: Max models amount (requires restart)
in the settings. Note that you will need to restart the WebUI for changes to take effect.
- Guess Mode will apply to all ControlNet if any of them are enabled.
Source A | Source B | Output |
---|---|---|