Ë
    Fêñi	  ã                   óB   — d dl mZ d dlmZ d dlmZmZ  G d„ de«      Zy)é    )ÚBasePredictor)ÚResults)ÚnmsÚopsc                   ó2   — e Zd ZdZd„ Zed„ «       Zd„ Zd„ Zy)ÚDetectionPredictora5  A class extending the BasePredictor class for prediction based on a detection model.

    This predictor specializes in object detection tasks, processing model outputs into meaningful detection results
    with bounding boxes and class predictions.

    Attributes:
        args (namespace): Configuration arguments for the predictor.
        model (nn.Module): The detection model used for inference.
        batch (list): Batch of images and metadata for processing.

    Methods:
        postprocess: Process raw model predictions into detection results.
        construct_results: Build Results objects from processed predictions.
        construct_result: Create a single Result object from a prediction.
        get_obj_feats: Extract object features from the feature maps.

    Examples:
        >>> from ultralytics.utils import ASSETS
        >>> from ultralytics.models.yolo.detect import DetectionPredictor
        >>> args = dict(model="yolo26n.pt", source=ASSETS)
        >>> predictor = DetectionPredictor(overrides=args)
        >>> predictor.predict_cli()
    c                 óü  — t        | dd«      du}t        j                  || j                  j                  | j                  j
                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  dk(  rdnt        | j                  j                  «      t        | j                  dd«      | j                  j                  dk(  |¬«
      }t        |t        «      st        j                   |«      d	ddd
…f   }|r$| j#                  | j$                  |d   «      }|d   } | j&                  |||fi |¤Ž}|rt)        |«      D ]  \  }}	|	|_        Œ |S )ap  Post-process predictions and return a list of Results objects.

        This method applies non-maximum suppression to raw model predictions and prepares them for visualization and
        further analysis.

        Args:
            preds (torch.Tensor): Raw predictions from the model.
            img (torch.Tensor): Processed input image tensor in model input format.
            orig_imgs (torch.Tensor | list): Original input images before preprocessing.
            **kwargs (Any): Additional keyword arguments.

        Returns:
            (list): List of Results objects containing the post-processed predictions.

        Examples:
            >>> predictor = DetectionPredictor(overrides=dict(model="yolo26n.pt"))
            >>> results = predictor.predict("path/to/image.jpg")
            >>> processed_results = predictor.postprocess(preds, img, orig_imgs)
        Ú_featsNÚdetectr   Úend2endFÚobb)Úmax_detÚncr   ÚrotatedÚreturn_idxs.éÿÿÿÿé   )Úgetattrr   Únon_max_suppressionÚargsÚconfÚiouÚclassesÚagnostic_nmsr   ÚtaskÚlenÚmodelÚnamesÚ
isinstanceÚlistr   Úconvert_torch2numpy_batchÚget_obj_featsr
   Úconstruct_resultsÚzipÚfeats)
ÚselfÚpredsÚimgÚ	orig_imgsÚkwargsÚ
save_featsÚ	obj_featsÚresultsÚrÚfs
             úh/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/models/yolo/detect/predict.pyÚpostprocesszDetectionPredictor.postprocess!   sB  € ô( ˜T 8¨TÓ2¸$Ð>ˆ
Ü×'Ñ'ØØ�I‰I�N‰NØ�I‰I�M‰MØ�I‰I×ÑØ�I‰I×"Ñ"Ø—I‘I×%Ñ%Ø—I‘I—N‘N hÒ.‰q´C¸¿
¹
×8HÑ8HÓ4IÜ˜DŸJ™J¨	°5Ó9Ø—I‘I—N‘N eÑ+Ø"ô
ˆô ˜)¤TÔ*Ü×5Ñ5°iÓ@ÀÁdÈÀdÀÑKˆIáØ×*Ñ*¨4¯;©;¸¸a¹ÓAˆIØ˜!‘HˆEà(�$×(Ñ(¨°°YÑIÀ&ÑIˆáÜ˜G YÓ/ò ‘��1Ø�•ðð ˆó    c                 óŽ  — ddl }t        d„ | D «       «      }|j                  | D �cg c]U  }|j                  dddd«      j	                  |j
                  d   d||j
                  d   |z  «      j                  d¬«      ‘ŒW c}d¬«      }t        ||«      D ��cg c]  \  }}|j
                  d   r||   ng ‘Œ c}}S c c}w c c}}w )	z.Extract object features from the feature maps.r   Nc              3   ó:   K  — | ]  }|j                   d    –— Œ y­w)r   N)Úshape)Ú.0Úxs     r0   ú	<genexpr>z3DetectionPredictor.get_obj_feats.<locals>.<genexpr>W   s   è ø€ Ò.˜q�—‘˜•
Ñ.ùs   ‚é   é   r   r   )Údim)ÚtorchÚminÚcatÚpermuteÚreshaper5   Úmeanr$   )Ú	feat_mapsÚidxsr<   Úsr7   r,   r%   Úidxs           r0   r"   z DetectionPredictor.get_obj_featsR   s¼   € ó 	äÑ. IÔ.Ó.ˆØ—I‘IØenÖoÐ`aˆQ�Y‰Y�q˜!˜Q Ó"×*Ñ*¨1¯7©7°1©:°r¸1¸a¿g¹gÀa¹jÈA¹oÓN×SÑSÐXZÐSÕ[ÒoÐuvð ó 
ˆ	ô FIÈÐTXÓEY×Z±z°u¸c˜cŸi™i¨šl��c’
°Ñ2ÓZÐZùò pùãZs   ¦AB<Â Cc                 ó”   — t        ||| j                  d   «      D ���cg c]  \  }}}| j                  ||||«      ‘Œ c}}}S c c}}}w )aØ  Construct a list of Results objects from model predictions.

        Args:
            preds (list[torch.Tensor]): List of predicted bounding boxes and scores for each image.
            img (torch.Tensor): Batch of preprocessed images used for inference.
            orig_imgs (list[np.ndarray]): List of original images before preprocessing.

        Returns:
            (list[Results]): List of Results objects containing detection information for each image.
        r   )r$   ÚbatchÚconstruct_result)r&   r'   r(   r)   ÚpredÚorig_imgÚimg_paths          r0   r#   z$DetectionPredictor.construct_results]   sQ   € ô -0°°yÀ$Ç*Á*ÈQÁ-Ó,P÷
ð 
á(��h ð ×!Ñ! $¨¨X°xÕ@ô
ð 	
ùô 
s   ŸAc           	      óÚ   — t        j                  |j                  dd |dd…dd…f   |j                  «      |dd…dd…f<   t        ||| j                  j
                  |dd…dd…f   ¬«      S )a%  Construct a single Results object from one image prediction.

        Args:
            pred (torch.Tensor): Predicted boxes and scores with shape (N, 6) where N is the number of detections.
            img (torch.Tensor): Preprocessed image tensor used for inference.
            orig_img (np.ndarray): Original image before preprocessing.
            img_path (str): Path to the original image file.

        Returns:
            (Results): Results object containing the original image, image path, class names, and scaled bounding boxes.
        r9   Né   é   )Úpathr   Úboxes)r   Úscale_boxesr5   r   r   r   )r&   rI   r(   rJ   rK   s        r0   rH   z#DetectionPredictor.construct_resultm   sh   € ô —o‘o c§i¡i°° m°Tº!¸R¸a¸R¸%±[À(Ç.Á.ÓQˆŠQ���ˆU‰Ü�x h°d·j±j×6FÑ6FÈdÒSTÐVXÐWXÐVXÐSXÉkÔZÐZr2   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r1   Ústaticmethodr"   r#   rH   © r2   r0   r   r      s.   „ ñò0/ðb ñ[ó ð[ò
ó [r2   r   N)Úultralytics.engine.predictorr   Úultralytics.engine.resultsr   Úultralytics.utilsr   r   r   rW   r2   r0   ú<module>r[      s    ðõ 7Ý .ß &ôr[˜õ r[r2   