Views
No views yet
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
1import torch
2from diffusers.utils import load_image
3
4# pip install git+https://github.com/huggingface/diffusers
5from diffusers import QwenImageControlNetModel, QwenImageControlNetInpaintPipeline
6
7base_model = "Qwen/Qwen-Image"
8controlnet_model = "InstantX/Qwen-Image-ControlNet-Inpainting"
9
10controlnet = QwenImageControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
11
12pipe = QwenImageControlNetInpaintPipeline.from_pretrained(
13 base_model, controlnet=controlnet, torch_dtype=torch.bfloat16
14)
15pipe.to("cuda")
16
17image = load_image("https://huggingface.co/InstantX/Qwen-Image-ControlNet-Inpainting/resolve/main/assets/images/image1.png")
18mask_image = load_image("https://huggingface.co/InstantX/Qwen-Image-ControlNet-Inpainting/resolve/main/assets/masks/mask1.png")
19prompt = "一辆绿色的出租车行驶在路上"
20
21image = pipe(
22 prompt=prompt,
23 negative_prompt=" ",
24 control_image=image,
25 control_mask=mask_image,
26 controlnet_conditioning_scale=controlnet_conditioning_scale,
27 width=control_image.size[0],
28 height=control_image.size[1],
29 num_inference_steps=30,
30 true_cfg_scale=4.0,
31 generator=torch.Generator(device="cuda").manual_seed(42),
32).images[0]
33image.save(f"qwenimage_cn_inpaint_result.png")