From 88925cfd73f238dd9fa0ed2d5fda51a9826d77ff Mon Sep 17 00:00:00 2001 From: Talhax55z Date: Fri, 3 Apr 2026 21:33:15 +0500 Subject: [PATCH 1/2] Fix object detection pipeline to process all batched images, not just first --- .../pipelines/object_detection.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/transformers/pipelines/object_detection.py b/src/transformers/pipelines/object_detection.py index 0a4fba996d7d..f342b7cb8955 100644 --- a/src/transformers/pipelines/object_detection.py +++ b/src/transformers/pipelines/object_detection.py @@ -159,21 +159,21 @@ def unnormalize(bbox): else: # This is a regular ForObjectDetectionModel raw_annotations = self.image_processor.post_process_object_detection(model_outputs, threshold, target_size) - raw_annotation = raw_annotations[0] - scores = raw_annotation["scores"] - labels = raw_annotation["labels"] - boxes = raw_annotation["boxes"] - - raw_annotation["scores"] = scores.tolist() - raw_annotation["labels"] = [self.model.config.id2label[label.item()] for label in labels] - raw_annotation["boxes"] = [self._get_bounding_box(box) for box in boxes] - - # {"scores": [...], ...} --> [{"score":x, ...}, ...] - keys = ["score", "label", "box"] - annotation = [ - dict(zip(keys, vals)) - for vals in zip(raw_annotation["scores"], raw_annotation["labels"], raw_annotation["boxes"]) - ] + annotation = [] + for raw_annotation in raw_annotations: + scores = raw_annotation["scores"] + labels = raw_annotation["labels"] + boxes = raw_annotation["boxes"] + + raw_annotation["scores"] = scores.tolist() + raw_annotation["labels"] = [self.model.config.id2label[label.item()] for label in labels] + raw_annotation["boxes"] = [self._get_bounding_box(box) for box in boxes] + + keys = ["score", "label", "box"] + annotation.append([ + dict(zip(keys, vals)) + for vals in zip(raw_annotation["scores"], raw_annotation["labels"], raw_annotation["boxes"]) + ]) return annotation From 1d9b99333c3bd1ea54e1184e06d3106dc8be9719 Mon Sep 17 00:00:00 2001 From: Talhax55z Date: Mon, 6 Apr 2026 15:14:36 +0500 Subject: [PATCH 2/2] Fix code quality formatting --- src/transformers/pipelines/object_detection.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/transformers/pipelines/object_detection.py b/src/transformers/pipelines/object_detection.py index f342b7cb8955..eaa2fdfa3a83 100644 --- a/src/transformers/pipelines/object_detection.py +++ b/src/transformers/pipelines/object_detection.py @@ -170,10 +170,12 @@ def unnormalize(bbox): raw_annotation["boxes"] = [self._get_bounding_box(box) for box in boxes] keys = ["score", "label", "box"] - annotation.append([ - dict(zip(keys, vals)) - for vals in zip(raw_annotation["scores"], raw_annotation["labels"], raw_annotation["boxes"]) - ]) + annotation.append( + [ + dict(zip(keys, vals)) + for vals in zip(raw_annotation["scores"], raw_annotation["labels"], raw_annotation["boxes"]) + ] + ) return annotation