Unstructured-IO / Unstructured-IO/unstructured

bug/None text attribute when normalizing Picture to Image element

Open
#4,084 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
HTML
Stars
15.5k
Forks
1.3k
Avg merge
4d 2h
Merged PRs (30d)
13

Description

Describe the bug
When using yolox as the Hi-res model for loading outputs / annotations, it annotates with bbox dimensions but missing text for complex images, resulting in text being set to None. But later on printing or accessing the Image element (__str__ method), it should be returning string instead of None.

To Reproduce

from langchain_community.document_loaders.image import UnstructuredImageLoader
from unstructured_inference.models.base import DEFAULT_MODEL

import os

img_loader = UnstructuredImageLoader(
            "5.jpg", # can rename the attached images
            hi_res_model_name=DEFAULT_MODEL,
        )

data = img_loader.load()

for i in data:
    print(i)

OR

from unstructured.partition.image import partition_image

elements = partition_image("5.jpg", hi_res_model_name=DEFAULT_MODEL)

print(elements)

for el in elements:
    print(el)

Expected behavior
Even if an image is detected with bbox but missing text, we should set the text to empty string instrad of "None" which ends up with exception when we try to print Image element (__str__ method).

Screenshots

Image

Test Images

Image Image

Environment Info

unstructured             0.18.13
unstructured-client      0.42.3
unstructured-inference   1.0.5
unstructured-pytesseract 0.3.15
detectron2               0.6
torch                    2.8.0
torchvision              0.23.0

Additional context
This issue is also related to this issue.

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 with the Image element’s str method and the partition_image and UnstructuredImageLoader entry points shown in the reproduction. Trace how a detected image with missing text is normalized, then verify that it uses an empty string and that printing the resulting elements completes without an exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.