Update README.md
Browse files
README.md
CHANGED
@@ -118,38 +118,62 @@ image = pipe(
|
|
118 |
|
119 |
# Multi-Controls Inference
|
120 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
import torch
|
122 |
from diffusers.utils import load_image
|
123 |
-
from
|
|
|
|
|
124 |
|
125 |
-
base_model = '
|
126 |
-
|
127 |
|
128 |
-
|
129 |
-
controlnet =
|
130 |
|
131 |
-
pipe =
|
132 |
pipe.to("cuda")
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
-
|
139 |
-
control_mode_canny = 0
|
140 |
|
141 |
-
|
142 |
|
|
|
143 |
image = pipe(
|
144 |
prompt,
|
145 |
-
control_image=
|
146 |
-
control_mode=
|
147 |
width=width,
|
148 |
height=height,
|
149 |
-
controlnet_conditioning_scale=
|
150 |
-
num_inference_steps=
|
151 |
-
|
152 |
-
|
|
|
153 |
).images[0]
|
154 |
|
155 |
```
|
|
|
118 |
|
119 |
# Multi-Controls Inference
|
120 |
```python
|
121 |
+
from huggingface_hub import hf_hub_download
|
122 |
+
import os
|
123 |
+
|
124 |
+
try:
|
125 |
+
local_dir = os.path.dirname(__file__)
|
126 |
+
except:
|
127 |
+
local_dir = '.'
|
128 |
+
|
129 |
+
hf_hub_download(repo_id="briaai/BRIA-4B-Adapt", filename='pipeline_bria.py', local_dir=local_dir)
|
130 |
+
hf_hub_download(repo_id="briaai/BRIA-4B-Adapt", filename='transformer_bria.py', local_dir=local_dir)
|
131 |
+
hf_hub_download(repo_id="briaai/BRIA-4B-Adapt", filename='bria_utils.py', local_dir=local_dir)
|
132 |
+
hf_hub_download(repo_id="briaai/BRIA-3.0-ControlNet-Union", filename='pipeline_bria_controlnet.py', local_dir=local_dir)
|
133 |
+
hf_hub_download(repo_id="briaai/BRIA-3.0-ControlNet-Union", filename='controlnet_bria.py', local_dir=local_dir)
|
134 |
+
|
135 |
+
|
136 |
import torch
|
137 |
from diffusers.utils import load_image
|
138 |
+
from controlnet_bria import BriaControlNetModel, BriaMultiControlNetModel
|
139 |
+
from pipeline_bria_controlnet import BriaControlNetPipeline
|
140 |
+
import PIL.Image as Image
|
141 |
|
142 |
+
base_model = 'briaai/BRIA-4B-Adapt'
|
143 |
+
controlnet_model = 'briaai/BRIA-3.0-ControlNet-Union'
|
144 |
|
145 |
+
controlnet = BriaControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
|
146 |
+
controlnet = BriaMultiControlNetModel([controlnet])
|
147 |
|
148 |
+
pipe = BriaControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16, trust_remote_code=True)
|
149 |
pipe.to("cuda")
|
150 |
|
151 |
+
# control_image_colorgrid = load_image("https://huggingface.co/briaai/BRIA-3.0-ControlNet-Union/resolve/main/colorgrid.jpg")
|
152 |
+
# control_image_pose = load_image("https://huggingface.co/briaai/BRIA-3.0-ControlNet-Union/resolve/main/pose.jpg")
|
153 |
+
|
154 |
+
control_image_colorgrid = Image.open("/home/ubuntu/spring/Infra/sd3/eval_results/control_images/colorgrid/38.jpg").convert("RGB")
|
155 |
+
control_image_pose = Image.open("/home/ubuntu/spring/Infra/sd3/eval_results/control_images/pose/38.jpg").convert("RGB")
|
156 |
+
|
157 |
+
control_image = [control_image_colorgrid, control_image_pose]
|
158 |
+
controlnet_conditioning_scale = [0.5, 0.5]
|
159 |
+
control_mode = [2, 5]
|
160 |
|
161 |
+
width, height = control_image[0].size
|
|
|
162 |
|
163 |
+
prompt = 'Two kids in jackets play near a tent in a forest with trees.'
|
164 |
|
165 |
+
generator = torch.Generator(device="cuda").manual_seed(555)
|
166 |
image = pipe(
|
167 |
prompt,
|
168 |
+
control_image=control_image,
|
169 |
+
control_mode=control_mode,
|
170 |
width=width,
|
171 |
height=height,
|
172 |
+
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
173 |
+
num_inference_steps=50,
|
174 |
+
max_sequence_length=128,
|
175 |
+
guidance_scale=5,
|
176 |
+
generator=generator
|
177 |
).images[0]
|
178 |
|
179 |
```
|