Update README.md
Browse files
README.md
CHANGED
|
@@ -134,12 +134,12 @@ pipe = FluxFillCFGPipeline.from_pretrained(
|
|
| 134 |
torch_dtype=torch.bfloat16).to("cuda")
|
| 135 |
```
|
| 136 |
|
| 137 |
-
###
|
| 138 |
```python
|
| 139 |
-
image = load_image('assets/
|
| 140 |
-
mask = load_image('assets/
|
| 141 |
image = pipe(
|
| 142 |
-
prompt='
|
| 143 |
negative_prompt="nsfw",
|
| 144 |
image=image,
|
| 145 |
mask_image=mask,
|
|
@@ -150,15 +150,15 @@ image = pipe(
|
|
| 150 |
num_inference_steps=50,
|
| 151 |
generator=torch.Generator("cpu").manual_seed(0)
|
| 152 |
).images[0]
|
| 153 |
-
image.save(f"
|
| 154 |
```
|
| 155 |
|
| 156 |
-
### Image Extend
|
| 157 |
```python
|
| 158 |
image = load_image('assets/image2.png')
|
| 159 |
mask = load_image('assets/mask_extend.png')
|
| 160 |
image = pipe(
|
| 161 |
-
prompt='
|
| 162 |
negative_prompt="nsfw",
|
| 163 |
image=image,
|
| 164 |
mask_image=mask,
|
|
@@ -169,15 +169,15 @@ image = pipe(
|
|
| 169 |
num_inference_steps=50,
|
| 170 |
generator=torch.Generator("cpu").manual_seed(0)
|
| 171 |
).images[0]
|
| 172 |
-
image.save(f"
|
| 173 |
```
|
| 174 |
|
| 175 |
-
###
|
| 176 |
```python
|
| 177 |
-
image = load_image('assets/
|
| 178 |
-
mask = load_image('assets/
|
| 179 |
image = pipe(
|
| 180 |
-
prompt='
|
| 181 |
negative_prompt="nsfw",
|
| 182 |
image=image,
|
| 183 |
mask_image=mask,
|
|
@@ -188,7 +188,55 @@ image = pipe(
|
|
| 188 |
num_inference_steps=50,
|
| 189 |
generator=torch.Generator("cpu").manual_seed(0)
|
| 190 |
).images[0]
|
| 191 |
-
image.save(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
```
|
| 193 |
|
| 194 |
|
|
|
|
| 134 |
torch_dtype=torch.bfloat16).to("cuda")
|
| 135 |
```
|
| 136 |
|
| 137 |
+
### Image Extend with prompt
|
| 138 |
```python
|
| 139 |
+
image = load_image('assets/image2.png')
|
| 140 |
+
mask = load_image('assets/mask_extend.png')
|
| 141 |
image = pipe(
|
| 142 |
+
prompt='Deep in the forest, surronded by colorful flowers',
|
| 143 |
negative_prompt="nsfw",
|
| 144 |
image=image,
|
| 145 |
mask_image=mask,
|
|
|
|
| 150 |
num_inference_steps=50,
|
| 151 |
generator=torch.Generator("cpu").manual_seed(0)
|
| 152 |
).images[0]
|
| 153 |
+
image.save(f"image_extend_w_prompt.jpg")
|
| 154 |
```
|
| 155 |
|
| 156 |
+
### Image Extend without prompt
|
| 157 |
```python
|
| 158 |
image = load_image('assets/image2.png')
|
| 159 |
mask = load_image('assets/mask_extend.png')
|
| 160 |
image = pipe(
|
| 161 |
+
prompt='high-definition, perfect composition', # using fix prompt in image extend wo prompt
|
| 162 |
negative_prompt="nsfw",
|
| 163 |
image=image,
|
| 164 |
mask_image=mask,
|
|
|
|
| 169 |
num_inference_steps=50,
|
| 170 |
generator=torch.Generator("cpu").manual_seed(0)
|
| 171 |
).images[0]
|
| 172 |
+
image.save(f"image_extend_wo_prompt.jpg")
|
| 173 |
```
|
| 174 |
|
| 175 |
+
### Object Removal
|
| 176 |
```python
|
| 177 |
+
image = load_image('assets/image.png')
|
| 178 |
+
mask = load_image('assets/mask_remove.png')
|
| 179 |
image = pipe(
|
| 180 |
+
prompt='remove', # using fix prompt in object removal
|
| 181 |
negative_prompt="nsfw",
|
| 182 |
image=image,
|
| 183 |
mask_image=mask,
|
|
|
|
| 188 |
num_inference_steps=50,
|
| 189 |
generator=torch.Generator("cpu").manual_seed(0)
|
| 190 |
).images[0]
|
| 191 |
+
image.save(f"object_removal.jpg")
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
### Object Removal with Lora
|
| 195 |
+
As the base model flux fill have undergone heavy SFT for object generation, the improvement on removal is not obvious. we release a lora for object removal separately and might be helpful for you.
|
| 196 |
+
|
| 197 |
+
```python
|
| 198 |
+
import torch
|
| 199 |
+
from diffusers.utils import load_image
|
| 200 |
+
from diffusers import FluxTransformer2DModel
|
| 201 |
+
|
| 202 |
+
from src.pipeline_flux_fill_with_cfg import FluxFillCFGPipeline
|
| 203 |
+
|
| 204 |
+
transformer_onereward = FluxTransformer2DModel.from_pretrained(
|
| 205 |
+
"bytedance-research/OneReward",
|
| 206 |
+
subfolder="flux.1-fill-dev-OneReward-transformer",
|
| 207 |
+
torch_dtype=torch.bfloat16
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
pipe = FluxFillCFGPipeline.from_pretrained(
|
| 211 |
+
"black-forest-labs/FLUX.1-Fill-dev",
|
| 212 |
+
transformer=transformer_onereward,
|
| 213 |
+
torch_dtype=torch.bfloat16).to("cuda")
|
| 214 |
+
|
| 215 |
+
pipe.load_lora_weights(
|
| 216 |
+
"bytedance-research/OneReward",
|
| 217 |
+
subfolder="flux.1-fill-dev-object-removal-lora",
|
| 218 |
+
weight_name="pytorch_lora_weights.safetensors",
|
| 219 |
+
adapter_name="object_removal_lora"
|
| 220 |
+
)
|
| 221 |
+
print("Loaded adapters:", pipe.get_list_adapters())
|
| 222 |
+
pipe.set_adapters(["object_removal_lora"], adapter_weights=[1.0])
|
| 223 |
+
|
| 224 |
+
# Object Removal
|
| 225 |
+
image = load_image('assets/image.png')
|
| 226 |
+
mask = load_image('assets/mask_remove.png')
|
| 227 |
+
image = pipe(
|
| 228 |
+
prompt='remove', # using fix prompt in object removal
|
| 229 |
+
negative_prompt="nsfw",
|
| 230 |
+
image=image,
|
| 231 |
+
mask_image=mask,
|
| 232 |
+
height=image.height,
|
| 233 |
+
width=image.width,
|
| 234 |
+
guidance_scale=1.0,
|
| 235 |
+
true_cfg=4.0,
|
| 236 |
+
num_inference_steps=50,
|
| 237 |
+
generator=torch.Generator("cpu").manual_seed(0),
|
| 238 |
+
).images[0]
|
| 239 |
+
image.save(f"object_removal_lora.jpg")
|
| 240 |
```
|
| 241 |
|
| 242 |
|