
    /jg                    J    d dl mZ d dlmZ d dlmZmZ  G d de          ZdS )    )annotations)DetectionPredictor)DEFAULT_CFGopsc                  6     e Zd ZdZeddfd fdZ fdZ xZS )PosePredictoraA  A class extending the DetectionPredictor class for prediction based on a pose model.

    This class specializes in pose estimation, handling keypoints detection alongside standard object detection
    capabilities inherited from DetectionPredictor.

    Attributes:
        args (namespace): Configuration arguments for the predictor.
        model (torch.nn.Module): The loaded YOLO pose model with keypoint detection capabilities.

    Methods:
        construct_result: Construct the result object from the prediction, including keypoints.

    Examples:
        >>> from ultralytics.utils import ASSETS
        >>> from ultralytics.models.yolo.pose import PosePredictor
        >>> args = dict(model="yolo26n-pose.pt", source=ASSETS)
        >>> predictor = PosePredictor(overrides=args)
        >>> predictor.predict_cli()
    N
_callbacksdict | Nonec                f    t                                          |||           d| j        _        dS )a  Initialize PosePredictor for pose estimation tasks.

        Sets up a PosePredictor instance, configuring it for pose detection tasks and handling device-specific warnings
        for Apple MPS.

        Args:
            cfg (Any): Configuration for the predictor.
            overrides (dict, optional): Configuration overrides that take precedence over cfg.
            _callbacks (dict, optional): Dictionary of callback functions to be invoked during prediction.
        poseN)super__init__argstask)selfcfg	overridesr	   	__class__s       i/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/models/yolo/pose/predict.pyr   zPosePredictor.__init__   s.     	i444	    c                *   t                                          ||||          } |ddddf         j        |j        d         g| j        j        R  }t          j        |j        dd         ||j                  }|                    |           |S )aY  Construct the result object from the prediction, including keypoints.

        Extends the parent class implementation by extracting keypoint data from predictions and adding them to the
        result object.

        Args:
            pred (torch.Tensor): The predicted bounding boxes, scores, and keypoints with shape (N, 6+K*D) where N is
                the number of detections, K is the number of keypoints, and D is the keypoint dimension.
            img (torch.Tensor): The processed input image tensor with shape (B, C, H, W).
            orig_img (np.ndarray): The original unprocessed image as a numpy array.
            img_path (str): The path to the original image file.

        Returns:
            (Results): The result object containing the original image, image path, class names, bounding boxes, and
                keypoints.
        N   r      )	keypoints)	r   construct_resultviewshapemodel	kpt_shaper   scale_coordsupdate)r   predimgorig_imgimg_pathresult	pred_kptsr   s          r   r   zPosePredictor.construct_result,   s    " ))$XxHH$DABBK$TZ]JTZ5IJJJ	$SYqrr]Ix~NN		***r   )r	   r
   )__name__
__module____qualname____doc__r   r   r   __classcell__)r   s   @r   r   r   	   so         ( '$RV                      r   r   N)
__future__r   &ultralytics.models.yolo.detect.predictr   ultralytics.utilsr   r   r    r   r   <module>r1      sx    # " " " " " E E E E E E . . . . . . . .: : : : :& : : : : :r   