Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SD3 Controlnet
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
| raw | control image | output |
|
7 |
+
|:-------------------------:|:-------------------------:|:-------------------------:|
|
8 |
+
|<img src="./raw.jpg" width = "400" /> | <img src="./canny.jpg" width = "400" /> | <img src="./demo_1.jpg" width = "400" /> |
|
9 |
+
|
10 |
+
|
11 |
+
# Install Diffusers-SD3-Controlnet
|
12 |
+
|
13 |
+
The current [diffusers](https://github.com/instantX-research/diffusers_sd3_control.git) have not been merged into the official code yet.
|
14 |
+
|
15 |
+
```cmd
|
16 |
+
git clone -b sd3_control https://github.com/instantX-research/diffusers_sd3_control.git
|
17 |
+
cd diffusers
|
18 |
+
pip install -e .
|
19 |
+
```
|
20 |
+
|
21 |
+
# Demo
|
22 |
+
```python
|
23 |
+
import torch
|
24 |
+
from diffusers import StableDiffusion3Pipeline
|
25 |
+
from diffusers.models.controlnet_sd3 import ControlNetSD3Model
|
26 |
+
from diffusers.utils.torch_utils import randn_tensor
|
27 |
+
import sys, os
|
28 |
+
sys.path.append('/path/diffusers/examples/community')
|
29 |
+
from pipeline_stable_diffusion_3_controlnet import StableDiffusion3CommonPipeline
|
30 |
+
# load pipeline
|
31 |
+
base_model = 'stabilityai/stable-diffusion-3-medium-diffusers'
|
32 |
+
pipe = StableDiffusion3CommonPipeline.from_pretrained(
|
33 |
+
base_model,
|
34 |
+
controlnet_list=['InstantX/SD3-Controlnet-Canny_alpha_512']
|
35 |
+
)
|
36 |
+
pipe.to('cuda:0', torch.float16)
|
37 |
+
prompt = 'Anime style illustration of a girl wearing a suit. A moon in sky. In the background we see a big rain approaching. text "InstantX" on image'
|
38 |
+
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
39 |
+
# controlnet config
|
40 |
+
controlnet_conditioning = [
|
41 |
+
dict(
|
42 |
+
control_index=0,
|
43 |
+
control_image=load_image('https://huggingface.co/InstantX/SD3-Controlnet-Canny/resolve/main/canny.jpg'),
|
44 |
+
control_weight=0.7,
|
45 |
+
control_pooled_projections='zeros'
|
46 |
+
)
|
47 |
+
]
|
48 |
+
# infer
|
49 |
+
image = pipe(
|
50 |
+
prompt=prompt,
|
51 |
+
negative_prompt=n_prompt,
|
52 |
+
controlnet_conditioning=controlnet_conditioning,
|
53 |
+
num_inference_steps=28,
|
54 |
+
guidance_scale=7.0,
|
55 |
+
height=1024,
|
56 |
+
width=1024,
|
57 |
+
latents=latents,
|
58 |
+
).images[0]
|
59 |
+
```
|