Skip to content

FFDetrDetector.extract_widgets crashes with AttributeError: 'list' object has no attribute 'with_nms' #40

Description

@johnynetralabs

Running prepare_form() with the FFDetr model throws this on a single-page PDF:

AttributeError: 'list' object has no attribute 'with_nms'

Traced it to FFDetrDetector.extract_widgets in inference.py:

for b in batch([p.image for p in pages], n=batch_size):
predictions = self.model.predict(b, threshold=confidence)
if len(pages) == 1 or batch_size == 1:
predictions = [predictions]
results.extend(predictions)

batch() always yields a list, even for one image, so predict(b, ...) already returns a list of Detections (one per image in the batch). The if len(pages) == 1 or batch_size == 1: predictions = [predictions] line wraps that list again, so results ends up with [Detections_obj] (a plain list) instead of the Detections_obj itself. Then later when it calls detections.with_nms(...) on that, it blows up since it's a list, not a Detections object.

Also noticed the log line "Page 0: 1 fields detected" is wrong because of this — it's counting the outer list length (1), not actual detections.

Fix: just drop the wrapping block, it's not needed:

for b in batch([p.image for p in pages], n=batch_size):
predictions = self.model.predict(b, threshold=confidence)
results.extend(predictions)

Tested locally on a single-page PDF and it processes fine after removing those two lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions