Skip to content

Fix: ObjectDetectionPipeline batch inference only returns first image results#45223

Open
Talhax55z wants to merge 2 commits intohuggingface:mainfrom
Talhax55z:fix-object-detection-batching
Open

Fix: ObjectDetectionPipeline batch inference only returns first image results#45223
Talhax55z wants to merge 2 commits intohuggingface:mainfrom
Talhax55z:fix-object-detection-batching

Conversation

@Talhax55z
Copy link
Copy Markdown

Fixes #31356

What does this PR do?

The postprocess method in ObjectDetectionPipeline was hardcoding
raw_annotations[0], which caused batch inference to only return
results for the first image, ignoring all others.

This PR replaces the single-item access with a loop over all
raw_annotations, so every image in a batch gets processed correctly.

Changes

  • src/transformers/pipelines/object_detection.py: replaced
    raw_annotation = raw_annotations[0] with a for loop over
    all annotations

  • I confirm that this is not a pure code agent PR.

@Rocketknight1

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45223&sha=1d9b99

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object Detection Pipeline only outputs first element when batching

1 participant