Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
DN6 merged 11 commits into huggingface:main from Trgtuan10:main
Aug 13, 2025
Merged

Conversation

Copy link
Contributor

@Trgtuan10 Trgtuan10 commented Aug 10, 2025
edited
Loading

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?

J4BEZ, john-rocky, ghunkins, TuanNT-ZenAI, Angericky, and toyxyz reacted with thumbs up emoji john-rocky, ghunkins, TuanNT-ZenAI, and toyxyz reacted with hooray emoji
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:

Copy link
Contributor 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.

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

DN6 commented Aug 12, 2025

@Trgtuan10 You just have to change from diffusers.pipelines.qwenimage.pipeline_qwenimage in the copied from statement on the pipeline methods to from diffusers.pipelines.qwenimage.pipeline_qwenimage.QwenImagePipeline

Trgtuan10 reacted with hooray emoji Trgtuan10 reacted with rocket emoji

Copy link
Contributor Author

Thanks @DN6

Copy link
Collaborator

DN6 commented Aug 13, 2025

@Trgtuan10 Pushed up minor changes to your branch for style and copy checks to pass. FYI you don't need to merge into main on your fork before opening the PR. It's better to open from your working branch.

Trgtuan10 reacted with rocket emoji

@DN6 DN6 merged commit da096a4 into huggingface:main Aug 13, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@a-r-r-o-w a-r-r-o-w a-r-r-o-w left review comments

@DN6 DN6 DN6 approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /