simonw / simonw/llm

embed-multi with CLIP - error message not very helpful in pinpointing the file that causes the error

Open
#422 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
12.5k
Forks
998
Avg merge
3d 13h
Merged PRs (30d)
10

Description

I ran llm embed-multi gallery --files pictures '**/*.png' --binary -m clip to embed hundreds of PNG files with the CLIP model, and the model encountered error on an image and threw a Traceback like this:
image

...
- image_processor: CLIPImageProcessor {
  "crop_size": {
    "height": 224,
    "width": 224
  },
  "do_center_cr...
  File "/Users/tscp/.local/pipx/venvs/llm/lib/python3.11/site-packages/transformers/image_processing_utils.py", line 552, in __call__
    return self.preprocess(images, **kwargs)
           │               │         └ {'return_tensors': 'pt', 'padding': True}
           │               └ [<PIL.PngImagePlugin.PngImageFile image mode=RGB size=4032x3024 at 0x130EFD750>, <PIL.PngImagePlugin.PngImageFile image mode=RGB...
           └ CLIPImageProcessor {
  "crop_size": {
    "height": 224,
    "width": 224
  },
  "do_center_crop": true,
  "do_convert_rgb": tru...
  File "/Users/tscp/.local/pipx/venvs/llm/lib/python3.11/site-packages/transformers/models/clip/image_processing_clip.py", line 283, in preprocess
    images = [convert_to_rgb(image) for image in images]
    │         │                                  └ [<PIL.PngImagePlugin.PngImageFile image mode=RGB size=4032x3024 at 0x130EFD750>, <PIL.PngImagePlugin.PngImageFile image mode=RGB...
    │         └ <function convert_to_rgb at 0x13050fc40>
    └ [<PIL.PngImagePlugin.PngImageFile image mode=RGB size=4032x3024 at 0x130EFD750>, <PIL.PngImagePlugin.PngImageFile image mode=RGB...
  File "/Users/tscp/.local/pipx/venvs/llm/lib/python3.11/site-packages/transformers/models/clip/image_processing_clip.py", line 283, in <listcomp>
    images = [convert_to_rgb(image) for image in images]
              │              │          └ <PIL.PngImagePlugin.PngImageFile image mode=RGB size=3024x4032 at 0x130EFADD0>
              │              └ <PIL.PngImagePlugin.PngImageFile image mode=RGB size=3024x4032 at 0x130EFADD0>
              └ <function convert_to_rgb at 0x13050fc40>
  File "/Users/tscp/.local/pipx/venvs/llm/lib/python3.11/site-packages/transformers/image_transforms.py", line 762, in convert_to_rgb
    image = image.convert("RGB")
    │       └ <PIL.PngImagePlugin.PngImageFile image mode=RGB size=3024x4032 at 0x130EFADD0>
    └ <PIL.PngImagePlugin.PngImageFile image mode=RGB size=3024x4032 at 0x130EFADD0>
  File "/Users/tscp/.local/pipx/venvs/llm/lib/python3.11/site-packages/PIL/Image.py", line 922, in convert
    self.load()
    └ <PIL.PngImagePlugin.PngImageFile image mode=RGB size=3024x4032 at 0x130EFADD0>
  File "/Users/tscp/.local/pipx/venvs/llm/lib/python3.11/site-packages/PIL/ImageFile.py", line 278, in load
    raise OSError(msg) from e
                  └ 'image file is truncated'
OSError: image file is truncated

I can see the image that caused the error was <PIL.PngImagePlugin.PngImageFile image mode=RGB size=3024x4032 at 0x130EFADD0>, but I didn't know the path of that particular image.

Do you think it'd be a good idea to handle such exceptions when running embedding with more than 1 file by also outputing the path that causes the error?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the llm embed-multi command and trace how multiple files are loaded and passed to the CLIP embedding model. Reproduce the failure with the command shown, then ensure an exception identifies the source path for the failing image; done means the error output names that path.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.