Skip to content

Issue with FluxKontextPipeline #11886

@nitinmukesh

Description

@nitinmukesh

Describe the bug

If we pass width/height in inference no changes in output image.
If we do not pass width/height, it defaults to 1024 x 1024 and crop the image.

Source image used (832 x 1216)

Image

Reproduction

Working code but wrong image size as defaults to 1024 x 1024

import torch
from diffusers import FluxKontextPipeline
from diffusers.utils import load_image

pipeline = FluxKontextPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-Kontext-dev", 
    torch_dtype=torch.bfloat16
)
pipeline.enable_sequential_cpu_offload()
image = load_image(
    "https://huggingface.co/datasets/newgenai79/testing/resolve/main/women_with_hat.png"
).convert("RGB")

prompt = "Remove the hat"
image = pipeline(
    image=image, 
    prompt=prompt, 
    guidance_scale=2.5
).images[0]
image.save("flux-kontext-dev_working.png")

Output image (1024 x 1024)

Image

Not working

import torch
from diffusers import FluxKontextPipeline
from diffusers.utils import load_image

pipeline = FluxKontextPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-Kontext-dev", 
    torch_dtype=torch.bfloat16
)
pipeline.enable_sequential_cpu_offload()
image = load_image(
    "https://huggingface.co/datasets/newgenai79/testing/resolve/main/women_with_hat.png"
).convert("RGB")

prompt = "Remove the hat"
image = pipeline(
    image=image, 
    prompt=prompt, 
    width=832,
    height=1216,
    guidance_scale=2.5
).images[0]
image.save("flux-kontext-dev2.png")

Output image (832 x 1232)

Generation height and width have been adjusted to 1232 and 832 to fit the model requirements.

Image

Logs

Not required

System Info

latest from source

Who can help?

@a-r-r-o-w

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions