Skip to content

Commit 7beac79

Browse files
committed
update eligen logo_transfer
1 parent ce2476a commit 7beac79

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

examples/EntityControl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ Demonstration of the entity transfer results with EliGen and In-Context LoRA, se
8080

8181
|Entity to Transfer|Transfer Target Image|Transfer Example 1|Transfer Example 2|
8282
|-|-|-|-|
83-
|![image_1_base](https://github.com/user-attachments/assets/bb3d4a46-8d82-4d3c-bce8-8c01a9973b8d)|![image_1_enhance](https://github.com/user-attachments/assets/44c0f422-525e-42ca-991b-f407f8faafc3)|![image_1_enhance](https://github.com/user-attachments/assets/a042ff5b-2748-4d91-8321-cec8f9eb73e4)|![image_1_enhance](https://github.com/user-attachments/assets/98f2d1b1-16e1-4c8f-b521-5cd68b567293)|
83+
|![image_1_base](https://github.com/user-attachments/assets/0d40ef22-0a09-420d-bd5a-bfb93120b60d)|![image_1_enhance](https://github.com/user-attachments/assets/f6c58ef2-54c1-4d86-8429-dad2eb0e0685)|![image_1_enhance](https://github.com/user-attachments/assets/05eed2e3-097d-40af-8aae-1e0c75051f32)|![image_1_enhance](https://github.com/user-attachments/assets/54314d16-244b-411e-8a91-96c500efa5f5)|
Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from diffsynth import ModelManager, FluxImagePipeline, download_customized_models
2-
from diffsynth.data.video import crop_and_resize
32
from modelscope import dataset_snapshot_download
43
from examples.EntityControl.utils import visualize_masks
54
from PIL import Image
6-
import numpy as np
75
import torch
86

97

10-
118
def build_pipeline():
129
model_manager = ModelManager(torch_dtype=torch.bfloat16, device="cuda", model_id_list=["FLUX.1-dev"])
1310
model_manager.load_lora(
@@ -30,16 +27,13 @@ def build_pipeline():
3027
return pipe
3128

3229

33-
def generate(pipe: FluxImagePipeline, logo_image, target_image, mask, height, width, prompt, logo_prompt, image_save_path, mask_save_path):
34-
mask = Image.fromarray(np.concatenate([
35-
np.ones((height, width, 3), dtype=np.uint8) * 0,
36-
np.array(crop_and_resize(mask, height, width)),
37-
], axis=1))
30+
def generate(pipe: FluxImagePipeline, source_image, target_image, mask, height, width, prompt, entity_prompt, image_save_path, mask_save_path, seed=0):
31+
input_mask = Image.new('RGB', (width * 2, height))
32+
input_mask.paste(mask.resize((width, height), resample=Image.NEAREST).convert('RGB'), (width, 0))
3833

39-
input_image = Image.fromarray(np.concatenate([
40-
np.array(crop_and_resize(logo_image, height, width)),
41-
np.array(crop_and_resize(target_image, height, width)),
42-
], axis=1))
34+
input_image = Image.new('RGB', (width * 2, height))
35+
input_image.paste(source_image.resize((width, height)).convert('RGB'), (0, 0))
36+
input_image.paste(target_image.resize((width, height)).convert('RGB'), (width, 0))
4337

4438
image = pipe(
4539
prompt=prompt,
@@ -48,41 +42,43 @@ def generate(pipe: FluxImagePipeline, logo_image, target_image, mask, height, wi
4842
negative_prompt="",
4943
num_inference_steps=50,
5044
embedded_guidance=3.5,
51-
seed=0,
45+
seed=seed,
5246
height=height,
5347
width=width * 2,
54-
eligen_entity_prompts=[logo_prompt],
55-
eligen_entity_masks=[mask],
48+
eligen_entity_prompts=[entity_prompt],
49+
eligen_entity_masks=[input_mask],
5650
enable_eligen_on_negative=False,
5751
enable_eligen_inpaint=True,
5852
)
59-
image.save(image_save_path)
60-
visualize_masks(image, [mask], [logo_prompt], mask_save_path)
53+
target_image = image.crop((width, 0, 2 * width, height))
54+
target_image.save(image_save_path)
55+
visualize_masks(target_image, [mask], [entity_prompt], mask_save_path)
56+
return target_image
6157

6258

6359
pipe = build_pipeline()
6460

6561
dataset_snapshot_download(dataset_id="DiffSynth-Studio/examples_in_diffsynth", local_dir="./", allow_file_pattern="data/examples/eligen/logo_transfer/*")
66-
logo_image = Image.open("data/examples/eligen/logo_transfer/logo_transfer_logo.png")
67-
target_image = Image.open("data/examples/eligen/logo_transfer/logo_transfer_target_image.png")
6862

6963
prompt="The two-panel image showcases the joyful identity, with the left panel showing a rabbit graphic; [LEFT] while the right panel translates the design onto a shopping tote with the rabbit logo in black, held by a person in a market setting, emphasizing the brand's approachable and eco-friendly vibe."
7064
logo_prompt="a rabbit logo"
7165

72-
mask = Image.open("data/examples/eligen/logo_transfer/logo_transfer_mask_1.png")
66+
logo_image = Image.open("data/examples/eligen/logo_transfer/source_image.png")
67+
target_image = Image.open("data/examples/eligen/logo_transfer/target_image.png")
68+
mask = Image.open("data/examples/eligen/logo_transfer/mask_1.png")
7369
generate(
7470
pipe, logo_image, target_image, mask,
75-
height=1024, width=736,
76-
prompt=prompt, logo_prompt=logo_prompt,
71+
height=1024, width=1024,
72+
prompt=prompt, entity_prompt=logo_prompt,
7773
image_save_path="entity_transfer_1.png",
7874
mask_save_path="entity_transfer_with_mask_1.png"
7975
)
8076

81-
mask = Image.open("data/examples/eligen/logo_transfer/logo_transfer_mask_2.png")
77+
mask = Image.open("data/examples/eligen/logo_transfer/mask_2.png")
8278
generate(
8379
pipe, logo_image, target_image, mask,
84-
height=1024, width=736,
85-
prompt=prompt, logo_prompt=logo_prompt,
80+
height=1024, width=1024,
81+
prompt=prompt, entity_prompt=logo_prompt,
8682
image_save_path="entity_transfer_2.png",
8783
mask_save_path="entity_transfer_with_mask_2.png"
8884
)

0 commit comments

Comments
 (0)