Skip to content

bug: Fix layout sorting when bbox is None (ChipperV1) #259

@0-hero

Description

@0-hero

Error

File "../unstructured-inference/inference/ordering.py", line 32, in order_layout 
        layout.sort(
     File "../unstructured-inference/inference/ordering.py", line 33, in <lambda>
        key=lambda element: (element.bbox.y1, element.bbox.x1, element.bbox.y2, element.bbox.x2), 
AttributeError: 'NoneType' object has no attribute 'y1'

Debugging

When running chipperv1 on a document, output for a page had the following element in the layout

LayoutElement(bbox=None, text='', source=<Source.CHIPPERV1: 'chipperv1'>, type='Picture', prob=None, image_path=None, parent=LayoutElement(bbox=Rectangle(x1=101.26530612244898, y1=87.20068027210884, x2=1654, y2=1675.0969387755104), text='', source=<Source.CHIPPERV1: 'chipperv1'>, type='Picture', prob=None, image_path=None, parent=None))

Possible Fix

Change unstructured_inference/inference/ordering.py line 33 from

layout.sort(
        key=lambda element: (element.bbox.y1, element.bbox.x1, element.bbox.y2, element.bbox.x2),
    )

to

layout.sort(
        key=lambda element: (
            float('inf') if element.bbox is None else element.bbox.y1,
            float('inf') if element.bbox is None else element.bbox.x1,
            float('inf') if element.bbox is None else element.bbox.y2,
            float('inf') if element.bbox is None else element.bbox.x2
        )
    )

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