File size: 1,983 Bytes
2319a41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import torch
from PIL import Image
from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig

import os

pipe = QwenImagePipeline.from_pretrained(
    torch_dtype=torch.bfloat16,
    device="cuda",
    model_configs=[
        ModelConfig(model_id="Qwen/Qwen-Image-Edit-2509", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),
        ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"),
        ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
    ],
    tokenizer_config=None,
    processor_config=ModelConfig(model_id="Qwen/Qwen-Image-Edit", origin_file_pattern="processor/"),
)


qwen_image_style_transfer_lora_model='./diffsynth_Qwen-Image-Edit-2509-Style-Transfer-V1.safetensors'

qwen_image_speedup_lora_model='./diffsynth_Qwen-Image-Edit-2509-Lightning-4steps-V1.0-bf16.safetensors'

pipe.load_lora(pipe.dit, qwen_image_style_transfer_lora_model)
pipe.load_lora(pipe.dit, qwen_image_speedup_lora_model)



content_ref='' #content reference image
style_ref=''#style reference image
    
prompt = 'Style Transfer the style of Figure 2 to Figure 1, and keep the content and characteristics of Figure 1.'




w,h=Image.open(content_ref).convert("RGB").size



minedge=1024
if w>h:
    r=w/h
    h=minedge
    w=int(h*r)-int(h*r)%16
    
else:
    r=h/w
    w=minedge
    h=int(w*r)-int(w*r)%16

images = [
    Image.open(content_ref).convert("RGB").resize((w, h)),
    Image.open(style_ref).convert("RGB").resize((minedge, minedge)) ,
]



image = pipe(prompt, edit_image=images, seed=123, num_inference_steps=4, height=h, width=w,edit_image_auto_resize=False,cfg_scale=1.0)#ligtning



save_dir=f'./qwen_style_output/'

os.makedirs(save_dir,exist_ok=True)
prefix=style_ref.split('/')[-1].split('.')[0]


image.save(os.path.join(save_dir, f'{prefix}_result.png'))


print(f"saved to {os.path.join(save_dir, f'{prefix}_result.png')}")