Skip to content

reading .png not working #220

Description

@meissna

Great work and thank you for putting the model and code open source!
If you read .png images into PIL, they might have either 3 or 4 channels, depending if they are transparent.
If a 4 channel .png-Image is used as input_images in:
results = pipeline(
prompt=instruction,
input_images=input_images,

I get an error.
To fix it, add .convert("RGB") after reading in the PIL-Image. e.g. in the preprocess-function.

def preprocess(input_image_path: List[str] = []) -> Tuple[str, str, List[Image.Image]]:
"""Preprocess the input images."""
# Process input images
input_images = []

if input_image_path:
    if isinstance(input_image_path, str):
        input_image_path = [input_image_path]
        
    if len(input_image_path) == 1 and os.path.isdir(input_image_path[0]):
        input_images = [Image.open(os.path.join(input_image_path[0], f)).convert("RGB") 
                      for f in os.listdir(input_image_path[0])]
    else:
        input_images = [Image.open(path).convert("RGB") for path in input_image_path]

    input_images = [ImageOps.exif_transpose(img) for img in input_images]

return input_images

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions