README.md
5.2 KB · 158 lines · markdown Raw
1 ---
2 license: other
3 license_name: qwen-research
4 license_link: LICENSE
5 pipeline_tag: text-to-image
6 tags:
7 - diffusers
8 - qwen
9 - image-generation
10 - image-editing
11 - rgba
12 ---
13
14 <p align="center">
15 <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/image2.1/logo.png" width="400"/>
16 </p>
17 <p align="center">
18 🤖 <a href="https://modelscope.cn/models/Qwen/Qwen-Image-2.1">ModelScope</a>&nbsp;&nbsp;|
19 &nbsp;&nbsp;🤗 <a href="https://huggingface.co/Qwen/Qwen-Image-2.1">HuggingFace</a>&nbsp;&nbsp;|
20 &nbsp;&nbsp;📑 <a href="https://qwen.ai/blog?id=qwen-image-2.1">Blog</a>&nbsp;&nbsp;|
21 &nbsp;&nbsp;🖥️ <a href="https://huggingface.co/spaces/Qwen/Qwen-Image-2.1">Demo</a>&nbsp;&nbsp;|
22 &nbsp;&nbsp;🫨 <a href="https://discord.gg/BEYSk3pkSu">Discord</a>&nbsp;&nbsp;|
23 &nbsp;&nbsp;💬 <a href="https://huggingface.co/Qwen/Qwen-Image-2.1/blob/main/assets/qr.png">WeChat</a>
24 </p>
25
26 ## Introduction
27
28 We are excited to open-source **Qwen-Image-2.1**, a unified text-to-image generation and image editing model in the Qwen family. With just **7B parameters in its visual generation component** (32 Single-Stream DiT layers), Qwen-Image-2.1 balances generation quality, inference efficiency, and versatility.
29
30 Four key improvements define this release:
31
32 - **Compact and Efficient** — A lightweight architecture with mixed-granularity attention and prefix KV cache reuse delivers strong image quality at low computational cost.
33 - **Native Transparency, Unified Creation and Editing** — Generate regular or transparent (RGBA) images from text, edit transparent layers, and extract subjects from photographs—all in one model.
34 - **Versatile Editing** — Support up to **10 reference images**, specify local edits via circles, painted annotations, or separate masks, and preserve identity for people and products.
35 - **Realistic Textures and Refined Aesthetics** — Improved typography, portrait lighting, and fine details for more visually compelling results.
36
37 <p align="center">
38 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-01.png" width="100%"/>
39 </p>
40
41 For more details, see the [GitHub repo](https://github.com/QwenLM/Qwen-Image-2.1) and [Blog](https://qwen.ai/blog?id=qwen-image-2.1).
42
43 ## Quick Start
44
45 ### Installation
46
47 ```bash
48 pip install torch>=2.4.0
49 pip install transformers>=5.17
50 pip install git+https://github.com/huggingface/diffusers
51 pip install accelerate pillow
52 ```
53
54 ### Text-to-Image
55
56 ```python
57 import torch
58 from diffusers import QwenImage21Pipeline
59
60 pipe = QwenImage21Pipeline.from_pretrained(
61 "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
62 ).to("cuda")
63
64 image = pipe(
65 prompt="A neon shop sign that reads \"QWEN IMAGE 2.1\", rainy night, reflections on wet pavement",
66 width=2048, height=2048,
67 num_inference_steps=40,
68 generator=torch.Generator("cuda").manual_seed(42),
69 ).images[0]
70
71 image.save("t2i_example.png")
72 ```
73
74 ### Image Editing
75
76 ```python
77 import torch
78 from PIL import Image
79 from diffusers import QwenImage21Pipeline
80
81 pipe = QwenImage21Pipeline.from_pretrained(
82 "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
83 ).to("cuda")
84
85 input_image = Image.open("input.png")
86
87 image = pipe(
88 prompt="Change the background to a sunset beach",
89 image=input_image,
90 num_inference_steps=40,
91 generator=torch.Generator("cuda").manual_seed(42),
92 ).images[0]
93
94 image.save("edit_example.png")
95 ```
96
97 ### Transparent Image Generation (RGBA)
98
99 Use the recommended prompt format for transparent images:
100
101 ```python
102 image = pipe(
103 prompt="This is an RGBA image with transparency. A cute cartoon dragon sticker. The image has alpha channel and the background is transparent.",
104 width=2048, height=2048,
105 num_inference_steps=40,
106 generator=torch.Generator("cuda").manual_seed(42),
107 ).images[0]
108
109 image.save("transparent_example.png")
110 ```
111
112 ### Supported Aspect Ratios
113
114 ```python
115 aspect_ratios = {
116 "1:1": (2048, 2048),
117 "4:3": (2400, 1792),
118 "3:4": (1792, 2400),
119 "3:2": (2528, 1696),
120 "2:3": (1696, 2528),
121 "16:9": (2752, 1536),
122 "9:16": (1536, 2752),
123 }
124 ```
125
126 ### Memory Optimization
127
128 ```python
129 pipe = QwenImage21Pipeline.from_pretrained(
130 "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
131 )
132 pipe.enable_model_cpu_offload()
133 ```
134
135 ## Showcase
136
137 <p align="center">
138 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-04.png" width="30%"/>
139 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-05.png" width="30%"/>
140 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-06.png" width="30%"/>
141 </p>
142 <p align="center"><em>Native transparent image generation</em></p>
143
144 <p align="center">
145 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-15.png" width="100%"/>
146 </p>
147 <p align="center"><em>Group photograph generated from six portrait references</em></p>
148
149 <p align="center">
150 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-43.png" width="48%"/>
151 <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-44.png" width="48%"/>
152 </p>
153 <p align="center"><em>Text rendering</em></p>
154
155 ## License
156
157 This model is licensed under the [Qwen Research License Agreement](./LICENSE).
158