Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,141 @@
|
|
| 1 |
-
---
|
| 2 |
-
license:
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: flux-1-dev-non-commercial-license
|
| 4 |
+
license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
library_name: diffusers
|
| 8 |
+
pipeline_tag: text-to-image
|
| 9 |
+
tags:
|
| 10 |
+
- Text-to-Image
|
| 11 |
+
- ControlNet
|
| 12 |
+
- Diffusers
|
| 13 |
+
- Flux.1-dev
|
| 14 |
+
- image-generation
|
| 15 |
+
- Stable Diffusion
|
| 16 |
+
base_model:
|
| 17 |
+
- Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# FLUX.1-dev-ControlNet-Union-Pro-2.0 (fp8)
|
| 21 |
+
|
| 22 |
+
This repository contains an unified ControlNet for FLUX.1-dev model released by [Shakker Labs](https://huggingface.co/Shakker-Labs). We provide an [online demo](https://huggingface.co/spaces/Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0).
|
| 23 |
+
|
| 24 |
+
# Keynotes
|
| 25 |
+
In comparison with [Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro](https://huggingface.co/Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro),
|
| 26 |
+
- Remove mode embedding, has smaller model size.
|
| 27 |
+
- Improve on canny and pose, better control and aesthetics.
|
| 28 |
+
- Add support for soft edge. Remove support for tile.
|
| 29 |
+
|
| 30 |
+
# Model Cards
|
| 31 |
+
- This ControlNet consists of 6 double blocks and 0 single block. Mode embedding is removed.
|
| 32 |
+
- We train the model from scratch for 300k steps using a dataset of 20M high-quality general and human images. We train at 512x512 resolution in BFloat16, batch size = 128, learning rate = 2e-5, the guidance is uniformly sampled from [1, 7]. We set the text drop ratio to 0.20.
|
| 33 |
+
- This model supports multiple control modes, including canny, soft edge, depth, pose, gray. You can use it just as a normal ControlNet.
|
| 34 |
+
- This model can be jointly used with other ControlNets.
|
| 35 |
+
|
| 36 |
+
# Showcases
|
| 37 |
+
|
| 38 |
+
<table>
|
| 39 |
+
<tr>
|
| 40 |
+
<td><img src="./images/canny.png" alt="canny" style="height:100%"></td>
|
| 41 |
+
</tr>
|
| 42 |
+
<tr>
|
| 43 |
+
<td><img src="./images/softedge.png" alt="softedge" style="height:100%"></td>
|
| 44 |
+
</tr>
|
| 45 |
+
<tr>
|
| 46 |
+
<td><img src="./images/pose.png" alt="pose" style="height:100%"></td>
|
| 47 |
+
</tr>
|
| 48 |
+
<tr>
|
| 49 |
+
<td><img src="./images/depth.png" alt="depth" style="height:100%"></td>
|
| 50 |
+
</tr>
|
| 51 |
+
<tr>
|
| 52 |
+
<td><img src="./images/gray.png" alt="gray" style="height:100%"></td>
|
| 53 |
+
</tr>
|
| 54 |
+
</table>
|
| 55 |
+
|
| 56 |
+
# Inference
|
| 57 |
+
```python
|
| 58 |
+
import torch
|
| 59 |
+
from diffusers.utils import load_image
|
| 60 |
+
from diffusers import FluxControlNetPipeline, FluxControlNetModel
|
| 61 |
+
|
| 62 |
+
base_model = 'black-forest-labs/FLUX.1-dev'
|
| 63 |
+
controlnet_model_union = 'Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0'
|
| 64 |
+
|
| 65 |
+
controlnet = FluxControlNetModel.from_pretrained(controlnet_model_union, torch_dtype=torch.bfloat16)
|
| 66 |
+
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
|
| 67 |
+
pipe.to("cuda")
|
| 68 |
+
|
| 69 |
+
# replace with other conds
|
| 70 |
+
control_image = load_image("./conds/canny.png")
|
| 71 |
+
width, height = control_image.size
|
| 72 |
+
|
| 73 |
+
prompt = "A young girl stands gracefully at the edge of a serene beach, her long, flowing hair gently tousled by the sea breeze. She wears a soft, pastel-colored dress that complements the tranquil blues and greens of the coastal scenery. The golden hues of the setting sun cast a warm glow on her face, highlighting her serene expression. The background features a vast, azure ocean with gentle waves lapping at the shore, surrounded by distant cliffs and a clear, cloudless sky. The composition emphasizes the girl's serene presence amidst the natural beauty, with a balanced blend of warm and cool tones."
|
| 74 |
+
|
| 75 |
+
image = pipe(
|
| 76 |
+
prompt,
|
| 77 |
+
control_image=control_image,
|
| 78 |
+
width=width,
|
| 79 |
+
height=height,
|
| 80 |
+
controlnet_conditioning_scale=0.7,
|
| 81 |
+
control_guidance_end=0.8,
|
| 82 |
+
num_inference_steps=30,
|
| 83 |
+
guidance_scale=3.5,
|
| 84 |
+
generator=torch.Generator(device="cuda").manual_seed(42),
|
| 85 |
+
).images[0]
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
# Multi-Inference
|
| 89 |
+
```python
|
| 90 |
+
import torch
|
| 91 |
+
from diffusers.utils import load_image
|
| 92 |
+
|
| 93 |
+
# https://github.com/huggingface/diffusers/pull/11350, after merging, you can directly import from diffusers
|
| 94 |
+
# from diffusers import FluxControlNetPipeline, FluxControlNetModel
|
| 95 |
+
|
| 96 |
+
# use local files for this moment
|
| 97 |
+
from pipeline_flux_controlnet import FluxControlNetPipeline
|
| 98 |
+
from controlnet_flux import FluxControlNetModel
|
| 99 |
+
|
| 100 |
+
base_model = 'black-forest-labs/FLUX.1-dev'
|
| 101 |
+
controlnet_model_union = 'Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0'
|
| 102 |
+
|
| 103 |
+
controlnet = FluxControlNetModel.from_pretrained(controlnet_model_union, torch_dtype=torch.bfloat16)
|
| 104 |
+
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=[controlnet], torch_dtype=torch.bfloat16) # use [] to enable multi-CNs
|
| 105 |
+
pipe.to("cuda")
|
| 106 |
+
|
| 107 |
+
# replace with other conds
|
| 108 |
+
control_image = load_image("./conds/canny.png")
|
| 109 |
+
width, height = control_image.size
|
| 110 |
+
|
| 111 |
+
prompt = "A young girl stands gracefully at the edge of a serene beach, her long, flowing hair gently tousled by the sea breeze. She wears a soft, pastel-colored dress that complements the tranquil blues and greens of the coastal scenery. The golden hues of the setting sun cast a warm glow on her face, highlighting her serene expression. The background features a vast, azure ocean with gentle waves lapping at the shore, surrounded by distant cliffs and a clear, cloudless sky. The composition emphasizes the girl's serene presence amidst the natural beauty, with a balanced blend of warm and cool tones."
|
| 112 |
+
|
| 113 |
+
image = pipe(
|
| 114 |
+
prompt,
|
| 115 |
+
control_image=[control_image, control_image], # try with different conds such as canny&depth, pose&depth
|
| 116 |
+
width=width,
|
| 117 |
+
height=height,
|
| 118 |
+
controlnet_conditioning_scale=[0.35, 0.35],
|
| 119 |
+
control_guidance_end=[0.8, 0.8],
|
| 120 |
+
num_inference_steps=30,
|
| 121 |
+
guidance_scale=3.5,
|
| 122 |
+
generator=torch.Generator(device="cuda").manual_seed(42),
|
| 123 |
+
).images[0]
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
# Recommended Parameters
|
| 127 |
+
You can adjust controlnet_conditioning_scale and control_guidance_end for stronger control and better detail preservation. For better stability, we highly suggest to use detailed prompt, for some cases, multi-conditions help.
|
| 128 |
+
- Canny: use cv2.Canny, controlnet_conditioning_scale=0.7, control_guidance_end=0.8.
|
| 129 |
+
- Soft Edge: use [AnylineDetector](https://github.com/huggingface/controlnet_aux), controlnet_conditioning_scale=0.7, control_guidance_end=0.8.
|
| 130 |
+
- Depth: use [depth-anything](https://github.com/DepthAnything/Depth-Anything-V2), controlnet_conditioning_scale=0.8, control_guidance_end=0.8.
|
| 131 |
+
- Pose: use [DWPose](https://github.com/IDEA-Research/DWPose/tree/onnx), controlnet_conditioning_scale=0.9, control_guidance_end=0.65.
|
| 132 |
+
- Gray: use cv2.cvtColor, controlnet_conditioning_scale=0.9, control_guidance_end=0.8.
|
| 133 |
+
|
| 134 |
+
# Resources
|
| 135 |
+
- [InstantX/FLUX.1-dev-IP-Adapter](https://huggingface.co/InstantX/FLUX.1-dev-IP-Adapter)
|
| 136 |
+
- [InstantX/FLUX.1-dev-Controlnet-Canny](https://huggingface.co/InstantX/FLUX.1-dev-Controlnet-Canny)
|
| 137 |
+
- [Shakker-Labs/FLUX.1-dev-ControlNet-Depth](https://huggingface.co/Shakker-Labs/FLUX.1-dev-ControlNet-Depth)
|
| 138 |
+
- [Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro](https://huggingface.co/Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro)
|
| 139 |
+
|
| 140 |
+
# Acknowledgements
|
| 141 |
+
This model is developed by [Shakker Labs](https://huggingface.co/Shakker-Labs). The original idea is inspired by [xinsir/controlnet-union-sdxl-1.0](https://huggingface.co/xinsir/controlnet-union-sdxl-1.0). All copyright reserved.
|