Fix: ObjectDetectionPipeline batch inference only returns first image results#45223
Fix: ObjectDetectionPipeline batch inference only returns first image results#45223Talhax55z wants to merge 2 commits intohuggingface:mainfrom
Conversation
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45223&sha=1d9b99 |
|
Is that issue not closed already? |
|
|
I understand that, but I think batching/unbatching is handled outside of |
|
Hi @Rocketknight1, I ran a reproducer on the current main branch from transformers import pipeline
pipe = pipeline('object-detection', model='facebook/detr-resnet-50')
images = [
'https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png',
'https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png'
]
result = pipe(images)
print('Number of images input:', len(images)) # 2
print('Number of results returned:', len(result)) # 2 ✅
print('Type of result[0]:', type(result[0])) # <class 'list'>Without the fix, |
|
When I run this on main I get which is identical to the output you pasted above |
|
Thank you for checking @Rocketknight1! That's really helpful to know. I'll close this PR. I appreciate your patience in explaining this — |
Fixes #31356
What does this PR do?
The
postprocessmethod inObjectDetectionPipelinewas hardcodingraw_annotations[0], which caused batch inference to only returnresults 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: replacedraw_annotation = raw_annotations[0]with a for loop overall annotations
I confirm that this is not a pure code agent PR.
@Rocketknight1