Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -8,7 +8,6 @@ language:
|
|
| 8 |
library_name: diffusers
|
| 9 |
pipeline_tag: text-to-image
|
| 10 |
---
|
| 11 |
-
|
| 12 |
<div align="center">
|
| 13 |
<h1>Qwen-Image-Pruning</h1>
|
| 14 |
<a href='https://github.com/OPPO-Mente-Lab/Qwen-Image-Pruning'><img src="https://img.shields.io/badge/GitHub-OPPOer-blue.svg?logo=github" alt="GitHub"></a>
|
|
@@ -20,3 +19,166 @@ This open-source project is based on Qwen-Image and has attempted model pruning,
|
|
| 20 |
<div align="center">
|
| 21 |
<img src="bench.png">
|
| 22 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
library_name: diffusers
|
| 9 |
pipeline_tag: text-to-image
|
| 10 |
---
|
|
|
|
| 11 |
<div align="center">
|
| 12 |
<h1>Qwen-Image-Pruning</h1>
|
| 13 |
<a href='https://github.com/OPPO-Mente-Lab/Qwen-Image-Pruning'><img src="https://img.shields.io/badge/GitHub-OPPOer-blue.svg?logo=github" alt="GitHub"></a>
|
|
|
|
| 19 |
<div align="center">
|
| 20 |
<img src="bench.png">
|
| 21 |
</div>
|
| 22 |
+
|
| 23 |
+
## Quick Start
|
| 24 |
+
|
| 25 |
+
Install the latest version of diffusers and pytorch
|
| 26 |
+
```
|
| 27 |
+
pip install torch
|
| 28 |
+
pip install git+https://github.com/huggingface/diffusers
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
### 1. Qwen-Image-Pruning Inference
|
| 32 |
+
```python
|
| 33 |
+
import torch
|
| 34 |
+
import os
|
| 35 |
+
from diffusers import DiffusionPipeline
|
| 36 |
+
|
| 37 |
+
model_name = "OPPOer/Qwen-Image-Pruning"
|
| 38 |
+
|
| 39 |
+
if torch.cuda.is_available():
|
| 40 |
+
torch_dtype = torch.bfloat16
|
| 41 |
+
device = "cuda"
|
| 42 |
+
else:
|
| 43 |
+
torch_dtype = torch.bfloat16
|
| 44 |
+
device = "cpu"
|
| 45 |
+
|
| 46 |
+
pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype)
|
| 47 |
+
pipe = pipe.to(device)
|
| 48 |
+
|
| 49 |
+
# Generate image
|
| 50 |
+
positive_magic = {"en": ", Ultra HD, 4K, cinematic composition.", # for english prompt,
|
| 51 |
+
"zh": ",超清,4K,电影级构图。" # for chinese prompt,
|
| 52 |
+
}
|
| 53 |
+
negative_prompt = " "
|
| 54 |
+
|
| 55 |
+
prompts = [
|
| 56 |
+
'一个穿着"QWEN"标志的T恤的中国美女正拿着黑色的马克笔面相镜头微笑。她身后的玻璃板上手写体写着 "一、Qwen-Image的技术路线: 探索视觉生成基础模型的极限,开创理解与生成一体化的未来。二、Qwen-Image的模型特色:1、复杂文字渲染。支持中英渲染、自动布局; 2、精准图像编辑。支持文字编辑、物体增减、风格变换。三、Qwen-Image的未来愿景:赋能专业内容创作、助力生成式AI发展。"',
|
| 57 |
+
'海报,温馨家庭场景,柔和阳光洒在野餐布上,色彩温暖明亮,主色调为浅黄、米白与淡绿,点缀着鲜艳的水果和野花,营造轻松愉快的氛围,画面简洁而富有层次,充满生活气息,传达家庭团聚与自然和谐的主题。文字内容:“共享阳光,共享爱。全家一起野餐,享受美好时光。让每一刻都充满欢笑与温暖。”',
|
| 58 |
+
'一个穿着校服的年轻女孩站在教室里,在黑板上写字。黑板中央用整洁的白粉笔写着“Introducing Qwen-Image, a foundational image generation model that excels in complex text rendering and precise image editing”。柔和的自然光线透过窗户,投下温柔的阴影。场景以写实的摄影风格呈现,细节精细,景深浅,色调温暖。女孩专注的表情和空气中的粉笔灰增添了动感。背景元素包括课桌和教育海报,略微模糊以突出中心动作。超精细32K分辨率,单反质量,柔和的散景效果,纪录片式的构图。',
|
| 59 |
+
'一个台球桌上放着两排台球,每排5个,第一行的台球上面分别写着"Qwen""Image" "将 "于" "8" ,第二排台球上面分别写着"月" "正" "式" "发" "布" 。',
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
output_dir = 'examples_Pruning'
|
| 63 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 64 |
+
for prompt in prompts:
|
| 65 |
+
output_img_path = f"{output_dir}/{prompt[:80]}.png"
|
| 66 |
+
image = pipe(
|
| 67 |
+
prompt=prompt + positive_magic['zh'],
|
| 68 |
+
negative_prompt=negative_prompt,
|
| 69 |
+
width=1328,
|
| 70 |
+
height=1328,
|
| 71 |
+
num_inference_steps=8,
|
| 72 |
+
true_cfg_scale=1,
|
| 73 |
+
generator=torch.Generator(device="cuda").manual_seed(42)
|
| 74 |
+
).images[0]
|
| 75 |
+
image.save(output_img_path)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### 2. Qwen-Image-Pruning & Realism-LoRA Inference
|
| 79 |
+
```python
|
| 80 |
+
import torch
|
| 81 |
+
import os
|
| 82 |
+
from diffusers import DiffusionPipeline
|
| 83 |
+
|
| 84 |
+
model_name = "OPPOer/Qwen-Image-Pruning"
|
| 85 |
+
lora_name = 'flymy_realism.safetensors'
|
| 86 |
+
|
| 87 |
+
if torch.cuda.is_available():
|
| 88 |
+
torch_dtype = torch.bfloat16
|
| 89 |
+
device = "cuda"
|
| 90 |
+
else:
|
| 91 |
+
torch_dtype = torch.bfloat16
|
| 92 |
+
device = "cpu"
|
| 93 |
+
|
| 94 |
+
pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype)
|
| 95 |
+
pipe = pipe.to(device)
|
| 96 |
+
pipe.load_lora_weights(lora_name, adapter_name="lora")
|
| 97 |
+
|
| 98 |
+
# Generate image
|
| 99 |
+
positive_magic = {"en": ", Ultra HD, 4K, cinematic composition.", # for english prompt,
|
| 100 |
+
"zh": ",超清,4K,电影级构图。" # for chinese prompt,
|
| 101 |
+
}
|
| 102 |
+
negative_prompt = " "
|
| 103 |
+
|
| 104 |
+
prompts = [
|
| 105 |
+
'一个穿着"QWEN"标志的T恤的中国美女正拿着黑色的马克笔面相镜头微笑。她身后的玻璃板上手写体写着 "一、Qwen-Image的技术路线: 探索视觉生成基础模型的极限,开创理解与生成一体化的未来。二、Qwen-Image的模型特色:1、复杂文字渲染。支持中英渲染、自动布局; 2、精准图像编辑。支持文字编辑、物体增减、风格变换。三、Qwen-Image的未来愿景:赋能专业内容创作、助力生成式AI发展。"',
|
| 106 |
+
'海报,温馨家庭场景,柔和阳光洒在野餐布上,色彩温暖明亮,主色调为浅黄、米白与淡绿,点缀着鲜艳的水果和野花,营造轻松愉快的氛围,画面简洁而富有层次,充满生活气息,传达家庭团聚与自然和谐的主题。文字内容:“共享阳光,共享爱。全家一起野餐��享受美好时光。让每一刻都充满欢笑与温暖。”',
|
| 107 |
+
'一个穿着校服的年轻女孩站在教室里,在黑板上写字。黑板中央用整洁的白粉笔写着“Introducing Qwen-Image, a foundational image generation model that excels in complex text rendering and precise image editing”。柔和的自然光线透过窗户,投下温柔的阴影。场景以写实的摄影风格呈现,细节精细,景深浅,色调温暖。女孩专注的表情和空气中的粉笔灰增添了动感。背景元素包括课桌和教育海报,略微模糊以突出中心动作。超精细32K分辨率,单反质量,柔和的散景效果,纪录片式的构图。',
|
| 108 |
+
'一个台球桌上放着两排台球,每排5个,第一行的台球上面分别写着"Qwen""Image" "将 "于" "8" ,第二排台球上面分别写着"月" "正" "式" "发" "布" 。',
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
output_dir = 'examples_Pruning+Realism_LoRA'
|
| 112 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 113 |
+
for prompt in prompts:
|
| 114 |
+
output_img_path = f"{output_dir}/{prompt[:80]}.png"
|
| 115 |
+
image = pipe(
|
| 116 |
+
prompt=prompt + positive_magic['zh'],
|
| 117 |
+
negative_prompt=negative_prompt,
|
| 118 |
+
width=1328,
|
| 119 |
+
height=1328,
|
| 120 |
+
num_inference_steps=8,
|
| 121 |
+
true_cfg_scale=1,
|
| 122 |
+
generator=torch.Generator(device="cuda").manual_seed(42)
|
| 123 |
+
).images[0]
|
| 124 |
+
image.save(output_img_path)
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
### 3. Qwen-Image-Pruning & ControlNet Inference
|
| 128 |
+
```python
|
| 129 |
+
import os
|
| 130 |
+
import glob
|
| 131 |
+
|
| 132 |
+
import torch
|
| 133 |
+
from diffusers import DiffusionPipeline
|
| 134 |
+
|
| 135 |
+
from diffusers.utils import load_image
|
| 136 |
+
from diffusers import QwenImageControlNetPipeline, QwenImageControlNetModel
|
| 137 |
+
|
| 138 |
+
model_name = "OPPOer/Qwen-Image-Pruning"
|
| 139 |
+
controlnet_name = "InstantX/Qwen-Image-ControlNet-Union"
|
| 140 |
+
|
| 141 |
+
# Load the pipeline
|
| 142 |
+
if torch.cuda.is_available():
|
| 143 |
+
torch_dtype = torch.bfloat16
|
| 144 |
+
device = "cuda"
|
| 145 |
+
else:
|
| 146 |
+
torch_dtype = torch.bfloat16
|
| 147 |
+
device = "cpu"
|
| 148 |
+
|
| 149 |
+
controlnet = QwenImageControlNetModel.from_pretrained(controlnet_name, torch_dtype=torch.bfloat16)
|
| 150 |
+
|
| 151 |
+
pipe = QwenImageControlNetPipeline.from_pretrained(
|
| 152 |
+
model_name, controlnet=controlnet, torch_dtype=torch.bfloat16
|
| 153 |
+
)
|
| 154 |
+
pipe = pipe.to(device)
|
| 155 |
+
|
| 156 |
+
# Generate image
|
| 157 |
+
prompt_dict = {
|
| 158 |
+
"soft_edge.png": "Photograph of a young man with light brown hair jumping mid-air off a large, reddish-brown rock. He's wearing a navy blue sweater, light blue shirt, gray pants, and brown shoes. His arms are outstretched, and he has a slight smile on his face. The background features a cloudy sky and a distant, leafless tree line. The grass around the rock is patchy.",
|
| 159 |
+
"canny.png": "Aesthetics art, traditional asian pagoda, elaborate golden accents, sky blue and white color palette, swirling cloud pattern, digital illustration, east asian architecture, ornamental rooftop, intricate detailing on building, cultural representation.",
|
| 160 |
+
"depth.png": "A swanky, minimalist living room with a huge floor-to-ceiling window letting in loads of natural light. A beige couch with white cushions sits on a wooden floor, with a matching coffee table in front. The walls are a soft, warm beige, decorated with two framed botanical prints. A potted plant chills in the corner near the window. Sunlight pours through the leaves outside, casting cool shadows on the floor.",
|
| 161 |
+
"pose.png": "Photograph of a young man with light brown hair and a beard, wearing a beige flat cap, black leather jacket, gray shirt, brown pants, and white sneakers. He's sitting on a concrete ledge in front of a large circular window, with a cityscape reflected in the glass. The wall is cream-colored, and the sky is clear blue. His shadow is cast on the wall.",
|
| 162 |
+
}
|
| 163 |
+
controlnet_conditioning_scale = 1.0
|
| 164 |
+
|
| 165 |
+
output_dir = f'examples_Pruning+ControlNet'
|
| 166 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 167 |
+
|
| 168 |
+
for path in glob.glob('conds/*'):
|
| 169 |
+
control_image = load_image(path)
|
| 170 |
+
image_name = path.split('/')[-1]
|
| 171 |
+
if image_name in prompt_dict:
|
| 172 |
+
image = pipe(
|
| 173 |
+
prompt=prompt_dict[image_name],
|
| 174 |
+
negative_prompt=" ",
|
| 175 |
+
control_image=control_image,
|
| 176 |
+
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 177 |
+
width=control_image.size[0],
|
| 178 |
+
height=control_image.size[1],
|
| 179 |
+
num_inference_steps=8,
|
| 180 |
+
true_cfg_scale=4.0,
|
| 181 |
+
generator=torch.Generator(device="cuda").manual_seed(42),
|
| 182 |
+
).images[0]
|
| 183 |
+
image.save(os.path.join(output_dir, image_name))
|
| 184 |
+
```
|