Views
No views yet

| Entity Control Condition | Generated Image |
|---|---|
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
git clone https://github.com/modelscope/DiffSynth-Studio.git
cd DiffSynth-Studio
pip install -e .1from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig
2from modelscope import dataset_snapshot_download, snapshot_download
3import torch
4from PIL import Image1pipe = QwenImagePipeline.from_pretrained(
2 torch_dtype=torch.bfloat16,
3 device="cuda",
4 model_configs=[
5 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),
6 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"),
7 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
8 ],
9 tokenizer_config=ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="tokenizer/"),
10)
11snapshot_download("DiffSynth-Studio/Qwen-Image-EliGen", local_dir="models/DiffSynth-Studio/Qwen-Image-EliGen", allow_file_pattern="model.safetensors")
12pipe.load_lora(pipe.dit, "models/DiffSynth-Studio/Qwen-Image-EliGen/model.safetensors")
13
14global_prompt = "Poster for the Qwen-Image-EliGen Magic Café, featuring two magical coffees—one emitting flames and the other emitting ice spikes—against a light blue misty background, with text reading 'Qwen-Image-EliGen Magic Café' and 'New Arrival'"
15entity_prompts = ["A red magic coffee with flames rising from the cup",
16 "A red magic coffee surrounded by ice spikes",
17 "Text: 'New Arrival'",
18 "Text: 'Qwen-Image-EliGen Magic Café'"]
19
20dataset_snapshot_download(dataset_id="DiffSynth-Studio/examples_in_diffsynth", local_dir="./", allow_file_pattern=f"data/examples/eligen/qwen-image/example_6/*.png")
21masks = [Image.open(f"./data/examples/eligen/qwen-image/example_6/{i}.png").convert('RGB').resize((1328, 1328)) for i in range(len(entity_prompts))]
22
23image = pipe(
24 prompt=global_prompt,
25 seed=0,
26 eligen_entity_prompts=entity_prompts,
27 eligen_entity_masks=masks,
28)
29image.save("image.jpg")@article{zhang2025eligen,
title={Eligen: Entity-level Controlled Image Generation with Regional Attention},
author={Zhang, Hong and Duan, Zhongjie and Wang, Xingjun and Chen, Yingda and Zhang, Yu},
journal={arXiv preprint arXiv:2501.01097},
year={2025}
}