Team Ai
Modelpublic

DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Canny

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
README_from_modelscope.md92 linesDownload Raw Back to root
1---2frameworks:3- Pytorch4license: Apache License 2.05tasks:6- text-to-image-synthesis7 8#model-type:9##如 gpt、phi、llama、chatglm、baichuan 等10#- gpt11 12#domain:13##如 nlp、cv、audio、multi-modal14#- nlp15 16#language:17##语言代码列表 https://help.aliyun.com/document_detail/215387.html?spm=a2c4g.11186623.0.0.9f8d7467kni6Aa18#- cn19 20#metrics:21##如 CIDEr、Blue、ROUGE 等22#- CIDEr23 24#tags:25##各种自定义,包括 pretrained、fine-tuned、instruction-tuned、RL-tuned 等训练方法和其他26#- pretrained27 28#tools:29##如 vllm、fastchat、llamacpp、AdaSeq 等30#- vllm31base_model:32  - Qwen/Qwen-Image33base_model_relation: adapter34---35# Qwen-Image 图像结构控制模型36 37![](./assets/title.png)38 39## 模型介绍40 41本模型是基于 [Qwen-Image](https://www.modelscope.cn/models/Qwen/Qwen-Image) 训练的图像结构控制模型,模型结构为 ControlNet,可根据边缘检测(Canny)图控制生成的图像结构。训练框架基于 [DiffSynth-Studio](https://github.com/modelscope/DiffSynth-Studio) 构建,采用的数据集是 [BLIP3o](https://modelscope.cn/datasets/BLIP3o/BLIP3o-60k)。42 43 44## 效果展示45 46|结构图|生成图1|生成图2|47|-|-|-|48|![](./assets/canny_3.png)|![](./assets/image_3_1.png)|![](./assets/image_3_2.png)|49|![](./assets/canny_2.png)|![](./assets/image_2_1.png)|![](./assets/image_2_2.png)|50|![](./assets/canny_1.png)|![](./assets/image_1_1.png)|![](./assets/image_1_2.png)|51 52## 推理代码53```54git clone https://github.com/modelscope/DiffSynth-Studio.git  55cd DiffSynth-Studio56pip install -e .57```58 59```python60from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig, ControlNetInput61from PIL import Image62import torch63from modelscope import dataset_snapshot_download64 65 66pipe = QwenImagePipeline.from_pretrained(67    torch_dtype=torch.bfloat16,68    device="cuda",69    model_configs=[70        ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),71        ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"),72        ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),73        ModelConfig(model_id="DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Canny", origin_file_pattern="model.safetensors"),74    ],75    tokenizer_config=ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="tokenizer/"),76)77 78dataset_snapshot_download(79    dataset_id="DiffSynth-Studio/example_image_dataset",80    local_dir="./data/example_image_dataset",81    allow_file_pattern="canny/image_1.jpg"82)83controlnet_image = Image.open("data/example_image_dataset/canny/image_1.jpg").resize((1328, 1328))84 85prompt = "一只小狗,毛发光洁柔顺,眼神灵动,背景是樱花纷飞的春日庭院,唯美温馨。"86image = pipe(87    prompt, seed=0,88    blockwise_controlnet_inputs=[ControlNetInput(image=controlnet_image)]89)90image.save("image.jpg")91```92