---
title: Qwen-Image-Blockwise-ControlNet-Inpaint
canonical_url: "https://www.modelscope.cn/models/DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint"
md_url: "https://www.modelscope.cn/models/DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint.md"
repository: DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint
chinese_name: "Qwen-Image 图像局部重绘模型-Inpaint ControlNet"
last_updated: 2025-08-21
license: "Apache License 2.0"
pipeline_tag: text-to-image-synthesis
tasks:
  - text-to-image-synthesis
base_model:
  - Qwen/Qwen-Image
base_model_relation: adapter
parameters: 1.1B
tensor_type:
  - BF16
library_name:
  - pytorch
  - safetensors
frameworks:
  - Pytorch
downloads: 5388
stars: 23
---

# Qwen-Image-Blockwise-ControlNet-Inpaint

> Qwen-Image-Blockwise-ControlNet-Inpaint - DiffSynth-Studio 在 ModelScope 开源的模型。本模型是基于 Qwen-Image 训练的图像局部重绘模型模型，模型结构为 ControlNet，可根据对图像的局部区域进行重绘。训练框架基于 DiffSynth-Studio 构建，采用的数据集是 Qwen-Image-Self-Generated-Dataset。

DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint 是 ModelScope 魔搭社区上的 1.1B 参数text-to-image-synthesis模型，采用 Apache License 2.0 许可，基于 Qwen/Qwen-Image 构建。

- **Repository**: DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint
- **License**: Apache License 2.0
- **Tasks**: text-to-image-synthesis
- **Parameters**: 1.1B
- **Base model**: Qwen/Qwen-Image
- **Downloads**: 5388
- **Stars**: 23
- **Last updated**: 2025-08-21

Source: https://www.modelscope.cn/models/DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint

---

# Qwen-Image 图像结构控制模型

![](./assets/cover.png)

## 模型介绍

本模型是基于 [Qwen-Image](https://www.modelscope.cn/models/Qwen/Qwen-Image) 训练的图像局部重绘模型模型，模型结构为 ControlNet，可根据对图像的局部区域进行重绘。训练框架基于 [DiffSynth-Studio](https://github.com/modelscope/DiffSynth-Studio) 构建，采用的数据集是 [Qwen-Image-Self-Generated-Dataset](https://www.modelscope.cn/datasets/DiffSynth-Studio/Qwen-Image-Self-Generated-Dataset)。

这个模型同时兼容 [Qwen-Image](https://www.modelscope.cn/models/Qwen/Qwen-Image) 和 [Qwen-Image-Edit](https://www.modelscope.cn/models/Qwen/Qwen-Image-Edit)，在 Qwen-Image 上可进行局部重绘，在 Qwen-Image-Edit 上可编辑指定区域。

## 效果展示

|输入Prompt|输入图|重绘图|
|-|-|-|
|A robot with wings and a hat standing in a colorful garden with flowers and butterflies.|![](./assets/image_1_1.jpg)|![](./assets/image_1_2.jpg)|
|A girl in a school uniform stands gracefully in front of a vibrant stained glass window with colorful geometric patterns.|![](./assets/image_2_1.jpg)|![](./assets/image_2_2.jpg)|
|A small wooden boat battles against towering, crashing waves in a stormy sea.|![](./assets/image_3_1.png)|![](./assets/image_3_2.png)|

## 局限性
- 基于 ControlNet 结构的 Inpaint 模型可能会导致重绘区域与非重绘区域的边界不和谐。
- 模型基于矩形框的重绘数据训练，对非矩形区域的重绘泛化性可能不佳。

## 推理代码
```
git clone https://github.com/modelscope/DiffSynth-Studio.git  
cd DiffSynth-Studio
pip install -e .
```

Qwen-Image：

```python
import torch
from PIL import Image
from modelscope import dataset_snapshot_download
from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig, ControlNetInput


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"),
        ModelConfig(model_id="DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint", origin_file_pattern="model.safetensors"),
    ],
    tokenizer_config=ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="tokenizer/"),
)

dataset_snapshot_download(
    dataset_id="DiffSynth-Studio/example_image_dataset",
    local_dir="./data/example_image_dataset",
    allow_file_pattern="inpaint/*.jpg"
)
prompt = "a cat with sunglasses"
controlnet_image = Image.open("./data/example_image_dataset/inpaint/image_1.jpg").convert("RGB").resize((1328, 1328))
inpaint_mask = Image.open("./data/example_image_dataset/inpaint/mask.jpg").convert("RGB").resize((1328, 1328))
image = pipe(
    prompt, seed=0,
    input_image=controlnet_image, inpaint_mask=inpaint_mask,
    blockwise_controlnet_inputs=[ControlNetInput(image=controlnet_image, inpaint_mask=inpaint_mask)],
    num_inference_steps=40,
)
image.save("image.jpg")
```

Qwen-Image-Edit：

```python
import torch
from PIL import Image
from modelscope import dataset_snapshot_download
from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig, ControlNetInput


pipe = QwenImagePipeline.from_pretrained(
    torch_dtype=torch.bfloat16,
    device="cuda",
    model_configs=[
        ModelConfig(model_id="Qwen/Qwen-Image-Edit", 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"),
        ModelConfig(model_id="DiffSynth-Studio/Qwen-Image-Blockwise-ControlNet-Inpaint", origin_file_pattern="model.safetensors"),
    ],
    tokenizer_config=None,
    processor_config=ModelConfig(model_id="Qwen/Qwen-Image-Edit", origin_file_pattern="processor/"),
)

dataset_snapshot_download(
    dataset_id="DiffSynth-Studio/example_image_dataset",
    local_dir="./data/example_image_dataset",
    allow_file_pattern="inpaint/*.jpg"
)
prompt = "Put sunglasses on this cat"
controlnet_image = Image.open("./data/example_image_dataset/inpaint/image_1.jpg").convert("RGB").resize((1328, 1328))
inpaint_mask = Image.open("./data/example_image_dataset/inpaint/mask.jpg").convert("RGB").resize((1328, 1328))
image = pipe(
    prompt, seed=0,
    input_image=controlnet_image, inpaint_mask=inpaint_mask,
    blockwise_controlnet_inputs=[ControlNetInput(image=controlnet_image, inpaint_mask=inpaint_mask)],
    num_inference_steps=40,
    edit_image=controlnet_image, # add edit_image here.
)
image.save("image.jpg")
```
