Ë
    ÜÓ^jG�  ã                   ó„  — d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	Z
d dlZd dlmc mZ d dlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z&  e&«       rd dl'Z' G d„ de!d¬«      Z(ddde)de*fd„Z+d1d„Z,d2d„Z-de.e*   de*de*fd„Z/	 	 	 	 d3de*de*de)de*dz  d e.e*   dz  d!e0e.e.e*      e.e*   f   fd"„Z1d#„ Z2d$e*d!ejf                  fd%„Z4	 d4d&„Z5	 d5de*d'ejf                  d(e0e*e*f   d!ejf                  fd)„Z6d*e7e8ef   d!ejf                  fd+„Z9d6d,„Z:d7d-„Z;d.„ Z<e% G d/„ d0e«      «       Z=d0gZ>y)8é    N)Údeepcopy)Úproduct)ÚAnyÚOptionalÚUnion)Úbatched_nmsé   )ÚTorchvisionBackend)Ú'SemanticSegmentationPostProcessorOutput)ÚBatchFeatureÚget_size_dict)ÚIMAGENET_STANDARD_MEANÚIMAGENET_STANDARD_STDÚChannelDimensionÚ
ImageInputÚPILImageResamplingÚSizeDict)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringÚis_vision_availablec                   ó&   — e Zd ZU dZeeef   ed<   y)ÚSam3ImageProcessorKwargszˆ
    mask_size (`dict[str, int]`, *optional*):
        The size `{"height": int, "width": int}` to resize the segmentation maps to.
    Ú	mask_sizeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdictÚstrÚintÚ__annotations__© ó    úy/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/sam3/image_processing_sam3.pyr   r   3   s   … ñð
 �C˜�H‰~Ôr%   r   F)ÚtotalÚmasksútorch.TensorÚmask_thresholdÚstability_score_offsetc                 ó(  — | ||z   kD  j                  dt        j                  ¬«      j                  dt        j                  ¬«      }| ||z
  kD  j                  dt        j                  ¬«      j                  dt        j                  ¬«      }||z  }|S )Néÿÿÿÿ©Údtype)ÚsumÚtorchÚint16Úint32)r(   r*   r+   ÚintersectionsÚunionsÚstability_scoress         r&   Ú_compute_stability_scorer7   <   s’   € ð 
�.Ð#9Ñ9Ñ	:×?Ñ?ÀÌ%Ï+É+Ð?ÓV×ZÑZÐ[]Ôej×epÑepÐZÓqð ð �~Ð(>Ñ>Ñ?×DÑDÀRÌuÏ{É{ÐDÓ[×_Ñ_Ð`bÔjo×juÑjuÐ_Óv€FØ$ vÑ-ÐØÐr%   c                 ól  — t        j                  | «      dk(  r1t        j                  g | j                  dd ¢d‘­d| j                  iŽS | j                  }|dd \  }}t        j
                  | d¬«      \  }}|t        j                  ||j                  ¬«      ddd…f   z  }t        j
                  |d¬«      \  }}||| z  z   }t        j                  |d¬«      \  }}t        j
                  | d¬«      \  }	}|	t        j                  ||	j                  ¬«      ddd…f   z  }
t        j
                  |
d¬«      \  }}|
||	 z  z   }
t        j                  |
d¬«      \  }}||k  ||k  z  }t        j                  ||||gd¬«      }|| j                  d«      z  } |j                  g |dd ¢d‘­Ž }|S )	aL  
    Computes the bounding boxes around the given input masks. The bounding boxes are in the XYXY format which
    corresponds the following required indices:
        - LEFT: left hand side of the bounding box
        - TOP: top of the bounding box
        - RIGHT: right of the bounding box
        - BOTTOM: bottom of the bounding box

    Return [0,0,0,0] for an empty mask. For input shape channel_1 x channel_2 x ... x height x width, the output shape
    is channel_1 x channel_2 x ... x 4.

    Args:
        - masks (`torch.Tensor` of shape `(batch, nb_mask, height, width)`)
    r   Néþÿÿÿé   Údevicer-   ©Údim©r;   )r1   ÚnumelÚzerosÚshaper;   ÚmaxÚarangeÚminÚstackÚ	unsqueezeÚreshape)r(   rA   ÚheightÚwidthÚ	in_heightÚ_Úin_height_coordsÚbottom_edgesÚ	top_edgesÚin_widthÚin_width_coordsÚright_edgesÚ
left_edgesÚempty_filterÚouts                  r&   Ú_batched_mask_to_boxrU   G   s±  € ô" ‡{�{�5Ó˜QÒÜ�{‰{ÐE˜EŸK™K¨¨Ð,ÐE¨aÒE¸¿¹ÑEÐEð �K‰K€EØ˜"˜#�J�M€FˆEô —9‘9˜U¨Ô+�L€IˆqØ ¤5§<¡<°¸y×?OÑ?OÔ#PÐQUÒWXÐQXÑ#YÑYÐÜ—i‘iÐ 0°bÔ9�O€L�!Ø'¨&°Y°JÑ*?Ñ?ÐÜ—9‘9Ð-°2Ô6�L€Iˆqô —)‘)˜E rÔ*�K€HˆaØ¤§¡¨e¸H¿O¹OÔ!LÈTÒSTÈWÑ!UÑU€OÜ—Y‘Y˜°BÔ7�N€K�Ø%¨°(°Ñ(;Ñ;€OÜ—I‘I˜o°2Ô6�M€J�ð   *Ñ,°À	Ñ1IÑJ€LÜ
�+‰+�z 9¨k¸<ÐHÈbÔ
Q€CØ
�,�×)Ñ)¨"Ó-Ñ
-€Cð ˆ#�+‰+Ð
%�u˜S˜b�zÐ
% 1Ò
%€CØ€Jr%   c                 óp  — t        j                  |t         j                  | j                  ¬«      }t        j                  |t         j                  | j                  ¬«      }|\  }}}}t        j                  ||||gg| j                  ¬«      }	t        | j                  «      dk(  r|	j                  d«      }	| |	z   j                  «       } t        j                  | |ddd…f   |d¬«      }
t        j                  | |ddd…f   |d¬«      }t        j                  |
| «      }
t        j                  |
d¬«      S )	zNFilter masks at the edge of a crop, but not at the edge of the original image.©r/   r;   r>   r	   é   Nr   )ÚatolÚrtolr<   )r1   Ú	as_tensorÚfloatr;   ÚtensorÚlenrA   rF   ÚiscloseÚlogical_andÚany)ÚboxesÚcrop_boxÚorig_boxrY   Úcrop_box_torchÚorig_box_torchÚleftÚtoprK   ÚoffsetÚnear_crop_edgeÚnear_image_edges               r&   Ú_is_box_near_crop_edgerl   x   sø   € ä—_‘_ X´U·[±[ÈÏÉÔV€NÜ—_‘_ X´U·[±[ÈÏÉÔV€Nà�O€Dˆ#ˆq�!Ü�\‰\˜D # t¨SÐ1Ð2¸5¿<¹<ÔH€Fä
ˆ5�;‰;Ó˜1ÒØ×!Ñ! !Ó$ˆØ�V‰^×"Ñ"Ó$€Eä—]‘] 5¨.¸ºq¸Ñ*AÈÐSTÔU€NÜ—m‘m E¨>¸$Â¸'Ñ+BÈÐTUÔV€OÜ×&Ñ& ~¸Ð7GÓH€NÜ�9‰9�^¨Ô+Ð+r%   rc   Úorig_heightÚ
orig_widthc                 óÌ   — |\  }}}}|dk(  r|dk(  r||k(  r||k(  r| S |||z
  z
  |||z
  z
  }	}|||z
  ||	|z
  f}
t         j                  j                  j                  | |
d¬«      S )Nr   )Úvalue)r1   ÚnnÚ
functionalÚpad)r(   rc   rm   rn   rg   rh   ÚrightÚbottomÚpad_xÚpad_yrs   s              r&   Ú
_pad_masksrx   Š   sƒ   € Ø'Ñ€Dˆ#ˆu�fØˆq‚y�S˜A’X %¨:Ò"5¸&ÀKÒ:OØˆà ¨¡Ñ.°¸vÈ¹|Ñ0Lˆ5€EØ�˜‘˜s E¨C¡KÐ
0€CÜ�8‰8×Ñ×"Ñ" 5¨#°QÐ"Ó7Ð7r%   Útarget_sizeÚcrop_n_layersÚoverlap_ratioÚpoints_per_cropÚcrop_n_points_downscale_factorÚreturnc                 óp  — t        | t        «      rt        d«      ‚| j                  dd }g }t	        |dz   «      D ]-  }t        |||z  z  «      }	|j                  t        |	«      «       Œ/ t        |||«      \  }
}t        |
| ||||«      \  }}t        j                  |
«      }
|
j                  «       }
t        j                  |«      }|j                  d«      j                  dddd«      }t        j                  |«      }t        j                   |dd…dd…dd…df   t        j"                  ¬«      }|
|||fS )	aó  
    Generates a list of crop boxes of different sizes. Each layer has (2**i)**2 boxes for the ith layer.

    Args:
        image (`torch.Tensor`):
            Image to generate crops for.
        target_size (`int`):
            Size of the smallest crop.
        crop_n_layers (`int`, *optional*):
            If `crops_n_layers>0`, mask prediction will be run again on crops of the image. Sets the number of layers
            to run, where each layer has 2**i_layer number of image crops.
        overlap_ratio (`int`, *optional*):
            Sets the degree to which crops overlap. In the first crop layer, crops will overlap by this fraction of the
            image length. Later layers with more crops scale down this overlap.
        points_per_crop (`int`, *optional*):
            Number of points to sam3ple per crop.
        crop_n_points_downscale_factor (`int`, *optional*):
            The number of points-per-side sam3pled in layer n is scaled down by crop_n_points_downscale_factor**n.
    z.Only one image is allowed for crop generation.r9   NrX   r   é   r	   r.   )Ú
isinstanceÚlistÚ
ValueErrorrA   Úranger"   ÚappendÚ_build_point_gridÚ_generate_per_layer_cropsÚ_generate_crop_imagesr1   r]   r\   rE   rF   ÚpermuteÚ	ones_likeÚint64)Úimagery   rz   r{   r|   r}   Úoriginal_sizeÚpoints_gridÚiÚn_pointsÚ
crop_boxesÚ
layer_idxsÚcropped_imagesÚpoint_grid_per_cropÚinput_labelss                  r&   Ú_generate_crop_boxesr–   ”   s0  € ô8 �%œÔÜÐIÓJÐJØ—K‘K  Ð$€Mà€KÜ�= 1Ñ$Ó%ò 8ˆÜ�Ð*HÈ!Ñ*KÑLÓMˆØ×ÑÔ,¨XÓ6Õ7ð8ô 7°}ÀmÐUbÓcÑ€J�
ä*?Ø�E˜;¨
°KÀó+Ñ'€NÐ'ô —‘˜jÓ)€JØ×!Ñ!Ó#€JÜ—k‘kÐ"5Ó6€OØ%×/Ñ/°Ó2×:Ñ:¸1¸aÀÀAÓF€OÜ—[‘[ Ó0€Nä—?‘? ?²1²aº¸A°:Ñ#>ÄeÇkÁkÔR€Là�¨¸ÐDÐDr%   c           	      óæ  — g g }}|\  }}t        ||«      }|j                  dd||g«       |j                  d«       t        | «      D �]  }d|dz   z  }	t        ||z  d|	z  z  «      }
t        t	        j
                  |
|	dz
  z  |z   |	z  «      «      }t        t	        j
                  |
|	dz
  z  |z   |	z  «      «      }t        |	«      D �cg c]  }t        ||
z
  |z  «      ‘Œ }}t        |	«      D �cg c]  }t        ||
z
  |z  «      ‘Œ }}t        ||«      D ]J  \  }}||t        ||z   |«      t        ||z   |«      g}|j                  |«       |j                  |dz   «       ŒL �Œ ||fS c c}w c c}w )aq  
    Generates 2 ** (layers idx + 1) crops for each crop_n_layers. Crops are in the XYWH format : The XYWH format
    consists of the following required indices:
        - X: X coordinate of the top left of the bounding box
        - Y: Y coordinate of the top left of the bounding box
        - W: width of the bounding box
        - H: height of the bounding box
    r   r€   rX   )rD   r…   r„   r"   ÚmathÚceilr   )rz   r{   r�   r‘   r’   Ú	im_heightÚim_widthÚ
short_sideÚi_layerÚn_crops_per_sideÚoverlapÚ
crop_widthÚcrop_heightr�   Úcrop_box_x0Úcrop_box_y0rg   rh   Úboxs                      r&   r‡   r‡   É   s   € ð   �
€JØ'Ñ€IˆxÜ�Y Ó)€Jð ×Ñ�q˜!˜X yÐ1Ô2Ø×Ñ�aÔÜ˜Ó'ó +ˆØ ¨1¡Ñ-ÐÜ�m jÑ0°AÐ8HÑ4HÑIÓJˆäœŸ™ GÐ/?À!Ñ/CÑ$DÀxÑ$OÐScÑ#cÓdÓeˆ
Üœ$Ÿ)™) WÐ0@À1Ñ0DÑ%EÈ	Ñ%QÐUeÑ$eÓfÓgˆä@EÐFVÓ@WÖX¸1”s˜J¨Ñ0°AÑ5Õ6ÐXˆÐXÜAFÐGWÓAXÖY¸A”s˜K¨'Ñ1°QÑ6Õ7ÐYˆÐYä  ¨kÓ:ò 	+‰IˆD�#Ø˜œc $¨Ñ"3°XÓ>ÄÀCÈ+ÑDUÐW`Ó@aÐbˆCØ×Ñ˜cÔ"Ø×Ñ˜g¨™kÕ*ò	+ð+ð �zÐ!Ð!ùò YùÚYs   ÃE)Ã/E.Ú
n_per_sidec                 ó  — dd| z  z  }t        j                  |d|z
  | «      }t        j                  |ddd…f   | df«      }t        j                  |dd…df   d| f«      }t        j                  ||gd¬«      j	                  dd«      }|S )z;Generates a 2D grid of points evenly spaced in [0,1]x[0,1].rX   r€   Nr-   r<   )r1   ÚlinspaceÚtilerE   rG   )r¥   ri   Úpoints_one_sideÚpoints_xÚpoints_yÚpointss         r&   r†   r†   ë   s‡   € à�!�j‘.Ñ!€FÜ—n‘n V¨Q°©Z¸ÓD€OÜ�z‰z˜/¨$²¨'Ñ2°ZÀ°OÓD€HÜ�z‰z˜/ª!¨T¨'Ñ2°Q¸
°OÓD€HÜ�[‰[˜( HÐ-°2Ô6×>Ñ>¸rÀ1ÓE€FØ€Mr%   c                 ó\  — g }g }t        | «      D ]—  \  }	}
|
\  }}}}|dd…||…||…f   }|j                  |«       |j                  dd }t        j                  |«      j                  d¬«      j                  d«      }|||	      |z  }t        |||«      }|j                  |«       Œ™ ||fS )z�
    Takes as an input bounding boxes that are used to crop the image. Based in the crops, the corresponding points are
    also passed.
    Nr9   )r   )Údimsr   )Ú	enumerater…   rA   r1   r]   ÚfliprF   Ú_normalize_coordinates)r‘   rŒ   rŽ   r’   ry   r�   Úinput_data_formatr“   Útotal_points_per_cropr�   rc   rg   rh   rt   ru   Ú
cropped_imÚcropped_im_sizeÚpoints_scaler¬   Únormalized_pointss                       r&   rˆ   rˆ   õ   sÔ   € ð €NØÐÜ  Ó,ò 8‰ˆˆ8Ø#+Ñ ˆˆc�5˜&Øš1˜c &˜j¨$¨u¨*Ð4Ñ5ˆ
à×Ñ˜jÔ)à$×*Ñ*¨2¨3Ð/ˆÜ—|‘| OÓ4×9Ñ9¸tÐ9ÓD×NÑNÈqÓQˆà˜Z¨™]Ñ+¨lÑ:ˆÜ2°;ÀÈÓVÐØ×$Ñ$Ð%6Õ7ð8ð Ð0Ð0Ð0r%   Úcoordsr�   c                 ó<  — |\  }}| dz  t        ||«      z  }||z  ||z  }}t        |dz   «      }t        |dz   «      }t        |«      j                  «       }|r|j	                  ddd«      }|d   ||z  z  |d<   |d   ||z  z  |d<   |r|j	                  dd«      }|S )zƒ
    Expects a numpy array of length 2 in the final dimension. Requires the original image size in (height, width)
    format.
    g      ð?ç      à?r-   r€   ).r   ).rX   r:   )rB   r"   r   r\   rG   )	ry   r¸   r�   Úis_bounding_boxÚ
old_heightÚ	old_widthÚscaleÚ
new_heightÚ	new_widths	            r&   r±   r±     sÂ   € ð *Ñ€J�	à˜#Ñ¤ J°	Ó :Ñ:€EØ&¨Ñ.°	¸EÑ0A�	€JÜ�I ‘OÓ$€IÜ�Z #Ñ%Ó&€Jä�fÓ×#Ñ#Ó%€FáØ—‘  A qÓ)ˆà˜F‘^ y°9Ñ'<Ñ=€Fˆ6�NØ˜F‘^ z°JÑ'>Ñ?€Fˆ6�NáØ—‘  AÓ&ˆà€Mr%   Úrlec                 óÒ   — | d   \  }}t        j                  ||z  t        ¬«      }d}d}| d   D ]  }|||||z    ||z  }| }Œ |j                  ||«      }|j	                  dd«      S )z/Compute a binary mask from an uncompressed RLE.Úsizer.   r   FÚcountsrX   )r1   ÚemptyÚboolrG   Ú	transpose)rÁ   rH   rI   ÚmaskÚidxÚparityÚcounts          r&   Ú_rle_to_maskrÌ   *  sƒ   € à˜‘K�M€FˆEÜ�;‰;�v ‘~¬TÔ2€DØ
€CØ€FØ�X‘ò ˆØ"(ˆˆS�3˜‘;ÐØˆu‰ˆØ�‰ðð �<‰<˜˜vÓ&€DØ�>‰>˜!˜QÓÐr%   c                 ó  — t        |j                  «       |t        j                  |j                  d   «      |¬«      }||   }|D �cg c]  }| |   ‘Œ	 } }||   }| D �cg c]  }t        |«      ‘Œ }}||| |fS c c}w c c}w )aë  
    Perform NMS (Non Maximum Suppression) on the outputs.

    Args:
            rle_masks (`torch.Tensor`):
                binary masks in the RLE format
            iou_scores (`torch.Tensor` of shape (nb_masks, 1)):
                iou_scores predicted by the model
            mask_boxes (`torch.Tensor`):
                The bounding boxes corresponding to segmentation masks
            amg_crops_nms_thresh (`float`, *optional*, defaults to 0.7):
                NMS threshold.
    r   )rb   ÚscoresÚidxsÚiou_threshold)r   r\   r1   r@   rA   rÌ   )Ú	rle_masksÚ
iou_scoresÚ
mask_boxesÚamg_crops_nms_threshÚkeep_by_nmsr�   rÁ   r(   s           r&   Ú!_post_process_for_mask_generationrÖ   8  s“   € ô Ø×ÑÓ ØÜ�[‰[˜×)Ñ)¨!Ñ,Ó-Ø*ô	€Kð ˜KÑ(€JØ'2Ö3 !�˜1“Ð3€IÐ3Ø˜KÑ(€JØ*3Ö4 3Œ\˜#ÕÐ4€EÐ4à�*˜i¨Ð3Ð3ùò	 4ùâ4s   ÁA8ÁA=c                 óˆ  — | j                   \  }}}| j                  ddd«      j                  d«      } | dd…dd…f   | dd…dd…f   z  }|j                  «       }g }t	        |«      D ]Ø  }||dd…df   |k(  df   dz   }t        |«      dk(  rA| |df   dk(  r|j                  ||g||z  gdœ«       n|j                  ||gd||z  gdœ«       Œf|dd |dd z
  }	| |df   dk(  rg ndg}
|
|d   j                  «       g|	j                  «       z   ||z  |d   j                  «       z
  gz   z  }
|j                  ||g|
dœ«       ŒÚ |S )z^
    Encodes masks the run-length encoding (RLE), in the format expected by pycoco tools.
    r   r€   rX   Nr-   )rÃ   rÄ   )	rA   r‰   ÚflattenÚnonzeror„   r^   r…   ÚitemÚtolist)Ú
input_maskÚ
batch_sizerH   rI   ÚdiffÚchange_indicesrT   r�   Úcur_idxsÚbtw_idxsrÄ   s              r&   Ú_mask_to_rlerâ   U  s�  € ð
 !+× 0Ñ 0Ñ€J�˜Ø×#Ñ# A q¨!Ó,×4Ñ4°QÓ7€Jð ’a˜™�eÑ˜zª!¨S¨b¨S¨&Ñ1Ñ1€DØ—\‘\“^€Nð €CÜ�:Óò @ˆØ! .²°A°Ñ"6¸!Ñ";¸QÐ">Ñ?À!ÑCˆÜˆx‹=˜AÒð ˜!˜Q˜$Ñ 1Ò$Ø—
‘
 V¨U OÀÈÁÐ?OÑPÕQà—
‘
 V¨U OÀÀ6ÈEÁ>Ð?RÑSÔTØØ˜A˜B�< (¨3¨B -Ñ/ˆØ! ! Q $Ñ'¨1Ò,‘°1°#ˆØ�8˜A‘;×#Ñ#Ó%Ð&¨¯©Ó):Ñ:¸fÀu¹nÈxÐXZÉ|×O`ÑO`ÓObÑ>bÐ=cÑcÑcˆØ�
‰
˜V U˜O°vÑ>Õ?ð@ð €Jr%   c                 óè  — t        |t        t        f«      rMt        j                  |D �cg c]  }|d   ‘Œ	 c}«      }t        j                  |D �cg c]  }|d   ‘Œ	 c}«      }n:t        |t        j
                  «      r|j                  d«      \  }}nt        d«      ‚t        j                  ||||gd¬«      }|j                  d«      j                  | j                  «      }| |z  } | S c c}w c c}w )a  
    Scale batch of bounding boxes to the target sizes.

    Args:
        boxes (`torch.Tensor` of shape `(batch_size, num_boxes, 4)`):
            Bounding boxes to scale. Each box is expected to be in (x1, y1, x2, y2) format.
        target_sizes (`list[tuple[int, int]]` or `torch.Tensor` of shape `(batch_size, 2)`):
            Target sizes to scale the boxes to. Each target size is expected to be in (height, width) format.

    Returns:
        `torch.Tensor` of shape `(batch_size, num_boxes, 4)`: Scaled bounding boxes.
    r   rX   z4`target_sizes` must be a list, tuple or torch.Tensorr<   )r�   r‚   Útupler1   r]   ÚTensorÚunbindÚ	TypeErrorrE   rF   Útor;   )rb   Útarget_sizesr�   Úimage_heightÚimage_widthÚscale_factors         r&   Ú_scale_boxesrí   t  sÌ   € ô �,¤¤u Ô.Ü—|‘|°<Ö$@¨a Q q£TÒ$@ÓAˆÜ—l‘l°,Ö#?¨Q A a£DÒ#?Ó@‰Ü	�L¤%§,¡,Ô	/Ø$0×$7Ñ$7¸Ó$:Ñ!ˆ‘käÐNÓOÐOä—;‘; ¨\¸;ÈÐUÐ[\Ô]€LØ×)Ñ)¨!Ó,×/Ñ/°·±Ó=€LØ�LÑ €EØ€Lùò %AùÚ#?s   ªC*ÁC/c                   ó`  ‡ — e Zd ZeZej                  ZeZ	e
ZdddœZdddœZdZdZdZdZdZdZdZdee   fˆ fd„Ze	 d*ded	edz  dee   d
efˆ fd„«       Z	 d*dedz  d
efˆ fd„Z	 d*ded	edz  dedede e!df   dz  dee   d
efd„Z"de#d   de!e$z  dz  d
dfˆ fd„Z%	 	 	 	 	 d+ddde&de'de&dz  de#e&   dz  de(d   fd„Z)	 	 	 	 d,d„Z*	 	 	 	 	 d-d„Z+d„ Z,d e-j\                  d
e-j\                  fd!„Z/	 	 	 d.d"e#e0e&e&f      dz  d#e'd$ed
d%fd&„Z1d/d#e'd"e#e0   dz  fd'„Z2	 	 	 d0d#e'd(e'd"e#e0   dz  fd)„Z3ˆ xZ4S )1ÚSam3ImageProcessorið  )rH   rI   i   TNÚkwargsc                 ó$   •— t        ‰| �  di |¤Ž y )Nr$   )ÚsuperÚ__init__)Úselfrð   Ú	__class__s     €r&   ró   zSam3ImageProcessor.__init__¢  s   ø€ Ü‰ÑÑ"˜6Ó"r%   ÚimagesÚsegmentation_mapsr~   c                 ó&   •— t        ‰| �  ||fi |¤ŽS )zp
        segmentation_maps (`ImageInput`, *optional*):
            The segmentation maps to preprocess.
        )rò   Ú
preprocess)rô   rö   r÷   rð   rõ   s       €r&   rù   zSam3ImageProcessor.preprocess¥  s   ø€ ô ‰wÑ! &Ð*;ÑF¸vÑFÐFr%   r   c                 ó|   •— |�&t        |t        «      st        di t        |d¬«      ¤Ž}||d<   t        ‰| �  di |¤ŽS )zT
        Update kwargs that need further processing before being validated.
        r   )Ú
param_namer$   )r�   r   r   rò   Ú_standardize_kwargs)rô   r   rð   rõ   s      €r&   rü   z&Sam3ImageProcessor._standardize_kwargs²  sE   ø€ ð Ð ¬°I¼xÔ)HÜ ÑT¤=°À{Ô#SÑTˆIØ'ˆˆ{ÑÜ‰wÑ*Ñ4¨VÑ4Ð4r%   Údo_convert_rgbr²   r;   ztorch.devicec                 ó8  — | j                  ||||¬«      }|D �cg c]  }|j                  dd ‘Œ }}|j                  «       }	 | j                  |fi |	¤Ž}
|
|dœ}|�«| j                  |ddt        j
                  ¬«      }|j                  «       }|j                  ddt        j                  |j                  d«      d	œ«        | j                  dd
|i|¤Ž}|j                  d«      j                  t        j                  «      |d<   t        ||d   ¬«      S c c}w )z/
        Preprocess image-like inputs.
        )rö   rý   r²   r;   r9   N)Úpixel_valuesÚoriginal_sizesr€   F)rö   Úexpected_ndimsrý   r²   r   )Údo_normalizeÚ
do_rescaleÚresamplerÃ   rö   rX   ÚlabelsÚreturn_tensors)ÚdataÚtensor_typer$   )Ú_prepare_image_like_inputsrA   ÚcopyÚ_preprocessr   ÚFIRSTÚupdater   ÚNEARESTÚpopÚsqueezerè   r1   r‹   r   )rô   rö   r÷   rý   r²   r;   rð   rŒ   r   Úimages_kwargsrÿ   r  Úprocessed_segmentation_mapsÚsegmentation_maps_kwargss                 r&   Ú_preprocess_image_like_inputsz0Sam3ImageProcessor._preprocess_image_like_inputs¿  sE  € ð ×0Ñ0Ø¨.ÐL]Ðflð 1ó 
ˆð 9?Ö?¨u˜%Ÿ+™+ b cÒ*Ð?ˆÐ?ØŸ™›ˆØ'�t×'Ñ'¨Ñ@°-Ñ@ˆà(Ø,ñ
ˆð
 Ð(Ø*.×*IÑ*IØ(Ø Ø$Ü"2×"8Ñ"8ð	 +Jó +Ð'ð (.§{¡{£}Ð$Ø$×+Ñ+à$)Ø"'Ü 2× :Ñ :Ø4×8Ñ8¸ÓEñ	ôð +;¨$×*:Ñ*:ñ +Ø2ð+Ø6Nñ+Ð'ð 9×@Ñ@ÀÓC×FÑFÄuÇ{Á{ÓSˆD�‰Nä °6Ð:JÑ3KÔLÐLùò= @s   šDr)   r  c                 ó<   •— t        ‰| �  |fd|i|¤Žj                  S )Nr  )rò   r  rÿ   )rô   rö   r  rð   rõ   s       €r&   r  zSam3ImageProcessor._preprocessî  s%   ø€ ô ‰wÑ" 6ÑS¸.ÐSÈFÑS×`Ñ`Ð`r%   rŒ   z+np.ndarray | PIL.Image.Image | torch.Tensorrz   r{   r|   r}   c                 óî   — | j                  |«      }t        ||||||«      \  }}}	}
|€t        j                  d«      }|j	                  |«      }|j	                  |«      }|
j	                  |«      }
|||	|
fS )a  
        Generates a list of crop boxes of different sizes. Each layer has (2**i)**2 boxes for the ith layer.

        Args:
            image (`torch.Tensor`):
                Input original image
            target_size (`int`):
                Target size of the resized image
            crop_n_layers (`int`, *optional*, defaults to 0):
                If >0, mask prediction will be run again on crops of the image. Sets the number of layers to run, where
                each layer has 2**i_layer number of image crops.
            overlap_ratio (`float`, *optional*, defaults to 512/1500):
                Sets the degree to which crops overlap. In the first crop layer, crops will overlap by this fraction of
                the image length. Later layers with more crops scale down this overlap.
            points_per_crop (`int`, *optional*, defaults to 32):
                Number of points to sam3ple from each crop.
            crop_n_points_downscale_factor (`list[int]`, *optional*, defaults to 1):
                The number of points-per-side sam3pled in layer n is scaled down by crop_n_points_downscale_factor**n.
            device (`torch.device`, *optional*, defaults to None):
                Device to use for the computation. If None, cpu will be used.
        Úcpu)Úprocess_imager–   r1   r;   rè   )rô   rŒ   ry   rz   r{   r|   r}   r;   r‘   r“   r•   s              r&   Úgenerate_crop_boxesz&Sam3ImageProcessor.generate_crop_boxesö  sŠ   € ð> ×"Ñ" 5Ó)ˆÜDXØØØØØØ*óE
ÑAˆ
�O ^°\ð ˆ>Ü—\‘\ %Ó(ˆFØ—]‘] 6Ó*ˆ
Ø)×,Ñ,¨VÓ4ˆà#—‘ vÓ.ˆà˜?¨N¸LÐHÐHr%   c	                 óŽ  — |\  }	}
|j                  dd«      }|j                  dd«      }|j                  d   |j                  d   k7  rt        d«      ‚|j                  |j                  k7  r|j	                  |j                  «      }|j                  d   }t        j                  |t
        j                  |j                  ¬«      }|dkD  r|||kD  z  }|dkD  rt        |||«      }|||kD  z  }||   }||   }||kD  }t        |«      }t        ||dd|
|	g«       }||   }||   }||   }t        |||	|
«      }t        |«      }|||fS )a  
        Filters the predicted masks by selecting only the ones that meets several criteria. The first criterion being
        that the iou scores needs to be greater than `pred_iou_thresh`. The second criterion is that the stability
        score needs to be greater than `stability_score_thresh`. The method also converts the predicted masks to
        bounding boxes and pad the predicted masks if necessary.

        Args:
            masks (`torch.Tensor`):
                Input masks.
            iou_scores (`torch.Tensor`):
                List of IoU scores.
            original_size (`tuple[int,int]`):
                Size of the original image.
            cropped_box_image (`torch.Tensor`):
                The cropped image.
            pred_iou_thresh (`float`, *optional*, defaults to 0.88):
                The threshold for the iou scores.
            stability_score_thresh (`float`, *optional*, defaults to 0.95):
                The threshold for the stability score.
            mask_threshold (`float`, *optional*, defaults to 0):
                The threshold for the predicted masks.
            stability_score_offset (`float`, *optional*, defaults to 1):
                The offset for the stability score used in the `_compute_stability_score` method.
        r   rX   z4masks and iou_scores must have the sam3e batch size.rW   ç        )rØ   rA   rƒ   r;   rè   r1   ÚonesrÆ   r7   rU   rl   rx   râ   )rô   r(   rÒ   r�   Úcropped_box_imageÚpred_iou_threshÚstability_score_threshr*   r+   Úoriginal_heightÚoriginal_widthrÝ   Ú	keep_maskr6   rÎ   Úconverted_boxess                   r&   Úfilter_maskszSam3ImageProcessor.filter_masks'  sw  € ðF +8Ñ'ˆ˜Ø×'Ñ'¨¨1Ó-ˆ
Ø—‘˜a Ó#ˆà�;‰;�q‰>˜Z×-Ñ-¨aÑ0Ò0ÜÐSÓTÐTà�<‰<˜:×,Ñ,Ò,Ø#Ÿ™ u§|¡|Ó4ˆJà—[‘[ ‘^ˆ
ä—J‘J˜z´·±ÀEÇLÁLÔQˆ	à˜SÒ Ø! Z°/Ñ%AÑBˆIð " CÒ'Ü7¸¸~ÐOeÓfÐØ!Ð%5Ð8NÑ%NÑOˆIà˜IÑ&ˆØ�iÑ ˆð ˜Ñ&ˆÜ.¨uÓ5ˆä+ØÐ.°°A°~ÀÐ0Wó
ð 
ˆ	ð ˜	Ñ"ˆØ�iÑ ˆØ)¨)Ñ4ˆä˜5Ð"3°_ÀnÓUˆä˜UÓ#ˆà�f˜oÐ-Ð-r%   c                 óô  — t        |t        j                  t        j                  f«      r|j                  «       }g }	t        |«      D ]­  \  }
}t        ||
   t        j                  «      rt        j                  ||
   «      ||
<   n(t        ||
   t        j                  «      st        d«      ‚t        j                  ||
   |dd¬«      }|r| j                  |«      }|r||kD  }|	j                  |«       Œ¯ |	S )aG  
        Remove padding and upscale masks to the original image size.

        Args:
            masks (`Union[torch.Tensor, List[torch.Tensor], np.ndarray, List[np.ndarray]]`):
                Batched masks from the mask_decoder in (batch_size, num_channels, height, width) format.
            original_sizes (`Union[torch.Tensor, List[Tuple[int,int]]]`):
                The original sizes of each image before it was resized to the model's expected input shape, in (height,
                width) format.
            mask_threshold (`float`, *optional*, defaults to 0.0):
                Threshold for binarization and post-processing operations.
            binarize (`bool`, *optional*, defaults to `True`):
                Whether to binarize the masks.
            max_hole_area (`float`, *optional*, defaults to 0.0):
                The maximum area of a hole to fill.
            max_sprinkle_area (`float`, *optional*, defaults to 0.0):
                The maximum area of a sprinkle to fill.
            apply_non_overlapping_constraints (`bool`, *optional*, defaults to `False`):
                Whether to apply non-overlapping constraints to the masks.

        Returns:
            (`torch.Tensor`): Batched masks in batch_size, num_channels, height, width) format, where (height, width)
            is given by original_size.
        zIInput masks should be a list of `torch.tensors` or a list of `np.ndarray`ÚbilinearF)ÚmodeÚalign_corners)r�   r1   rå   ÚnpÚndarrayrÛ   r¯   Ú
from_numpyrç   ÚFÚinterpolateÚ"_apply_non_overlapping_constraintsr…   )rô   r(   r   r*   ÚbinarizeÚmax_hole_areaÚmax_sprinkle_areaÚ!apply_non_overlapping_constraintsrð   Úoutput_masksr�   r�   Úinterpolated_masks                r&   Úpost_process_masksz%Sam3ImageProcessor.post_process_masksu  sä   € ôF �n¤u§|¡|´R·Z±ZÐ&@ÔAØ+×2Ñ2Ó4ˆNàˆÜ )¨.Ó 9ò 
	3ÑˆAˆ}Ü˜% ™(¤B§J¡JÔ/Ü ×+Ñ+¨E°!©HÓ5��a’Ü  a¡¬%¯,©,Ô7ÜÐ kÓlÐlÜ !§¡¨e°A©h¸ÈJÐfkÔ lÐÙ0Ø$(×$KÑ$KÐL]Ó$^Ð!ÙØ$5¸Ñ$FÐ!Ø×ÑÐ 1Õ2ð
	3ð Ðr%   c                 ó   — t        ||||«      S )a$  
        Post processes mask that are generated by calling the Non Maximum Suppression algorithm on the predicted masks.

        Args:
            all_masks (`torch.Tensor`):
                List of all predicted segmentation masks
            all_scores (`torch.Tensor`):
                List of all predicted iou scores
            all_boxes (`torch.Tensor`):
                List of all bounding boxes of the predicted masks
            crops_nms_thresh (`float`):
                Threshold for NMS (Non Maximum Suppression) algorithm.
        )rÖ   )rô   Ú	all_masksÚ
all_scoresÚ	all_boxesÚcrops_nms_threshs        r&   Ú post_process_for_mask_generationz3Sam3ImageProcessor.post_process_for_mask_generationª  s   € ô 1°¸JÈ	ÐScÓdÐdr%   Ú
pred_masksc                 ó   — |j                  d«      }|dk(  r|S |j                  }t        j                  |dd¬«      }t        j                  ||¬«      dd…dddf   }||k(  }t        j
                  ||t        j                  |d¬«      «      }|S )	z´
        Apply non-overlapping constraints to the object scores in pred_masks. Here we
        keep only the highest scoring object at each spatial location in pred_masks.
        r   rX   T)r=   Úkeepdimr>   Ng      $À)rB   )rÃ   r;   r1   ÚargmaxrC   ÚwhereÚclamp)rô   r<  rÝ   r;   Úmax_obj_indsÚbatch_obj_indsÚkeeps          r&   r.  z5Sam3ImageProcessor._apply_non_overlapping_constraintsº  sŠ   € ð
  —_‘_ QÓ'ˆ
Ø˜Š?ØÐà×"Ñ"ˆä—|‘| J°A¸tÔDˆäŸ™ j¸Ô@ÂÀDÈ$ÐPTÐATÑUˆØ˜~Ñ-ˆô —[‘[  z´5·;±;¸zÈuÔ3UÓVˆ
ØÐr%   ré   Ú	thresholdÚreturn_segmentation_scoreszBlist[torch.Tensor] | list[SemanticSegmentationPostProcessorOutput]c                 óÎ  — |j                   }|€t        d«      ‚|j                  «       }t        |«      }|�¼t        |«      t        |«      k7  rt        d«      ‚g }t	        |«      D ]‰  }	t
        j                  j                  j                  ||	   j                  d¬«      ||	   dd¬«      }
|j                  t        |
d   |kD  j                  t
        j                  «      |
d   d	œ¬
«      «       Œ‹ nMt	        |«      D �cg c]9  }t        ||df   |kD  j                  t
        j                  «      ||   d	œ¬
«      ‘Œ; }}|s|D �cg c]  }|j                  ‘Œ }}|S c c}w c c}w )a±  
        Converts the output of [`Sam3Model`] into semantic segmentation maps.

        Args:
            outputs ([`Sam3ImageSegmentationOutput`]):
                Raw outputs of the model containing semantic_seg.
            target_sizes (`list[tuple[int, int]]` of length `batch_size`, *optional*):
                List of tuples corresponding to the requested final size (height, width) of each prediction. If unset,
                predictions will not be resized.
            threshold (`float`, *optional*, defaults to 0.5):
                Threshold for binarizing the semantic segmentation masks.
            return_segmentation_scores (`bool`, *optional*, defaults to `False`):
                Whether to return segmentation scores alongside the segmentation map. When `True`, each element of
                the returned list is a [`SemanticSegmentationPostProcessorOutput`] with fields `segmentation`
                (binary class IDs, shape `(height, width)`) and `segmentation_scores` (sigmoid probabilities,
                shape `(1, height, width)`).

        Returns:
            `list[torch.Tensor]` or `list[SemanticSegmentationPostProcessorOutput]`: When
            `return_segmentation_scores=False` (default), a list of length `batch_size` where each item is a
            segmentation map of shape `(height, width)` with class IDs. When `return_segmentation_scores=True`,
            a list of [`SemanticSegmentationPostProcessorOutput`] with fields `segmentation` (class IDs, shape
            `(height, width)`) and `segmentation_scores` (shape `(1, height, width)`). In both cases,
            `(height, width)` corresponds to the target size (if `target_sizes` is specified).
        zƒSemantic segmentation output is not available in the model outputs. Make sure the model was run with semantic segmentation enabled.zTMake sure that you pass in as many target sizes as the batch dimension of the logitsr   r<   r&  F©rÃ   r'  r(  )r   r   )ÚsegmentationÚsegmentation_scores)r  )Úsemantic_segrƒ   Úsigmoidr^   r„   r1   rq   rr   r-  rF   r…   r   rè   ÚlongrI  )rô   Úoutputsré   rE  rF  Úsemantic_logitsÚsemantic_probsrÝ   Úsemantic_segmentationrÉ   Úresized_probsr�   rÚ   s                r&   Ú"post_process_semantic_segmentationz5Sam3ImageProcessor.post_process_semantic_segmentationÎ  sš  € ðD "×.Ñ.ˆàÐ"ÜðRóð ð )×0Ñ0Ó2ˆÜ˜Ó)ˆ
ð Ð#Ü�?Ó#¤s¨<Ó'8Ò8Ü Øjóð ð %'Ð!Ü˜ZÓ(ò �Ü %§¡× 3Ñ 3× ?Ñ ?Ø" 3Ñ'×1Ñ1°aÐ1Ó8Ø% cÑ*Ø#Ø"'ð	 !@ó !�ð &×,Ñ,Ü;à-:¸4Ñ-@À9Ñ-L×,PÑ,PÔQV×Q[ÑQ[Ó,\Ø3@ÀÑ3Cñôõñô. ˜zÓ*ö%ð ô 8à)7¸¸1¸Ñ)=À	Ñ)I×(MÑ(MÌeÏjÉjÓ(YØ/=¸aÑ/@ñöð%Ð!ð %ñ *ØCXÖ$Y¸4 T×%6Ó%6Ð$YÐ!Ð$Yà$Ð$ùò%ùò %Zs   Ä >EÅE"c                 ó‚  — |j                   }|j                  }|j                  }|j                  d   }|�t	        |«      |k7  rt        d«      ‚|j                  «       }|�|j                  «       }	||	z  }|}
|�t        |
|«      }
g }t        ||
«      D ](  \  }}||kD  }||   }||   }|j                  ||dœ«       Œ* |S )aD  
        Converts the raw output of [`Sam3Model`] into final bounding boxes in (top_left_x, top_left_y,
        bottom_right_x, bottom_right_y) format.

        Args:
            outputs ([`Sam3ImageSegmentationOutput`]):
                Raw outputs of the model containing pred_boxes, pred_logits, and optionally presence_logits.
            threshold (`float`, *optional*, defaults to 0.3):
                Score threshold to keep object detection predictions.
            target_sizes (`list[tuple[int, int]]`, *optional*):
                List of tuples (`tuple[int, int]`) containing the target size `(height, width)` of each image in the
                batch. If unset, predictions will not be resized.

        Returns:
            `list[dict]`: A list of dictionaries, each dictionary containing the following keys:
                - **scores** (`torch.Tensor`): The confidence scores for each predicted box on the image.
                - **boxes** (`torch.Tensor`): Image bounding boxes in (top_left_x, top_left_y, bottom_right_x,
                  bottom_right_y) format.
        r   ú9Make sure that you pass in as many target sizes as images)rÎ   rb   )
Úpred_logitsÚ
pred_boxesÚpresence_logitsrA   r^   rƒ   rL  rí   Úzipr…   )rô   rN  rE  ré   rV  rW  rX  rÝ   Úbatch_scoresÚpresence_scoresÚbatch_boxesÚresultsrÎ   rb   rD  s                  r&   Úpost_process_object_detectionz0Sam3ImageProcessor.post_process_object_detection#  sï   € ð( ×)Ñ)ˆØ×'Ñ'ˆ
Ø!×1Ñ1ˆà ×&Ñ& qÑ)ˆ
àÐ#¬¨LÓ(9¸ZÒ(GÜÐXÓYÐYð #×*Ñ*Ó,ˆØÐ&Ø-×5Ñ5Ó7ˆOØ'¨/Ñ9ˆLð !ˆð Ð#Ü& {°LÓAˆKàˆÜ  ¨{Ó;ò 	?‰MˆF�EØ˜IÑ%ˆDØ˜D‘\ˆFØ˜$‘KˆEØ�N‰N f°uÑ=Õ>ð		?ð ˆr%   r*   c                 óæ  — |j                   }|j                  }|j                  }|j                  }|j                  d   }	|�t        |«      |	k7  rt        d«      ‚|j                  «       }
|�|j                  «       }|
|z  }
|j                  «       }|}|�t        ||«      }g }t        t        |
||«      «      D ]´  \  }\  }}}||kD  }||   }||   }||   }|�^||   }t        |«      dkD  rKt        j                  j                  j                  |j                  d«      |dd¬«      j!                  d«      }||kD  j#                  t        j$                  «      }|j'                  |||dœ«       Œ¶ |S )aQ  
        Converts the raw output of [`Sam3Model`] into instance segmentation predictions with bounding boxes and masks.

        Args:
            outputs ([`Sam3ImageSegmentationOutput`]):
                Raw outputs of the model containing pred_boxes, pred_logits, pred_masks, and optionally
                presence_logits.
            threshold (`float`, *optional*, defaults to 0.3):
                Score threshold to keep instance predictions.
            mask_threshold (`float`, *optional*, defaults to 0.5):
                Threshold for binarizing the predicted masks.
            target_sizes (`list[tuple[int, int]]`, *optional*):
                List of tuples (`tuple[int, int]`) containing the target size `(height, width)` of each image in the
                batch. If unset, predictions will not be resized.

        Returns:
            `list[dict]`: A list of dictionaries, each dictionary containing the following keys:
                - **scores** (`torch.Tensor`): The confidence scores for each predicted instance on the image.
                - **boxes** (`torch.Tensor`): Image bounding boxes in (top_left_x, top_left_y, bottom_right_x,
                  bottom_right_y) format.
                - **masks** (`torch.Tensor`): Binary segmentation masks for each instance, shape (num_instances,
                  height, width).
        r   rU  r&  FrH  )rÎ   rb   r(   )rV  rW  r<  rX  rA   r^   rƒ   rL  rí   r¯   rY  r1   rq   rr   r-  rF   r  rè   rM  r…   )rô   rN  rE  r*   ré   rV  rW  r<  rX  rÝ   rZ  r[  Úbatch_masksr\  r]  rÉ   rÎ   rb   r(   rD  ry   s                        r&   Ú"post_process_instance_segmentationz5Sam3ImageProcessor.post_process_instance_segmentationV  s¡  € ð< ×)Ñ)ˆØ×'Ñ'ˆ
Ø×'Ñ'ˆ
Ø!×1Ñ1ˆà ×&Ñ& qÑ)ˆ
àÐ#¬¨LÓ(9¸ZÒ(GÜÐXÓYÐYð #×*Ñ*Ó,ˆØÐ&Ø-×5Ñ5Ó7ˆOØ'¨/Ñ9ˆLð !×(Ñ(Ó*ˆð !ˆð Ð#Ü& {°LÓAˆKàˆÜ+4´S¸À{ÐT_Ó5`Ó+aò 	OÑ'ˆCÑ'�&˜% à˜IÑ%ˆDØ˜D‘\ˆFØ˜$‘KˆEØ˜$‘KˆEð Ð'Ø*¨3Ñ/�Ü�u“: ’>Ü!ŸH™H×/Ñ/×;Ñ;ØŸ™¨Ó*Ø(Ø'Ø&+ð	 <ó ÷
 ‘g˜a“jð ð ˜^Ñ+×/Ñ/´·
±
Ó;ˆEà�N‰N f°uÀuÑMÕNð+	Oð. ˆr%   ©N)r   ç¥âìÃgØÕ?é    rX   N)g)\�Âõ(ì?gffffffî?r   rX   )r  Tr  r  F)Nrº   F)ç333333Ó?N)re  rº   N)5r   r   r   r   Úvalid_kwargsr   ÚBILINEARr  r   Ú
image_meanr   Ú	image_stdrÃ   r   Ú	do_resizer  r  rý   Údo_padÚpad_sizeÚmask_pad_sizer   ró   r   r   r   rù   r   r    rü   rÆ   r   r   r!   r  r‚   r   r  r"   r\   r   r  r$  r5  r;  r1   rå   r.  rä   rS  r^  ra  Ú__classcell__)rõ   s   @r&   rï   rï   �  sá  ø„ à+€LØ!×*Ñ*€HØ'€JØ%€IØ TÑ*€DØ¨Ñ-€IØ€IØ€JØ€LØ€Nð €FØ€HØ€Mð# Ð(@Ñ!Aõ #ð ð 04ñ
Gàð
Gð &¨Ñ,ð
Gð Ð1Ñ2ð	
Gð
 
ô
Gó ð
Gð &*ñ5à˜d‘?ð5ð 
õ	5ð& 59ñ-Màð-Mð &¨Ñ,ð-Mð ð	-Mð
 ,ð-Mð �c˜>Ð)Ñ*¨TÑ1ð-Mð Ð1Ñ2ð-Mð 
ó-Mð^aà�^Ñ$ðað ˜jÑ(¨4Ñ/ðað
 
õað Ø)Ø&(Ø;<Ø+/ñ/Ià<ð/Ið ð	/Ið
 ð/Ið ˜t™ð/Ið )-¨S©	°DÑ(8ð/Ið ˜Ñ(ó/Iðn Ø#ØØ óL.ðd ØØØØ*/ó3òjeð ¸U¿\¹\ð ÈeÏlÉló ð. 6:ØØ+0ñS%ð ˜5  c ™?Ñ+¨dÑ2ðS%ð ð	S%ð
 %)ðS%ð 
NóS%ñj1Àð 1Ð[_Ð`eÑ[fÐimÑ[mó 1ðl Ø #Ø+/ñPð ðPð ð	Pð
 ˜5‘k DÑ(÷Pr%   rï   )r(   r)   )g      4@)r   rc  rd  rX   rb  )F)gffffffæ?)rÜ   r)   )?r˜   r
  r   Ú	itertoolsr   Útypingr   r   r   Únumpyr)  r1   Útorch.nn.functionalrq   rr   r,  Útorchvision.ops.boxesr   Úimage_processing_backendsr
   Úimage_processing_outputsr   Úimage_processing_utilsr   r   Úimage_utilsr   r   r   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   ÚPILr   r\   r"   r7   rU   rl   r‚   rx   rä   r–   r‡   rå   r†   rˆ   r±   r    r!   rÌ   rÖ   râ   rí   rï   Ú__all__r$   r%   r&   ú<module>r|     sÕ  ðó, Ý Ý ß 'Ñ 'ã Û ß Ð Ý -å ;Ý Oß A÷÷ ÷ 5ß DÑ Dñ ÔÛô˜|°5õ ð Nð ÀEð Ðcfó ó.ób,ð$8  S¡	ð 8¸ð 8Èó 8ð Ø%Ø"$Ø78ñ2Eàð2Eð ð2Eð ð	2Eð
 ˜4‘Zð2Eð %)¨¡I°Ñ$4ð2Eð ˆ4��S‘	‰?˜D ™IÐ%Ñ&ó2Eòj"ðD #ð ¨%¯,©,ó ð _có1ð4 ]bñØðØ#Ÿl™lðØ;@ÀÀcÀ¹?ðà
‡\�\óð8 �d˜3 ˜8‘nð  ¨¯©ó  ó4ó:ò>ð8 ôUÐ+ó Uó ðUðp  Ð
 �r%   