def postprocess()

in optimum/amd/ryzenai/pipelines/object_detection.py [0:0]


    def postprocess(self, model_outputs, nms_threshold=0.45, threshold=0.25, data_format=None):
        results = []
        target_sizes = model_outputs.pop("target_sizes")
        outputs = self.image_processor.post_process_object_detection(
            outputs=model_outputs,
            target_sizes=target_sizes,
            threshold=threshold,
            nms_threshold=nms_threshold,
            data_format=data_format,
        )[0]

        scores = outputs["scores"]
        labels = outputs["labels"]
        boxes = outputs["boxes"]

        outputs["scores"] = scores.tolist()
        outputs["labels"] = [label.item() for label in labels]
        outputs["boxes"] = [self._get_bounding_box(box) for box in boxes]

        keys = ["score", "label", "box"]
        results = [dict(zip(keys, vals)) for vals in zip(outputs["scores"], outputs["labels"], outputs["boxes"])]

        return results