Skip to content

Add QwenImage Inpainting and Img2Img pipeline #12117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Trgtuan10
Copy link

@Trgtuan10 Trgtuan10 commented Aug 10, 2025

What does this PR do?

This PR introduces support for the QwenImage model in both Inpainting and Img2Img tasks, expanding the model’s creative capabilities and integration within the Diffusers library.

1. Image to Image

Example code

import torch
from diffusers import QwenImageImg2ImgPipeline
from diffusers.utils import load_image

pipe = QwenImageImg2ImgPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16,)
pipe = pipe.to("cuda")

init_image = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/cute_cat.png?raw=true")

prompt = "wizard dog, Gandalf-inspired, Lord of the Rings aesthetic, majestic yet cute, Studio Ghibli style"
negative_prompt = ""

strengths = [0.6, 0.7, 0.8, 0.9, 1.0]

for s in strengths:
    out = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        image=init_image,
        height=init_image.size[1],
        width=init_image.size[0],
        strength=s,
        num_inference_steps=35,
        true_cfg_scale=4.0,
        generator=torch.Generator(device="cuda").manual_seed(42),
    )
    out.images[0].save(f"example_img2img_{s}.png")

Results at different strengths

Init image
0.6
0.7
0.8
0.9
1.0

2. Inpainting

Example code

import torch
from PIL import Image
from diffusers import QwenImageInpaintPipeline
from diffusers.utils import load_image

pipe = QwenImageInpaintPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16)
pipe.to("cuda")
prompt = "cat wizard with red hat, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney"
negative_prompt = " "
source = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/cute_cat.png?raw=true")
mask = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/mask_cat.png?raw=true")

strengths = [0.6, 0.7, 0.8, 0.9, 1.0]

for strength in strengths:
    image = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        height=source.size[1],
        width=source.size[0],
        image=source,
        mask_image=mask,
        strength=strength,
        num_inference_steps=35,
        true_cfg_scale=4.0,
        generator=torch.Generator(device="cuda").manual_seed(42)
    ).images[0]
    image.save(f"qwen_inpainting_{strength}.png")

Results at different strengths

Init image
Mask
0.6
0.7
0.8
0.9
1.0

Before submitting

Who can review?

Copy link
Member

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The PR looks super clean :) Just have some nits about # Copied from convention we follow. Other than that, looks good to me

Could you also update the qwenimage.md in docs/ folder to reflect these pipelines:

@Trgtuan10
Copy link
Author

@a-r-r-o-w I’ve finished updating qwenimage.md to reflect the pipelines and fixed the # Copied from convention. Please take a look at the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants