§
    ezniy[  ã                   ó&  — d Z ddlmZ ddlmZ ddlmZ ddlZddl	Z	ddl
mZ ddlmZmZmZ ddlmZmZmZ dd	lmZ  G d
„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )z†
Ultralytics Results, Boxes and Masks classes for handling inference results.

Usage: See https://docs.ultralytics.com/modes/predict/
é    )Údeepcopy)Ú	lru_cache)ÚPathN)Ú	LetterBox)ÚLOGGERÚSimpleClassÚops)Ú	AnnotatorÚcolorsÚsave_one_box)Úsmart_inference_modec                   óT   — e Zd ZdZdd„Zed„ ¦   «         Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ ZdS )Ú
BaseTensorzTBase tensor class with additional methods for easy manipulation and device handling.ÚreturnNc                 ór   — t          |t          j        t          j        f¦  «        sJ ‚|| _        || _        dS )zí
        Initialize BaseTensor with data and original shape.

        Args:
            data (torch.Tensor | np.ndarray): Predictions, such as bboxes, masks and keypoints.
            orig_shape (tuple): Original shape of image.
        N)Ú
isinstanceÚtorchÚTensorÚnpÚndarrayÚdataÚ
orig_shape)Úselfr   r   s      úz/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/engine/results.pyÚ__init__zBaseTensor.__init__   s5   € õ ˜$¥¤­r¬zÐ :Ñ;Ô;Ð;Ð;Ð;ØˆŒ	Ø$ˆŒˆˆó    c                 ó   — | j         j        S )z$Return the shape of the data tensor.)r   Úshape©r   s    r   r   zBaseTensor.shape$   s   € ð ŒyŒÐr   c                 ó¨   — t          | j        t          j        ¦  «        r| n1|                      | j                             ¦   «         | j        ¦  «        S )z*Return a copy of the tensor on CPU memory.)r   r   r   r   Ú	__class__Úcpur   r   s    r   r"   zBaseTensor.cpu)   s;   € å! $¤)­R¬ZÑ8Ô8Ðnˆtˆt¸d¿nºnÈTÌYÏ]Ê]É_Ì_Ð^bÔ^mÑ>nÔ>nÐnr   c                 ó¨   — t          | j        t          j        ¦  «        r| n1|                      | j                             ¦   «         | j        ¦  «        S )z-Return a copy of the tensor as a numpy array.)r   r   r   r   r!   Únumpyr   r   s    r   r$   zBaseTensor.numpy-   s=   € å! $¤)­R¬ZÑ8Ô8Ðpˆtˆt¸d¿nºnÈTÌYÏ_Ê_ÑM^ÔM^Ð`dÔ`oÑ>pÔ>pÐpr   c                 óŠ   — |                       t          j        | j        ¦  «                             ¦   «         | j        ¦  «        S )z*Return a copy of the tensor on GPU memory.)r!   r   Ú	as_tensorr   Úcudar   r   s    r   r'   zBaseTensor.cuda1   s0   € à�~Š~�eœo¨d¬iÑ8Ô8×=Ò=Ñ?Ô?ÀÄÑQÔQÐQr   c                 ó|   — |                        t          j        | j        ¦  «        j        |i |¤Ž| j        ¦  «        S )z@Return a copy of the tensor with the specified device and dtype.)r!   r   r&   r   Útor   ©r   ÚargsÚkwargss      r   r)   zBaseTensor.to5   s7   € à�~Š~Ð;�eœo¨d¬iÑ8Ô8Ô;¸TÐLÀVÐLÐLÈdÌoÑ^Ô^Ð^r   c                 ó*   — t          | j        ¦  «        S )z%Return the length of the data tensor.)Úlenr   r   s    r   Ú__len__zBaseTensor.__len__9   s   € å�4”9‰~Œ~Ðr   c                 óN   — |                       | j        |         | j        ¦  «        S )z@Return a BaseTensor with the specified index of the data tensor.)r!   r   r   ©r   Úidxs     r   Ú__getitem__zBaseTensor.__getitem__=   s   € à�~Š~˜dœi¨œn¨d¬oÑ>Ô>Ð>r   ©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r"   r$   r'   r)   r/   r3   © r   r   r   r      s¯   € € € € € Ø^Ð^ð
%ð 
%ð 
%ð 
%ð ðð ñ „Xððoð oð oðqð qð qðRð Rð Rð_ð _ð _ðð ð ð?ð ?ð ?ð ?ð ?r   r   c                   ó¨   — e Zd ZdZddd„Zd„ Zd„ Zdd„Zd„ Zd	„ Z	d
„ Z
d„ Zd„ Zd„ Z	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zd„ Zdd„Z ed¦  «        fd„Zdd„ZdS )ÚResultsaÚ  
    A class for storing and manipulating inference results.

    Args:
        orig_img (numpy.ndarray): The original image as a numpy array.
        path (str): The path to the image file.
        names (dict): A dictionary of class names.
        boxes (torch.tensor, optional): A 2D tensor of bounding box coordinates for each detection.
        masks (torch.tensor, optional): A 3D tensor of detection masks, where each mask is a binary image.
        probs (torch.tensor, optional): A 1D tensor of probabilities of each class for classification task.
        keypoints (List[List[float]], optional): A list of detected keypoints for each object.

    Attributes:
        orig_img (numpy.ndarray): The original image as a numpy array.
        orig_shape (tuple): The original image shape in (height, width) format.
        boxes (Boxes, optional): A Boxes object containing the detection bounding boxes.
        masks (Masks, optional): A Masks object containing the detection masks.
        probs (Probs, optional): A Probs object containing probabilities of each class for classification task.
        keypoints (Keypoints, optional): A Keypoints object containing detected keypoints for each object.
        speed (dict): A dictionary of preprocess, inference, and postprocess speeds in milliseconds per image.
        names (dict): A dictionary of class names.
        path (str): The path to the image file.
        _keys (tuple): A tuple of attribute names for non-empty attributes.
    Nr   c                 ón  — || _         |j        dd…         | _        |�t          || j        ¦  «        nd| _        |�t          || j        ¦  «        nd| _        |�t          |¦  «        nd| _        |�t          || j        ¦  «        nd| _
        ddddœ| _        || _        || _        d| _        d| _        dS )zInitialize the Results class.Né   )Ú
preprocessÚ	inferenceÚpostprocess)ÚboxesÚmasksÚprobsÚ	keypoints)Úorig_imgr   r   ÚBoxesrB   ÚMasksrC   ÚProbsrD   Ú	KeypointsrE   ÚspeedÚnamesÚpathÚsave_dirÚ_keys)r   rF   rM   rL   rB   rC   rD   rE   s           r   r   zResults.__init__\   sº   € à ˆŒØ"œ.¨¨!¨Ô,ˆŒØ6;Ð6G•U˜5 $¤/Ñ2Ô2Ð2ÈTˆŒ
Ø6;Ð6G•U˜5 $¤/Ñ2Ô2Ð2ÈTˆŒ
Ø%*Ð%6•U˜5‘\”\�\¸DˆŒ
ØBKÐBW� 9¨d¬oÑ>Ô>Ð>Ð]aˆŒØ$(°tÈDÐQÐQˆŒ
ØˆŒ
ØˆŒ	ØˆŒØ;ˆŒ
ˆ
ˆ
r   c                 ó.   — |                       d|¦  «        S )z0Return a Results object for the specified index.r3   ©Ú_applyr1   s     r   r3   zResults.__getitem__j   s   € à�{Š{˜=¨#Ñ.Ô.Ð.r   c                 ó`   — | j         D ]%}t          | |¦  «        }|�t          |¦  «        c S Œ&dS )z6Return the number of detections in the Results object.N)rO   Úgetattrr.   )r   ÚkÚvs      r   r/   zResults.__len__n   sE   € à”ð 	ð 	ˆAÝ˜˜aÑ Ô ˆAØˆ}Ý˜1‘v”v���ð ð	ð 	r   c                 ó¼   — |�2t          t          j        || j        ¦  «        | j        ¦  «        | _        |�t          || j        ¦  «        | _        |�	|| _        dS dS )zDUpdate the boxes, masks, and probs attributes of the Results object.N)rG   r	   Ú
clip_boxesr   rB   rH   rC   rD   )r   rB   rC   rD   s       r   ÚupdatezResults.updateu   s[   € àÐÝ�sœ~¨e°T´_ÑEÔEÀtÄÑWÔWˆDŒJØÐÝ˜u d¤oÑ6Ô6ˆDŒJØÐØˆDŒJˆJˆJð Ðr   c           
      ó°   — |                       ¦   «         }| j        D ]9}t          | |¦  «        }|�%t          || t          ||¦  «        |i |¤Ž¦  «         Œ:|S )a  
        Applies a function to all non-empty attributes and returns a new Results object with modified attributes. This
        function is internally called by methods like .to(), .cuda(), .cpu(), etc.

        Args:
            fn (str): The name of the function to apply.
            *args: Variable length argument list to pass to the function.
            **kwargs: Arbitrary keyword arguments to pass to the function.

        Returns:
            Results: A new Results object with attributes modified by the applied function.
        )ÚnewrO   rT   Úsetattr)r   Úfnr+   r,   ÚrrU   rV   s          r   rR   zResults._apply~   se   € ð �HŠH‰JŒJˆØ”ð 	?ð 	?ˆAÝ˜˜aÑ Ô ˆAØˆ}Ý˜˜1˜n�g a¨™nœn¨dÐ=°fÐ=Ð=Ñ>Ô>Ð>øØˆr   c                 ó,   — |                       d¦  «        S )zCReturn a copy of the Results object with all tensors on CPU memory.r"   rQ   r   s    r   r"   zResults.cpu’   s   € à�{Š{˜5Ñ!Ô!Ð!r   c                 ó,   — |                       d¦  «        S )zEReturn a copy of the Results object with all tensors as numpy arrays.r$   rQ   r   s    r   r$   zResults.numpy–   s   € à�{Š{˜7Ñ#Ô#Ð#r   c                 ó,   — |                       d¦  «        S )zCReturn a copy of the Results object with all tensors on GPU memory.r'   rQ   r   s    r   r'   zResults.cudaš   s   € à�{Š{˜6Ñ"Ô"Ð"r   c                 ó$   —  | j         dg|¢R i |¤ŽS )zSReturn a copy of the Results object with tensors on the specified device and dtype.r)   rQ   r*   s      r   r)   z
Results.tož   s$   € àˆtŒ{˜4Ð1 $Ð1Ð1Ð1¨&Ð1Ð1Ð1r   c                 óD   — t          | j        | j        | j        ¬¦  «        S )zAReturn a new Results object with the same image, path, and names.)rF   rM   rL   )r<   rF   rM   rL   r   s    r   r[   zResults.new¢   s   € å ¤°D´IÀTÄZÐPÑPÔPÐPr   Tú	Arial.ttfFé   c           	      óø  ‡‡— |€©t          | j        t          j        ¦  «        rŠ| j        d                              ¦   «                              ddd¦  «                             ¦   «         dz                       t          j        ¦  «         	                    ¦   «          
                    ¦   «         }| j        Š| j        |}}| j        |}}| j        |cŠ}t          t!          |€| j        n|¦  «        ||||p‰duo|‰¬¦  «        }|rð|rî|€  t#          |j        dd…         ¦  «        |                     ¦   «         ¬¦  «        }t          j        |t          j        |j        j        ¬¦  «                             ddd¦  «                             d¦  «                             ¦   «         dz  }|r|j        nt5          t7          |¦  «        ¦  «        }|                     |j        d	„ |D ¦   «         |¬
¦  «         |rÏ|rÍt9          |¦  «        D ]½}t;          |j        ¦  «        |rt=          |j        ¦  «        nd|j         €dn%t;          |j          !                    ¦   «         ¦  «        }}}|€dnd|› d�‰|         z   }|
r|r|› d|d›�n|nd}| "                    |j#         $                    ¦   «         |tK          |d¦  «        ¬¦  «         Œ¾‰�`|r^d &                    ˆˆfd„‰j'        D ¦   «         ¦  «        }tQ          | j)        d         dz  ¦  «        }| *                    ||g|d¬¦  «         | j+        �:t9          | j+        j        ¦  «        D ] }| ,                    || j)        ||	¬¦  «         Œ!|                     ¦   «         S )aÚ  
        Plots the detection results on an input RGB image. Accepts a numpy array (cv2) or a PIL Image.

        Args:
            conf (bool): Whether to plot the detection confidence score.
            line_width (float, optional): The line width of the bounding boxes. If None, it is scaled to the image size.
            font_size (float, optional): The font size of the text. If None, it is scaled to the image size.
            font (str): The font to use for the text.
            pil (bool): Whether to return the image as a PIL Image.
            img (numpy.ndarray): Plot to another image. if not, plot to original image.
            im_gpu (torch.Tensor): Normalized image in gpu with shape (1, 3, 640, 640), for faster mask plotting.
            kpt_radius (int, optional): Radius of the drawn keypoints. Default is 5.
            kpt_line (bool): Whether to draw lines connecting keypoints.
            labels (bool): Whether to plot the label of bounding boxes.
            boxes (bool): Whether to plot the bounding boxes.
            masks (bool): Whether to plot the masks.
            probs (bool): Whether to plot classification probability

        Returns:
            (numpy.ndarray): A numpy array of the annotated image.

        Example:
            ```python
            from PIL import Image
            from ultralytics import YOLO

            model = YOLO('yolov8n.pt')
            results = model('bus.jpg')  # results list
            for r in results:
                im_array = r.plot()  # plot a BGR numpy array of predictions
                im = Image.fromarray(im_array[..., ::-1])  # RGB PIL image
                im.show()  # show image
                im.save('results.jpg')  # save image
            ```
        Nr   é   r>   éÿ   )Úexample)Úimage)ÚdtypeÚdevicec                 ó.   — g | ]}t          |d ¦  «        ‘ŒS )T)r   )Ú.0Úxs     r   ú
<listcomp>z Results.plot.<locals>.<listcomp>ï   s    € Ð4RÐ4RÐ4RÈµV¸A¸t±_´_Ð4RÐ4RÐ4Rr   )r   Úim_gpuÚ zid:ú ú.2fT)Úcolorz,
c              3   óR   •K  — | ]!}‰r‰|         n|› d ‰j         |         d›�V — Œ"dS ©rs   rt   N©r   )rn   ÚjrL   Ú
pred_probss     €€r   ú	<genexpr>zResults.plot.<locals>.<genexpr>û   sI   øè è € ÐnÐnÐYZ¨UÐ!9  q¤ ¸ÐTÐT¸J¼OÈAÔ<NÐTÐTÐTÐnÐnÐnÐnÐnÐnr   g¸…ëQ¸ž?)rh   rh   rh   )Ú	txt_color)ÚradiusÚkpt_line)-r   rF   r   r   ÚdetachÚpermuteÚ
contiguousr)   Úuint8r"   r$   rL   rB   rC   rD   r
   r   r   r   Úresultr&   Úfloat16r   rl   ÚflipÚclsÚranger.   ÚreversedÚintÚfloatÚconfÚidÚitemÚ	box_labelÚxyxyÚsqueezer   ÚjoinÚtop5Úroundr   ÚtextrE   Úkpts)r   r‹   Ú
line_widthÚ	font_sizeÚfontÚpilÚimgrq   Ú
kpt_radiusr~   ÚlabelsrB   rC   rD   Ú
pred_boxesÚ
show_boxesÚ
pred_masksÚ
show_masksÚ
show_probsÚ	annotatorr2   ÚdÚcrŒ   ÚnameÚlabelr”   ro   rU   rL   rz   s                                @@r   ÚplotzResults.plot¦   s�  øø€ ðf ˆ;�: d¤mµU´\ÑBÔBˆ;Ø”= Ô#×*Ò*Ñ,Ô,×4Ò4°Q¸¸1Ñ=Ô=×HÒHÑJÔJÈSÑP×TÒTÕUZÔU`ÑaÔa×eÒeÑgÔg×mÒmÑoÔoˆCà”
ˆØ!%¤¨U�Jˆ
Ø!%¤¨U�Jˆ
Ø!%¤¨UÐˆ
�JÝÝ c k�T”]�]°sÑ;Ô;ØØØØÐ:�J dÐ*Ð9¨zØðñ ô ˆ	ð ð 	c˜*ð 	cØˆ~Ø5•i 
Ô 0°°°Ô 4Ñ5Ô5¸I×<LÒ<LÑ<NÔ<NÐOÑOÔO�Ýœ¨µE´MÈ*Ì/ÔJ`ÐaÑaÔa×iÒiØ�q˜!ñô ß!šT !™WœW§Z¢Z¡\¤\°Cñ8�à$.ÐJ�*”.�.µE½#¸j¹/¼/Ñ4JÔ4JˆCØ�OŠO˜JœOÐ4RÐ4RÈcÐ4RÑ4RÔ4RÐ[aˆOÑbÔbÐbð ð 	T˜*ð 	TÝ˜jÑ)Ô)ð Tð T�Ý! !¤%™jœj¸4Ð*I­%°´©-¬-¨-ÀTÐSTÔSWÐS_È4È4ÕehÐijÔim×irÒirÑitÔitÑeuÔeu˜�4�Ø ˜j˜˜¨k°B¨k¨k¨k¸UÀ1¼XÑE�ØDJÐT°Ð?˜DÐ-Ð- 4Ð-Ð-Ð-Ð-¸4¸4ÐPT�Ø×#Ò# A¤F§N¢NÑ$4Ô$4°eÅ6È!ÈTÁ?Ä?Ð#ÑSÔSÐSÐSð Ð! jÐ!Ø—:’:ÐnÐnÐnÐnÐnÐ^hÔ^mÐnÑnÔnÑnÔnˆDÝ�d”o aÔ(¨4Ñ/Ñ0Ô0ˆAØ�NŠN˜A˜q˜6 4°?ˆNÑCÔCÐCð Œ>Ð%Ý˜dœnÔ1Ñ2Ô2ð Yð Y�Ø—’˜q $¤/¸*Èx�ÑXÔXÐXÐXà×ÒÑ!Ô!Ð!r   c                 óŽ  ‡ ‡— d}‰ j         Š‰ j        }t          ‰ ¦  «        dk    r	‰�|n|› d�S ‰�-|d                     ˆˆ fd„‰j        D ¦   «         ¦  «        › d�z  }|re|j                             ¦   «         D ]K}|j        |k                         ¦   «         }||› d‰ j        t          |¦  «                 › d|d	k    z  › d�z  }ŒL|S )
z Return log string for each task.rr   r   Nz(no detections), z, c              3   óT   •K  — | ]"}‰j         |         › d ‰j        |         d›�V — Œ#dS rw   )rL   r   )rn   ry   rD   r   s     €€r   r{   z"Results.verbose.<locals>.<genexpr>  sA   øè è € Ð&bÐ&bÐRS¨$¬*°Q¬-Ð'MÐ'M¸%¼*ÀQ¼-Ð'MÐ'MÐ'MÐ&bÐ&bÐ&bÐ&bÐ&bÐ&br   rs   Úsrg   )
rD   rB   r.   r‘   r’   r†   ÚuniqueÚsumrL   r‰   )r   Ú
log_stringrB   r¤   ÚnrD   s   `    @r   ÚverbosezResults.verbose  sû   øø€ àˆ
Ø”
ˆØ”
ˆÝˆt‰9Œ9˜Š>ˆ>Ø!&Ð!2�:�:¸:Ð8XÐ8XÐ8XÐXØÐØ˜TŸYšYÐ&bÐ&bÐ&bÐ&bÐ&bÐW\ÔWaÐ&bÑ&bÔ&bÑbÔbÐfÐfÐfÑfˆJØð 	KØ”Y×%Ò%Ñ'Ô'ð Kð K�Ø”Y !’^×(Ò(Ñ*Ô*�Ø ÐJÐJ T¤Zµ°A±´Ô%7ÐJ¸ÀÀAÂ¹ÐJÐJÐJÑJ�
�
ØÐr   c                 ó�  ‡ ‡‡— ‰ j         }‰ j        }‰ j        Š‰ j        }g Š‰�ˆˆ ˆfd„‰j        D ¦   «          �n–|�r“t          |¦  «        D �]‚\  }}t          |j        ¦  «        t          |j	        ¦  «        |j
        €dn%t          |j
                             ¦   «         ¦  «        }
}	}|g|j                             d¦  «        ¢R }|r>||         j        d                              ¦   «                              d¦  «        }|g|¢R }|�z||         j        r3t%          j        ||         j        ||         j	        d         fd¦  «        n||         j        }|g |                     d¦  «                             ¦   «         ¢R z  }||	f|z  |
€dn|
fz   z  }‰                     dt-          |¦  «        z                       ¦   «         |z  ¦  «         �Œ„‰rst1          |¦  «        j                             d	d	¬
¦  «         t7          |d¦  «        5 }|                     d„ ‰D ¦   «         ¦  «         ddd¦  «         dS # 1 swxY w Y   dS dS )z§
        Save predictions into txt file.

        Args:
            txt_file (str): txt file path.
            save_conf (bool): save confidence score or not.
        Nc                 ór   •— g | ]3}‰                      ‰j        |         d ›d‰j        |         › �¦  «        ‘Œ4S )rt   rs   )Úappendr   rL   )rn   ry   rD   r   Útextss     €€€r   rp   z$Results.save_txt.<locals>.<listcomp>$  sB   ø€ ÐVÐVÐVÀaˆU�\Š\˜UœZ¨œ]Ð@Ð@Ð@°´¸A´Ð@Ð@ÑAÔAÐVÐVÐVr   éÿÿÿÿr   ).Nr>   r:   z%g T)ÚparentsÚexist_okÚac              3   ó    K  — | ]	}|d z   V — Œ
dS )ú
Nr:   )rn   r”   s     r   r{   z#Results.save_txt.<locals>.<genexpr>6  s&   è è € Ð;Ð;¨T˜T D™[Ð;Ð;Ð;Ð;Ð;Ð;r   )rB   rC   rD   rE   r’   Ú	enumerater‰   r†   rŠ   r‹   rŒ   r�   ÚxywhnÚviewÚxynÚcopyÚreshapeÚhas_visibler   ÚcatÚtolistr²   r.   Úrstripr   ÚparentÚmkdirÚopenÚ
writelines)r   Útxt_fileÚ	save_confrB   rC   r•   ry   r£   r¤   r‹   rŒ   ÚlineÚsegÚkptÚfrD   r³   s   `              @@r   Úsave_txtzResults.save_txt  sŸ  øøø€ ð ”
ˆØ”
ˆØ”
ˆØŒ~ˆØˆØÐàVÐVÐVÐVÐVÐVÈ5Ì:ÐVÑVÔVÐVÑVØñ 	Bå! %Ñ(Ô(ð 
Bñ 
B‘��1Ý! !¤%™jœj­%°´©-¬-ÀÄÀ¸¸ÕSVÐWXÔW[×W`ÒW`ÑWbÔWbÑScÔSc˜�4�ØÐ-˜AœGŸLšL¨Ñ,Ô,Ð-Ð-�Øð %Ø œ(œ, qœ/×.Ò.Ñ0Ô0×8Ò8¸Ñ<Ô<�CØ˜9 ˜9˜9�DØÐ#ØRVÐWXÔRYÔReÐv�%œ) T¨!¤W¤[°$°q´'´,¸yÔ2IÐ$JÈAÑNÔNÐNÐkoÐpqÔkrÔkv�CØÐ9˜cŸkšk¨"™oœo×4Ò4Ñ6Ô6Ð9Ð9Ñ9�DØ˜˜ 9Ñ,°b°j°°ÀrÀfÑMÑM�Ø—’˜e¥c¨$¡i¤iÑ/×7Ò7Ñ9Ô9¸DÑ@ÑAÔAÐAÑAàð 	<Ý�‰NŒNÔ!×'Ò'°¸tÐ'ÑDÔDÐDÝ�h Ñ$Ô$ð <¨Ø—’Ð;Ð;°UÐ;Ñ;Ô;Ñ;Ô;Ð;ð<ð <ð <ñ <ô <ð <ð <ð <ð <ð <ð <ð <øøøð <ð <ð <ð <ð <ð <ð	<ð 	<s   È H9È9H=É H=zim.jpgc           
      ó2  — | j         �t          j        d¦  «         dS | j        D ]q}t	          |j        | j                             ¦   «         t          |¦  «        | j	        t          |j        ¦  «                 z  t          |¦  «        › d�z  d¬¦  «         ŒrdS )zÇ
        Save cropped predictions to `save_dir/cls/file_name.jpg`.

        Args:
            save_dir (str | pathlib.Path): Save path.
            file_name (str | pathlib.Path): File name.
        Nu8   WARNING âš ï¸� Classify task do not support `save_crop`.z.jpgT)ÚfileÚBGR)rD   r   ÚwarningrB   r   r�   rF   r¾   r   rL   r‰   r†   )r   rN   Ú	file_namer£   s       r   Ú	save_cropzResults.save_crop8  s£   € ð Œ:Ð!ÝŒNÐUÑVÔVÐVØˆFØ”ð 	#ð 	#ˆAÝ˜œØœ×+Ò+Ñ-Ô-Ý" 8™nœn¨t¬z½#¸a¼e¹*¼*Ô/EÑEÍ4ÐPYÉ?Ì?ÐH`ÐH`ÐH`Ñ`Ø!ð#ñ #ô #ð #ð #ð	#ð 	#r   c                 óH  — | j         �t          j        d¦  «         dS ddl}g }| j        j                             ¦   «                              ¦   «         }|r| j        nd\  }}t          |¦  «        D �]š\  }}|d         |z  |d         |z  |d         |z  |d         |z  dœ}	|d	         }
t          |d
         ¦  «        }| j        |         }|||
|	dœ}| j        j        rt          |d         ¦  «        |d<   | j        rj| j        j        |         dd…df         | j        j        |         dd…df         }}||z                       ¦   «         ||z                       ¦   «         dœ|d<   | j        �‡| j        |         j        d                              ¦   «                              d¬¦  «        \  }}}||z                       ¦   «         ||z                       ¦   «         |                     ¦   «         dœ|d<   |                     |¦  «         �Œœ|                     |d¬¦  «        S )z"Convert the object to JSON format.Nz3Warning: Classify task do not support `tojson` yet.r   )rg   rg   rg   r>   é   )Úx1Úy1Úx2Úy2éþÿÿÿr´   )r¥   ÚclassÚ
confidenceÚboxéýÿÿÿÚtrack_id)ro   ÚyÚsegments)Údim)ro   rá   ÚvisiblerE   )Úindent)rD   r   rÒ   ÚjsonrB   r   r"   rÂ   r   rº   r‰   rL   Úis_trackrC   ÚxyrE   Úunbindr²   Údumps)r   Ú	normalizeræ   Úresultsr   ÚhÚwÚiÚrowrÞ   r‹   Úclass_idr¥   rƒ   ro   rá   rä   s                    r   ÚtojsonzResults.tojsonI  s  € àŒ:Ð!ÝŒNÐPÑQÔQÐQØˆFàˆˆˆð ˆØŒzŒ×"Ò"Ñ$Ô$×+Ò+Ñ-Ô-ˆØ"+Ð7ˆtŒˆ°‰ˆˆ1Ý ‘o”oð 	#ñ 	#‰FˆAˆsØ˜Qœ !™¨3¨q¬6°A©:¸SÀ¼VÀa¹ZÈsÐSTÌvÐXYÉzÐZÐZˆCØ�r”7ˆDÝ˜3˜rœ7‘|”|ˆHØ”:˜hÔ'ˆDØ"¨XÀTÐRUÐVÐVˆFØŒzÔ"ð 2Ý%(¨¨R¬¡\¤\��zÑ"ØŒzð TØ”z”} QÔ'¨¨¨¨1¨Ô-¨t¬z¬}¸QÔ/?ÀÀÀÀ1ÀÔ/E�1�Ø,-°©E¯>ª>Ñ+;Ô+;À1ÀqÁ5Ç.Â.ÑBRÔBRÐ%SÐ%S��zÑ"ØŒ~Ð)Ø $¤¨qÔ 1Ô 6°qÔ 9× =Ò =Ñ ?Ô ?× FÒ FÈ1Ð FÑ MÔ M‘��1�gØ-.°©U¯NªNÑ,<Ô,<ÀAÈÁEÇ>Â>ÑCSÔCSÐ`g×`nÒ`nÑ`pÔ`pÐ&qÐ&q��{Ñ#Ø�NŠN˜6Ñ"Ô"Ð"Ñ"ð �zŠz˜'¨!ˆzÑ,Ô,Ð,r   )NNNNr4   )NNN)TNNrd   FNNre   TTTTT)F)r5   r6   r7   r8   r   r3   r/   rY   rR   r"   r$   r'   r)   r[   r§   r¯   rÎ   r   rÔ   rò   r:   r   r   r<   r<   B   sa  € € € € € ðð ð2<ð <ð <ð <ð <ð/ð /ð /ðð ð ðð ð ð ðð ð ð("ð "ð "ð$ð $ð $ð#ð #ð #ð2ð 2ð 2ðQð Qð Qð ØØØØØØØØØØØØð^"ð ^"ð ^"ð ^"ð@ð ð ð!<ð !<ð !<ð !<ðF -1¨D°©N¬Nð #ð #ð #ð #ð"-ð -ð -ð -ð -ð -r   r<   c                   ó*  ‡ — e Zd ZdZdˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	e e
d	¬
¦  «        d„ ¦   «         ¦   «         Ze e
d	¬
¦  «        d„ ¦   «         ¦   «         Ze e
d	¬
¦  «        d„ ¦   «         ¦   «         Zˆ xZS )rG   aJ  
    A class for storing and manipulating detection boxes.

    Args:
        boxes (torch.Tensor | numpy.ndarray): A tensor or numpy array containing the detection boxes,
            with shape (num_boxes, 6) or (num_boxes, 7). The last two columns contain confidence and class values.
            If present, the third last column contains track IDs.
        orig_shape (tuple): Original image size, in the format (height, width).

    Attributes:
        xyxy (torch.Tensor | numpy.ndarray): The boxes in xyxy format.
        conf (torch.Tensor | numpy.ndarray): The confidence values of the boxes.
        cls (torch.Tensor | numpy.ndarray): The class values of the boxes.
        id (torch.Tensor | numpy.ndarray): The track IDs of the boxes (if available).
        xywh (torch.Tensor | numpy.ndarray): The boxes in xywh format.
        xyxyn (torch.Tensor | numpy.ndarray): The boxes in xyxy format normalized by original image size.
        xywhn (torch.Tensor | numpy.ndarray): The boxes in xywh format normalized by original image size.
        data (torch.Tensor): The raw bboxes tensor (alias for `boxes`).

    Methods:
        cpu(): Move the object to CPU memory.
        numpy(): Convert the object to a numpy array.
        cuda(): Move the object to CUDA memory.
        to(*args, **kwargs): Move the object to the specified device.
    r   Nc                 óÚ   •— |j         dk    r|ddd…f         }|j        d         }|dv sJ d|› �¦   «         ‚t          ¦   «                              ||¦  «         |dk    | _        || _        dS )zInitialize the Boxes class.rg   Nr´   )é   é   z expected `n` in [6, 7], but got rö   )Úndimr   Úsuperr   rç   r   )r   rB   r   r®   r!   s       €r   r   zBoxes.__init__„  sv   ø€ àŒ:˜Š?ˆ?Ø˜$   ˜'”NˆEØŒK˜ŒOˆØ�Fˆ{ˆ{ˆ{ÐB¸qÐBÐB‰{Œ{ˆ{Ý‰Œ×Ò˜ 
Ñ+Ô+Ð+Ø˜QšˆŒØ$ˆŒˆˆr   c                 ó(   — | j         dd…dd…f         S )z Return the boxes in xyxy format.Né   rx   r   s    r   r�   z
Boxes.xyxyŽ  s   € ð Œy˜˜˜˜B˜Q˜B˜ÔÐr   c                 ó$   — | j         dd…df         S )z*Return the confidence values of the boxes.NrÛ   rx   r   s    r   r‹   z
Boxes.conf“  ó   € ð Œy˜˜˜˜B˜ÔÐr   c                 ó$   — | j         dd…df         S )z%Return the class values of the boxes.Nr´   rx   r   s    r   r†   z	Boxes.cls˜  rü   r   c                 ó6   — | j         r| j        dd…df         ndS )z1Return the track IDs of the boxes (if available).Nrß   )rç   r   r   s    r   rŒ   zBoxes.id�  s%   € ð $(¤=Ð:ˆtŒy˜˜˜˜B˜ÔÐ°dÐ:r   r>   ©Úmaxsizec                 ó4   — t          j        | j        ¦  «        S )z Return the boxes in xywh format.)r	   Ú	xyxy2xywhr�   r   s    r   Úxywhz
Boxes.xywh¢  s   € õ Œ}˜TœYÑ'Ô'Ð'r   c                 ó$  — t          | j        t          j        ¦  «        r| j                             ¦   «         nt          j        | j        ¦  «        }|dddgfxx         | j        d         z  cc<   |dddgfxx         | j        d         z  cc<   |S )zBReturn the boxes in xyxy format normalized by original image size..r   r>   rg   rÖ   )r   r�   r   r   Úcloner   r¾   r   )r   r�   s     r   ÚxyxynzBoxes.xyxyn¨  s–   € õ %/¨t¬y½%¼,Ñ$GÔ$GÐ_ˆtŒy�ŠÑ Ô Ð ÍRÌWÐUYÔU^ÑM_ÔM_ˆØˆS�1�a�&ˆ[ÐÐÔ˜Tœ_¨QÔ/Ñ/ÐÐÑØˆS�1�a�&ˆ[ÐÐÔ˜Tœ_¨QÔ/Ñ/ÐÐÑØˆr   c                 ó´   — t          j        | j        ¦  «        }|dddgfxx         | j        d         z  cc<   |dddgfxx         | j        d         z  cc<   |S )zBReturn the boxes in xywh format normalized by original image size..r   r>   rg   rÖ   )r	   r  r�   r   )r   r  s     r   r»   zBoxes.xywhn±  sp   € õ Œ}˜TœYÑ'Ô'ˆØˆS�1�a�&ˆ[ÐÐÔ˜Tœ_¨QÔ/Ñ/ÐÐÑØˆS�1�a�&ˆ[ÐÐÔ˜Tœ_¨QÔ/Ñ/ÐÐÑØˆr   r4   )r5   r6   r7   r8   r   r9   r�   r‹   r†   rŒ   r   r  r  r»   Ú__classcell__©r!   s   @r   rG   rG   i  sL  ø€ € € € € ðð ð4%ð %ð %ð %ð %ð %ð ð ð  ñ „Xð ð ð ð  ñ „Xð ð ð ð  ñ „Xð ð ð;ð ;ñ „Xð;ð Ø€Y�qÐÑÔð(ð (ñ Ôñ „Xð(ð Ø€Y�qÐÑÔðð ñ Ôñ „Xðð Ø€Y�qÐÑÔðð ñ Ôñ „Xðð ð ð ð r   rG   c                   ó˜   ‡ — e Zd ZdZd	ˆ fd„Ze ed¬¦  «        d„ ¦   «         ¦   «         Ze ed¬¦  «        d„ ¦   «         ¦   «         Zˆ xZ	S )
rH   aÑ  
    A class for storing and manipulating detection masks.

    Attributes:
        xy (list): A list of segments in pixel coordinates.
        xyn (list): A list of normalized segments.

    Methods:
        cpu(): Returns the masks tensor on CPU memory.
        numpy(): Returns the masks tensor as a numpy array.
        cuda(): Returns the masks tensor on GPU memory.
        to(device, dtype): Returns the masks tensor with the specified device and dtype.
    r   Nc                 óz   •— |j         dk    r|ddd…f         }t          ¦   «                              ||¦  «         dS )zPInitialize the Masks class with the given masks tensor and original image shape.r>   N)r÷   rø   r   )r   rC   r   r!   s      €r   r   zMasks.__init__Ê  s?   ø€ àŒ:˜Š?ˆ?Ø˜$   ˜'”NˆEÝ‰Œ×Ò˜ 
Ñ+Ô+Ð+Ð+Ð+r   rg   rÿ   c                 óN   ‡ — ˆ fd„t          j        ‰ j        ¦  «        D ¦   «         S )zReturn normalized segments.c                 ón   •— g | ]1}t          j        ‰j        j        d d…         |‰j        d¬¦  «        ‘Œ2S )rg   NT©rë   ©r	   Úscale_coordsr   r   r   ©rn   ro   r   s     €r   rp   zMasks.xyn.<locals>.<listcomp>Ô  sM   ø€ ð 4ð 4ð 4àõ Ô˜TœYœ_¨Q¨R¨RÔ0°!°T´_ÐPTÐUÑUÔUð4ð 4ð 4r   ©r	   Úmasks2segmentsr   r   s   `r   r½   z	Masks.xynÐ  ó;   ø€ ð4ð 4ð 4ð 4åÔ'¨¬	Ñ2Ô2ð4ñ 4ô 4ð 	4r   c                 óN   ‡ — ˆ fd„t          j        ‰ j        ¦  «        D ¦   «         S )z%Return segments in pixel coordinates.c                 ón   •— g | ]1}t          j        ‰j        j        d d…         |‰j        d¬¦  «        ‘Œ2S )rg   NFr  r  r  s     €r   rp   zMasks.xy.<locals>.<listcomp>Ü  sM   ø€ ð 4ð 4ð 4àõ Ô˜TœYœ_¨Q¨R¨RÔ0°!°T´_ÐPUÐVÑVÔVð4ð 4ð 4r   r  r   s   `r   rè   zMasks.xyØ  r  r   r4   )
r5   r6   r7   r8   r   r9   r   r½   rè   r  r	  s   @r   rH   rH   »  s­   ø€ € € € € ðð ð,ð ,ð ,ð ,ð ,ð ,ð Ø€Y�qÐÑÔð4ð 4ñ Ôñ „Xð4ð Ø€Y�qÐÑÔð4ð 4ñ Ôñ „Xð4ð 4ð 4ð 4ð 4r   rH   c                   óò   ‡ — e Zd ZdZ e¦   «         d
ˆ fd„¦   «         Ze ed¬¦  «        d„ ¦   «         ¦   «         Ze ed¬¦  «        d„ ¦   «         ¦   «         Z	e ed¬¦  «        d	„ ¦   «         ¦   «         Z
ˆ xZS )rJ   aÇ  
    A class for storing and manipulating detection keypoints.

    Attributes:
        xy (torch.Tensor): A collection of keypoints containing x, y coordinates for each detection.
        xyn (torch.Tensor): A normalized version of xy with coordinates in the range [0, 1].
        conf (torch.Tensor): Confidence values associated with keypoints if available, otherwise None.

    Methods:
        cpu(): Returns a copy of the keypoints tensor on CPU memory.
        numpy(): Returns a copy of the keypoints tensor as a numpy array.
        cuda(): Returns a copy of the keypoints tensor on GPU memory.
        to(device, dtype): Returns a copy of the keypoints tensor with the specified device and dtype.
    r   Nc                 ó  •— |j         dk    r|ddd…f         }|j        d         dk    r|d         dk     }d|ddd…f         |<   t          ¦   «                              ||¦  «         | j        j        d         dk    | _        dS )	zRInitializes the Keypoints object with detection keypoints and original image size.r>   NrÖ   ©.r>   g      à?r   .r´   )r÷   r   rø   r   r   rÀ   )r   rE   r   Úmaskr!   s       €r   r   zKeypoints.__init__ñ  s’   ø€ ð Œ>˜QÒÐØ! $¨¨¨ 'Ô*ˆIØŒ?˜1Ô Ò"Ð"Ø˜VÔ$ sÒ*ˆDØ'(ˆI�c˜2˜A˜2�gÔ˜tÑ$Ý‰Œ×Ò˜ JÑ/Ô/Ð/Øœ9œ?¨2Ô.°!Ò3ˆÔÐÐr   rg   rÿ   c                 ó$   — | j         ddd…f         S )z&Returns x, y coordinates of keypoints..Nr>   rx   r   s    r   rè   zKeypoints.xyü  s   € ð Œy˜˜b˜q˜b˜Ô!Ð!r   c                 ó  — t          | j        t          j        ¦  «        r| j                             ¦   «         nt          j        | j        ¦  «        }|dxx         | j        d         z  cc<   |dxx         | j        d         z  cc<   |S )z1Returns normalized x, y coordinates of keypoints.).r   rg   ).rg   r   )r   rè   r   r   r  r   r¾   r   )r   rè   s     r   r½   zKeypoints.xyn  su   € õ !+¨4¬7µE´LÑ AÔ AÐWˆTŒW�]Š]‰_Œ_ˆ_ÅrÄwÈtÌwÑGWÔGWˆØ
ˆ6ˆ
ˆ
Œ
�d”o aÔ(Ñ(ˆ
ˆ
‰
Ø
ˆ6ˆ
ˆ
Œ
�d”o aÔ(Ñ(ˆ
ˆ
‰
Øˆ	r   c                 ó.   — | j         r| j        d         ndS )z?Returns confidence values of keypoints if available, else None.r  N)rÀ   r   r   s    r   r‹   zKeypoints.conf  s   € ð %)Ô$4Ð>ˆtŒy˜Ô Ð ¸$Ð>r   r4   )r5   r6   r7   r8   r   r   r9   r   rè   r½   r‹   r  r	  s   @r   rJ   rJ   á  sö   ø€ € € € € ðð ð ÐÑÔð4ð 4ð 4ð 4ð 4ñ Ôð4ð Ø€Y�qÐÑÔð"ð "ñ Ôñ „Xð"ð Ø€Y�qÐÑÔðð ñ Ôñ „Xðð Ø€Y�qÐÑÔð?ð ?ñ Ôñ „Xð?ð ?ð ?ð ?ð ?r   rJ   c                   ó  ‡ — e Zd ZdZddˆ fd„Ze ed¬¦  «        d„ ¦   «         ¦   «         Ze ed¬¦  «        d„ ¦   «         ¦   «         Ze ed¬¦  «        d	„ ¦   «         ¦   «         Z	e ed¬¦  «        d
„ ¦   «         ¦   «         Z
ˆ xZS )rI   aq  
    A class for storing and manipulating classification predictions.

    Attributes:
        top1 (int): Index of the top 1 class.
        top5 (list[int]): Indices of the top 5 classes.
        top1conf (torch.Tensor): Confidence of the top 1 class.
        top5conf (torch.Tensor): Confidences of the top 5 classes.

    Methods:
        cpu(): Returns a copy of the probs tensor on CPU memory.
        numpy(): Returns a copy of the probs tensor as a numpy array.
        cuda(): Returns a copy of the probs tensor on GPU memory.
        to(): Returns a copy of the probs tensor with the specified device and dtype.
    Nr   c                 óL   •— t          ¦   «                              ||¦  «         dS )zfInitialize the Probs class with classification probabilities and optional original shape of the image.N)rø   r   )r   rD   r   r!   s      €r   r   zProbs.__init__#  s#   ø€ å‰Œ×Ò˜ 
Ñ+Ô+Ð+Ð+Ð+r   rg   rÿ   c                 óN   — t          | j                             ¦   «         ¦  «        S )zReturn the index of top 1.)r‰   r   Úargmaxr   s    r   Útop1z
Probs.top1'  s    € õ �4”9×#Ò#Ñ%Ô%Ñ&Ô&Ð&r   c                 ól   — | j                               d¦  «        dd…                              ¦   «         S )zReturn the indices of top 5.r   Nre   )r   ÚargsortrÂ   r   s    r   r’   z
Probs.top5-  s1   € ð ”�
×#Ò# AÑ&Ô& r¨ rÔ*×1Ò1Ñ3Ô3Ð3r   c                 ó&   — | j         | j                 S )zReturn the confidence of top 1.)r   r"  r   s    r   Útop1confzProbs.top1conf3  ó   € ð Œy˜œÔ#Ð#r   c                 ó&   — | j         | j                 S )z Return the confidences of top 5.)r   r’   r   s    r   Útop5confzProbs.top5conf9  r'  r   )Nr4   )r5   r6   r7   r8   r   r9   r   r"  r’   r&  r)  r  r	  s   @r   rI   rI     s  ø€ € € € € ðð ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð Ø€Y�qÐÑÔð'ð 'ñ Ôñ „Xð'ð Ø€Y�qÐÑÔð4ð 4ñ Ôñ „Xð4ð Ø€Y�qÐÑÔð$ð $ñ Ôñ „Xð$ð Ø€Y�qÐÑÔð$ð $ñ Ôñ „Xð$ð $ð $ð $ð $r   rI   )r8   r¾   r   Ú	functoolsr   Úpathlibr   r$   r   r   Úultralytics.data.augmentr   Úultralytics.utilsr   r   r	   Úultralytics.utils.plottingr
   r   r   Úultralytics.utils.torch_utilsr   r   r<   rG   rH   rJ   rI   r:   r   r   ú<module>r0     s×  ððð ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø €€€à .Ð .Ð .Ð .Ð .Ð .Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ >Ð >Ð >Ð >Ð >Ð >ð*?ð *?ð *?ð *?ð *?�ñ *?ô *?ð *?ðZd-ð d-ð d-ð d-ð d-ˆkñ d-ô d-ð d-ðN	Oð Oð Oð Oð OˆJñ Oô Oð Oðd#4ð #4ð #4ð #4ð #4ˆJñ #4ô #4ð #4ðL.?ð .?ð .?ð .?ð .?�
ñ .?ô .?ð .?ðb+$ð +$ð +$ð +$ð +$ˆJñ +$ô +$ð +$ð +$ð +$r   