The QwenImageLayeredPipeline from diffusers allows you to decompose an input image into multiple RGBA layers.
Key Input Parameters:
image: The input image (must be converted to RGBA).layers: The number of layers to decompose the image into.resolution: Recommended resolution is 640.true_cfg_scale: Guidance scale.negative_prompt: Text prompt for what to avoid.cfg_normalize: Boolean to enable/disable CFG normalization.use_en_prompt: Boolean to automatically caption the image in English if no caption is provided.
Note: The text prompt should describe the overall content of the image (including occluded elements) rather than controlling individual layers explicitly. The model is fine-tuned for image-to-multi-RGBA decomposition; text-to-multi-RGBA generation performance is limited.
from diffusers import QwenImageLayeredPipeline
import torch
from PIL import Image
pipeline = QwenImageLayeredPipeline.from_pretrained("Qwen/Qwen-Image-Layered")
pipeline = pipeline.to("cuda", torch.bfloat16)
pipeline.set_progress_bar_config(disable=None)
image = Image.open("asserts/test_images/1.png").convert("RGBA")
inputs = {
"image": image,
"generator": torch.Generator(device='cuda').manual_seed(777),
"true_cfg_scale": 4.0,
"negative_prompt": " ",
"num_inference_steps": 50,
"num_images_per_prompt": 1,
"layers": 4,
"resolution": 640, # Using different bucket (640, 1024) to determine the resolution. For this version, 640 is recommended
"cfg_normalize": True, # Whether enable cfg normalization.
"use_en_prompt": True, # Automatic caption language if user does not provide caption,
}
with torch.inference_mode():
output = pipeline(**inputs)
output_image = output.images[0]
for i, image in enumerate(output_image):
image.save(f"{i}.png")