Image does not get edited, what am I getting wrong?

#31
by r3lativo - opened

The image remains the same at each iteration, it just gets degradated in the quality

code:

import os
from PIL import Image
import torch

from diffusers import QwenImageEditPipeline

model_name = "Qwen/Qwen-Image-Edit"

# Load the pipeline
if torch.cuda.is_available():
    torch_dtype = torch.bfloat16
    device = "cuda"
else:
    torch_dtype = torch.float32
    device = "cpu"

pipeline = QwenImageEditPipeline.from_pretrained(model_name, torch_dtype=torch_dtype)
pipeline = pipeline.to(device)

positive_magic = ", black and white, sketch, composition, simple."

prompts = ["A bar lounge with a LED-lit sign near the restroom entrance", "Add a man sitting at the counter", "Add a coloured mojito on the right of the counter"]

image_path = "./canvas.png"  # A 1024*1024 white PNG image

for idx, prompt in enumerate(prompts):
    
    print(image_path)
    print(prompt + positive_magic)  # checking I'm using the right things
    
    inputs = {
        "image": Image.open(image_path).convert("RGB"),
        "prompt": prompt + positive_magic,
        "negative_prompt": negative_prompt,
        "generator": torch.Generator(device="cuda").manual_seed(42),
        #"true_cfg_scale": 4.0, # tried with and without it
        "num_inference_steps": 50,  
    }
      
    with torch.inference_mode():
        output = pipeline(**inputs)
        output_image = output.images[0]
        output_path = f"lounge_{idx}.png"
        output_image.save(output_path)
        print("image saved at", os.path.abspath(output_path))
    
    # Reassign the newly generated image as the input for the next iteration
    image_path = output_path

First iteration
lounge_0.png

Second iteration
lounge_1.png

Third iteration
lounge_2.png

Sign up or log in to comment