| --- |
| frameworks: |
| - Pytorch |
| license: Apache License 2.0 |
| tasks: |
| - text-to-image-synthesis |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| base_model: |
| - Qwen/Qwen-Image |
| base_model_relation: adapter |
| new_version: DiffSynth-Studio/Qwen-Image-EliGen-V2 |
| --- |
| # Qwen-Image 精确分区控制模型 |
|
|
|  |
|
|
| ## 模型介绍 |
|
|
| 本模型是基于 [Qwen-Image](https://www.modelscope.cn/models/Qwen/Qwen-Image) 训练的精确分区控制模型,模型结构为 LoRA,可以通过输入每个实体的文本和区域条件(蒙版图)来控制每个实体的位置和形状。训练框架基于 [DiffSynth-Studio](https://github.com/modelscope/DiffSynth-Studio) 构建,采用的数据集是 [DiffSynth-Studio/EliGenTrainSet](https://www.modelscope.cn/datasets/DiffSynth-Studio/EliGenTrainSet)。 |
|
|
|
|
| ## 效果展示 |
|
|
| |实体控制条件|生成图| |
| |-|-| |
| ||| |
| ||| |
| ||| |
| ||| |
| ||| |
| ||| |
|
|
|
|
| ## 推理代码 |
| ``` |
| git clone https://github.com/modelscope/DiffSynth-Studio.git |
| cd DiffSynth-Studio |
| pip install -e . |
| ``` |
|
|
| ```python |
| from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig |
| from modelscope import dataset_snapshot_download, snapshot_download |
| import torch |
| from PIL import Image |
| |
| |
| pipe = QwenImagePipeline.from_pretrained( |
| torch_dtype=torch.bfloat16, |
| device="cuda", |
| model_configs=[ |
| ModelConfig(model_id="Qwen/Qwen-Image", 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=ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="tokenizer/"), |
| ) |
| snapshot_download("DiffSynth-Studio/Qwen-Image-EliGen", local_dir="models/DiffSynth-Studio/Qwen-Image-EliGen", allow_file_pattern="model.safetensors") |
| pipe.load_lora(pipe.dit, "models/DiffSynth-Studio/Qwen-Image-EliGen/model.safetensors") |
| |
| global_prompt = "Qwen-Image-EliGen魔法咖啡厅的宣传海报,主体是两杯魔法咖啡,一杯冒着火焰,一杯冒着冰锥,背景是浅蓝色水雾,海报写着“Qwen-Image-EliGen魔法咖啡厅”、“新品上市”" |
| entity_prompts = ["一杯红色魔法咖啡,杯中火焰燃烧", "一杯红色魔法咖啡,杯中冰锥环绕", "字:“新品上市”", "字:“Qwen-Image-EliGen魔法咖啡厅”"] |
| |
| dataset_snapshot_download(dataset_id="DiffSynth-Studio/examples_in_diffsynth", local_dir="./", allow_file_pattern=f"data/examples/eligen/qwen-image/example_6/*.png") |
| masks = [Image.open(f"./data/examples/eligen/qwen-image/example_6/{i}.png").convert('RGB').resize((1328, 1328)) for i in range(len(entity_prompts))] |
| |
| image = pipe( |
| prompt=global_prompt, |
| seed=0, |
| eligen_entity_prompts=entity_prompts, |
| eligen_entity_masks=masks, |
| ) |
| image.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} |
| } |
| ``` |