-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object Detection Pipeline only outputs first element when batching #31356
Comments
It looks like that the output of the _forward function is correct (batch). |
cc @qubvel |
Hi @simonschoenhofen, thanks for reporting this! Would you like to open a PR to address this? |
@amyeroberts Will do tomorrow |
Adding a good first issue label in case anyone from the community wants to add this |
hmm.. I was not able to reproduce the bug, the following example works fine. @simonschoenhofen were you able to solve this issue? from transformers import pipeline
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
pipe = pipeline("object-detection", model="PekingU/rtdetr_r50vd", device="cuda")
results = pipe([url] * 4, batch_size=2)
for i, result in enumerate(results):
print(f"Image {i}:\n{result}\n")
|
@qubvel
|
@royvelich Yes this example works, but the results are weird and do not match with results running the model outside of the pipeline. While I suspect that "object-detection" pipeline doesn't have an issue, it looks like "zero-shot-object-detection" pipeline is not working properly with grounding dino |
@qubvel So, do you recommend using your example for now and avoiding the pipeline? |
@royvelich yes, please, use grounding dino model, not a |
@qubvel the def postprocess(self, model_outputs, threshold=0.1, top_k=None):
results = []
for model_output in model_outputs:
label = model_output["candidate_label"]
model_output = BaseModelOutput(model_output)
outputs = self.image_processor.post_process_object_detection(
outputs=model_output, threshold=threshold, target_sizes=model_output["target_size"]
)[0]
... while the grounding dino hf post says The |
Hi @shankram, thank you for investigating this! Indeed there is a problem with the pipeline for zero-shot object detection for some models. I've prepared a PR fixing a pipeline, its not yet merged, but already functional |
System Info
transformers
version: 4.41.2When running the ObjectDetectionPipeline in a batch, the output will only be the bounding boxes of the first input image due to ObjectDetectionPipeline.py accessing element [0] in postprocessing and not looping over all outputs.
transformers/src/transformers/pipelines/object_detection.py
Line 150 in a4e1a1d
This accesses only and always the first element, instead of looping over all outputs.
Only the first element is accessed in postprocessing
Who can help?
@Narsil
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
pipe = pipeline("object-detection", model=model_name, image_processor=preprocessor_name, device=device)
for out in tqdm(pipe(dataset, batch_size=batch_size)):
Expected behavior
Expected Output: 2 Elements with each x items (bboxes).
Actual Output, only bboxes of the first input element.
The text was updated successfully, but these errors were encountered: