Skip to content

added tensor and numpy array support for image input in Flux2KleinPipeline#13265

Open
abhixb wants to merge 1 commit intohuggingface:mainfrom
abhixb:fix/flux2-klein-tensor-input
Open

added tensor and numpy array support for image input in Flux2KleinPipeline#13265
abhixb wants to merge 1 commit intohuggingface:mainfrom
abhixb:fix/flux2-klein-tensor-input

Conversation

@abhixb
Copy link

@abhixb abhixb commented Mar 14, 2026

Fixed issue #13177

The problem

If you pass a tensor or numpy array as the image to the Klein pipeline, it errors even though the docstring explicitly says these types are supported. Three things cause this:

  • The image processor's validation method has a hard isinstance check for PIL and just rejects everything else on the spot
  • The image loop in the pipeline's call method does image_width, image_height = img.size which is PIL only on a tensor .size is a method, on a numpy array it's a single int, both explode when you try to unpack them
  • The type annotation on the image parameter only mentions PIL types, so your IDE would tell you not to even try

The fix

  • Added a to_pil helper on the image processor that converts tensors and numpy arrays into PIL images, PIL inputs just pass through
  • Wired it into the validation method so it converts first, validates second, and returns a guaranteed PIL image
  • The call method's image loop now uses that return value instead of throwing it away
  • Updated the type annotation to match the docstring

Nothing changes for people already passing PIL images, same code path as before.

Tests

Added tests for tensor input, numpy input, and a list of tensors for multi-reference editing. Existing PIL test still passes. All 4 green locally.

@abhixb abhixb changed the title This PR fixes ISSUE #13177 This PR adds tensor and numpy array support for image input in Flux2KleinPipeline Mar 14, 2026
@abhixb abhixb changed the title This PR adds tensor and numpy array support for image input in Flux2KleinPipeline added tensor and numpy array support for image input in Flux2KleinPipeline Mar 14, 2026
@abhixb
Copy link
Author

abhixb commented Mar 15, 2026

@sayakpaul hello can u please look into/review this

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.

1 participant