
    Z jLo                        S SK r S SKJr  S SKJr  S SKJrJrJr  S SK	r
S SKrS SKJs  Jr  S SKJr  SSKJr  SSKJrJr  SS	KJrJrJrJrJrJr  SS
KJrJ r   SSK!J"r"J#r#J$r$  \$" 5       (       a  S SK%r% " S S\SS9r&SSS\'S\(4S jr)S/S jr*S0S jr+S\,\(   S\(S\(4S jr-    S1S\(S\(S\'S\(S-  S\,\(   S-  S \.\,\,\(      \,\(   4   4S! jjr/S" r0S#\(S \Rb                  4S$ jr2 S2S% jr3 S3S\(S&\Rb                  S'\.\(\(4   S \Rb                  4S( jjr4S)\5\6\4   S \Rb                  4S* jr7S4S+ jr8S5S, jr9\# " S- S.\5      5       r:S./r;g)6    N)deepcopy)product)AnyOptionalUnion)batched_nms   )TorchvisionBackend)BatchFeatureget_size_dict)IMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STDChannelDimension
ImageInputPILImageResamplingSizeDict)ImagesKwargsUnpack)
TensorTypeauto_docstringis_vision_availablec                   .    \ rS rSr% Sr\\\4   \S'   Sr	g)Sam2ImageProcessorKwargs0   z|
mask_size (`dict[str, int]`, *optional*):
    The size `{"height": int, "width": int}` to resize the segmentation maps to.
	mask_size N)
__name__
__module____qualname____firstlineno____doc__dictstrint__annotations____static_attributes__r       /root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/sam2/image_processing_sam2.pyr   r   0   s    
 CH~r'   r   F)totalmaskstorch.Tensormask_thresholdstability_score_offsetc                 
   XU-   :  R                  S[        R                  S9R                  S[        R                  S9nXU-
  :  R                  S[        R                  S9R                  S[        R                  S9nX4-  nU$ )Ndtype)sumtorchint16int32)r*   r,   r-   intersectionsunionsstability_scoress         r(   _compute_stability_scorer9   9   s     
#99	:??%++?VZZ[]ejepepZq  (>>?DDRu{{D[__`bjojuju_vF$-r'   c                 .   [         R                  " U 5      S:X  a2  [         R                  " / U R                  SS QSP7SU R                  06$ U R                  nUSS u  p#[         R
                  " U SS9u  pEU[         R                  " X$R                  S9SSS24   -  n[         R
                  " USS9u  puXbU) -  -   n[         R                  " USS9u  p[         R
                  " U SS9u  pU	[         R                  " X9R                  S9SSS24   -  n
[         R
                  " U
SS9u  pXU	) -  -   n
[         R                  " U
SS9u  pX:  Xx:  -  n[         R                  " XX/SS9nX) R                  S5      -  nUR                  " / USS QSP76 nU$ )	a   
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=   )r3   numelzerosshaper=   maxarangeminstack	unsqueezereshape)r*   rC   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_boxrW   D   s   " {{5Q{{EEKK,EaEEE KKE"#JMF 99U+LI 5<<?O?O#PQUWXQX#YYii 0b9OL'YJ*??99-26LI ))Er*KHeOO!LTSTW!UUOYYB7NK%((;;OIIo26MJ  ,1IJL
++zkHb
QC
))"-
-C ++
%uSbz
%1
%CJr'   c                 N   [         R                  " U[         R                  U R                  S9n[         R                  " U[         R                  U R                  S9nUu  pg  n[         R                  " XgXg//U R                  S9n	[        U R                  5      S:X  a  U	R                  S5      n	X	-   R                  5       n [         R                  " XSSS24   USS9n
[         R                  " XSSS24   USS9n[         R                  " X) 5      n
[         R                  " U
SS9$ )	zNFilter masks at the edge of a crop, but not at the edge of the original image.r1   r=   r@   r	      Nr   )atolrtolr>   )r3   	as_tensorfloatr=   tensorlenrC   rH   iscloselogical_andany)boxescrop_boxorig_boxr[   crop_box_torchorig_box_torchlefttoprM   offsetnear_crop_edgenear_image_edges               r(   _is_box_near_crop_edgern   u   s    __XU[[VN__XU[[VNODq!\\Dt125<<HF
5;;1!!!$^""$E]]5q*ASTUNmmE$'+BTUVO&&~7GHN99^++r'   re   orig_height
orig_widthc                     Uu  pEpgUS:X  a  US:X  a  Xc:X  a  Xr:X  a  U $ X6U-
  -
  X'U-
  -
  pXHU-
  XYU-
  4n
[         R                  R                  R                  X
SS9$ )Nr   )value)r3   nn
functionalpad)r*   re   ro   rp   ri   rj   rightbottompad_xpad_yru   s              r(   
_pad_masksrz      so    'DuqySAX%"5&:O.|0L5sCK
0C88""5Q"77r'   target_sizecrop_n_layersoverlap_ratiopoints_per_cropcrop_n_points_downscale_factorreturnc                 n   [        U [        5      (       a  [        S5      eU R                  SS n/ n[	        US-   5       H-  n[        XEU-  -  5      n	UR                  [        U	5      5        M/     [        X#U5      u  p[        XX{X5      u  p[        R                  " U
5      n
U
R                  5       n
[        R                  " U5      nUR                  S5      R                  SSSS5      n[        R                  " U5      n[        R                   " USS2SS2SS2S4   [        R"                  S9nXX4$ )	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 sam2ple per crop.
    crop_n_points_downscale_factor (`int`, *optional*):
        The number of points-per-side sam2pled in layer n is scaled down by crop_n_points_downscale_factor**n.
z.Only one image is allowed for crop generation.r;   NrZ   r      r	   r0   )
isinstancelist
ValueErrorrC   ranger$   append_build_point_grid_generate_per_layer_crops_generate_crop_imagesr3   r_   r^   rG   rH   permute	ones_likeint64)imager{   r|   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      s   8 %IJJKK$MK=1$%!*KLM,X67 & 7}UbcJ*?;K+'N j)J!!#Jkk"56O%//2::1aAFO[[0N???1aA:#>ekkRLDDr'   c           	         / / pCUu  pV[        XV5      nUR                  SSXe/5        UR                  S5        [        U 5       GH  nSUS-   -  n	[        X-  SU	-  -  5      n
[        [        R
                  " XS-
  -  U-   U	-  5      5      n[        [        R
                  " XS-
  -  U-   U	-  5      5      n[        U	5       Vs/ s H  n[        X-
  U-  5      PM     nn[        U	5       Vs/ s H  n[        X-
  U-  5      PM     nn[        X5       HK  u  nnUU[        UU-   U5      [        UU-   U5      /nUR                  U5        UR                  US-   5        MM     GM"     X44$ s  snf s  snf )aU  
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   rZ   )rF   r   r   r$   mathceilr   )r|   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_y0ri   rj   boxs                      r(   r   r      s     
'IY)J q!X12a'1-m0A8H4HIJG!/C$Dx$OSc#cde
$))W10D%E	%QUe$efg@EFV@WX@W1sJ0A56@WXAFGWAXYAXAsK1Q67AXY :ID#c$"3X>C+DUW`@abCc"gk* ; ( !! YYs   E*,E/
n_per_sidec                    SSU -  -  n[         R                  " USU-
  U 5      n[         R                  " USSS24   U S45      n[         R                  " USS2S4   SU 45      n[         R                  " X4/SS9R	                  SS5      nU$ )z;Generates a 2D grid of points evenly spaced in [0,1]x[0,1].rZ   r   Nr/   r>   )r3   linspacetilerG   rI   )r   rk   points_one_sidepoints_xpoints_ypointss         r(   r   r      s    !j.!FnnVQZDOzz/$'2ZODHzz/!T'2Q
ODH[[(-26>>r1EFMr'   c                 N   / n/ n[        U 5       H  u  pU
u  ppUSS2X2X24   nUR                  U5        UR                  SS n[        R                  " U5      R                  SS9R                  S5      nX#U	      U-  n[        UUU5      nUR                  U5        M     Xx4$ )z
Takes as an input bounding boxes that are used to crop the image. Based in the crops, the corresponding points are
also passed.
Nr;   )r   )dimsr   )	enumerater   rC   r3   r_   fliprH   _normalize_coordinates)r   r   r   r   r{   r   input_data_formatr   total_points_per_cropr   re   ri   rj   rv   rw   
cropped_imcropped_im_sizepoints_scaler   normalized_pointss                       r(   r   r      s     N ,#+ 51cj$*45
j)$**23/||O499t9DNNqQ]+l:2;V$$%67 - 00r'   coordsr   c                 B   Uu  pEU S-  [        XE5      -  nXF-  XV-  p[        US-   5      n[        US-   5      n[        U5      R                  5       nU(       a  UR	                  SSS5      nUS   X-  -  US'   US   Xt-  -  US'   U(       a  UR	                  SS5      nU$ )zw
Expects a numpy array of length 2 in the final dimension. Requires the original image size in (height, width)
format.
g      ?g      ?r/   r   ).r   ).rZ   r<   )rD   r$   r   r^   rI   )	r{   r   r   is_bounding_box
old_height	old_widthscale
new_height	new_widths	            r(   r   r     s     *J#J ::E&.	0A	IO$IZ#%&Jf##%FAq)F^y'<=F6NF^z'>?F6NA&Mr'   rlec                     U S   u  p[         R                  " X-  [        S9nSnSnU S    H  nXSXDU-   & XF-  nU(       + nM     UR                  X!5      nUR	                  SS5      $ )z/Compute a binary mask from an uncompressed RLE.sizer0   r   FcountsrZ   )r3   emptyboolrI   	transpose)r   rJ   rK   maskidxparitycounts          r(   _rle_to_maskr   '  sr    KMF;;v~T2D
CFX"(S;  <<&D>>!Qr'   c                    [        UR                  5       U[        R                  " UR                  S   5      US9nX   nU Vs/ s H  oPU   PM	     n nX$   nU  Vs/ s H  n[        U5      PM     nnXqX4$ s  snf s  snf )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   )rd   scoresidxsiou_threshold)r   r^   r3   rB   rC   r   )	rle_masks
iou_scores
mask_boxesamg_crops_nms_threshkeep_by_nmsr   r   r*   s           r(   !_post_process_for_mask_generationr   5  s      [[))!,-*	K (J'23{!1{I3(J*34)3\#)E4i33	 44s   A7A<c                 ~   U R                   u  pnU R                  SSS5      R                  S5      n U SS2SS24   U SS2SS24   -  nUR                  5       n/ n[	        U5       H  nXUSS2S4   U:H  S4   S-   n[        U5      S:X  a>  XS4   S:X  a  UR                  X#/X#-  /S.5        OUR                  X#/SX#-  /S.5        Mc  USS USS -
  n	XS4   S:X  a  / OS/n
XS   R                  5       /U	R                  5       -   X#-  US   R                  5       -
  /-   -  n
UR                  X#/U
S.5        M     U$ )zV
Encodes masks the run-length encoding (RLE), in the format expected by pycoco tools.
r   r   rZ   Nr/   )r   r   )	rC   r   flattennonzeror   r`   r   itemtolist)
input_mask
batch_sizerJ   rK   diffchange_indicesrV   r   cur_idxsbtw_idxsr   s              r(   _mask_to_rler   R  sr   
 !+ 0 0J##Aq!,44Q7J aez!SbS&11D\\^N C:!A"6!";Q">?!Cx=A Q$1$

VO?OPQ

VO6>?RSTAB<(3B-/!Q$'1,1#A;##%&)::fnxXZ|O`O`Ob>b=ccc

VOv>?  Jr'   c                     ^  \ rS rSr\r\R                  r\	r
\rSSS.rSSS.rSrSrSrSrSrSrSrS\\   4U 4S jjr\ S$S	\S
\S-  S\\   S\4U 4S jjj5       r S$S\S-  S\4U 4S jjjr S$S	\S
\S-  S\S\ S\!\"S4   S-  S\\   S\4S jjr#S	\$S   S\"\%-  S-  SS4U 4S jjr&     S%SSS\'S\(S\'S-  S\$\'   S-  S\)S   4S jjr*    S&S jr+     S'S jr,S  r-S!\.R^                  S\.R^                  4S" jr0S#r1U =r2$ )(Sam2ImageProcessoriq  i   )rJ   rK      TNkwargsc                 &   > [         TU ]  " S0 UD6  g )Nr   )super__init__)selfr   	__class__s     r(   r   Sam2ImageProcessor.__init__  s    "6"r'   imagessegmentation_mapsr   c                 &   > [         TU ]  " X40 UD6$ )zX
segmentation_maps (`ImageInput`, *optional*):
    The segmentation maps to preprocess.
)r   
preprocess)r   r   r   r   r   s       r(   r   Sam2ImageProcessor.preprocess  s     w!&FvFFr'   r   c           	         > Ub(  [        U[        5      (       d  [        S0 [        USS9D6nXS'   [        TU ]  " S0 UD6$ )zD
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   &Sam2ImageProcessor._standardize_kwargs  sF      Ix)H)H T={#STI'{w*4V44r'   do_convert_rgbr   r=   ztorch.devicec                 &   U R                  XXES9nU Vs/ s H  owR                  SS PM     nnUR                  5       n	U R                  " U40 U	D6n
U
US.nUb  U R                  USS[        R
                  S9nUR                  5       nUR                  SS[        R                  UR                  S5      S	.5        U R                  " SS
U0UD6nUR                  S5      R                  [        R                  5      US'   [        XS   S9$ s  snf )z
Preprocess image-like inputs.
)r   r   r   r=   r;   N)pixel_valuesoriginal_sizesr   F)r   expected_ndimsr   r   r   )do_normalize
do_rescaleresampler   r   rZ   labelsreturn_tensors)datatensor_typer   )_prepare_image_like_inputsrC   copy_preprocessr   FIRSTupdater   NEARESTpopsqueezetor3   r   r   )r   r   r   r   r   r=   r   r   r   images_kwargsr   r  processed_segmentation_mapssegmentation_maps_kwargss                 r(   _preprocess_image_like_inputs0Sam2ImageProcessor._preprocess_image_like_inputs  s9    00L] 1 
 9??u++bc*?''@-@(,

 (*.*I*I( $"2"8"8	 +J +' (.{{}$$++$)"' 2 : :488E	 +/*:*: +2+6N+' 9@@CFFu{{SDN:J3KLL= @s   Dr+   r   c                 >   > [         TU ]  " U4SU0UD6R                  $ )Nr   )r   r  r   )r   r   r   r   r   s       r(   r  Sam2ImageProcessor._preprocess  s%     w"6S.SFS```r'   r   z+np.ndarray | PIL.Image.Image | torch.Tensorr|   r}   r~   r   c                     U R                  U5      n[        UUUUUU5      u  ppUc  [        R                  " S5      nUR	                  U5      nUR	                  U5      nU
R	                  U5      n
XX4$ )ap  
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 sam2ple from each crop.
    crop_n_points_downscale_factor (`list[int]`, *optional*, defaults to 1):
        The number of points-per-side sam2pled 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   r3   r=   r  )r   r   r{   r|   r}   r~   r   r=   r   r   r   s              r(   generate_crop_boxes&Sam2ImageProcessor.generate_crop_boxes  s    > ""5)DX*E
A
^ >\\%(F]]6*
),,V4#v.NHHr'   c	                 t   Uu  pUR                  SS5      nUR                  SS5      nUR                  S   UR                  S   :w  a  [        S5      eUR                  UR                  :w  a  UR	                  UR                  5      nUR                  S   n[
        R                  " U[
        R                  UR                  S9nUS:  a  XU:  -  nUS:  a  [        XU5      nXU:  -  nX,   nX   nX:  n[        U5      n[        XSSX/5      ) nX   nX   nX   n[        XX5      n[        U5      nXU4$ )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   rZ   z4masks and iou_scores must have the sam2e batch size.rY           )r   rC   r   r=   r  r3   onesr   r9   rW   rn   rz   r   )r   r*   r   r   cropped_box_imagepred_iou_threshstability_score_threshr,   r-   original_heightoriginal_widthr   	keep_maskr8   r   converted_boxess                   r(   filter_masksSam2ImageProcessor.filter_masks  sV   F +8'''1-
a#;;q>Z--a00STT<<:,,,#u||4J[[^
JJzELLQ	S !/%ABI "C'7Oef!8N%NOI&  &.u5+A~0W
 
	 " )45_UU#o--r'   c                    [        U[        R                  [        R                  45      (       a  UR                  5       n/ n	[        U5       H  u  p[        X   [        R                  5      (       a  [        R                  " X   5      X'   O,[        X   [        R                  5      (       d  [        S5      e[        R                  " X   USSS9nU(       a  U R                  U5      nU(       a  X:  nU	R                  U5        M     U	$ )a  
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   r3   Tensornpndarrayr   r   
from_numpy	TypeError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_masks%Sam2ImageProcessor.post_process_masksV  s    F nu||RZZ&@AA+224N ). 9A%(BJJ// ++EH5%,,77 kll !ehJfk l0$($K$KL]$^!$5$F! 12 !: r'   c                     [        XX45      $ )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_generation3Sam2ImageProcessor.post_process_for_mask_generation  s     1	ddr'   
pred_masksc           	         UR                  S5      nUS:X  a  U$ UR                  n[        R                  " USSS9n[        R                  " X#S9SS2SSS4   nXE:H  n[        R
                  " Xa[        R                  " USS95      nU$ )	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   rZ   T)r?   keepdimr@   Ng      $)rD   )r   r=   r3   argmaxrE   whereclamp)r   r?  r   r=   max_obj_indsbatch_obj_indskeeps          r(   r/  5Sam2ImageProcessor._apply_non_overlapping_constraints  s    
  __Q'
?""||JAtDj@D$PTATU- [[5;;zu3UV
r'   r   N)r   g?    rZ   N)g)\(?gffffff?r   rZ   )r  Tr  r  F)3r   r   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"  r6  r=  r3   r(  r/  r&   __classcell__)r   s   @r(   r   r   q  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 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\\ ell  r'   r   )r*   r+   )g      4@)r   rJ  rK  rZ   rI  )F)gffffff?)r   r+   )<r   r  r   	itertoolsr   typingr   r   r   numpyr)  r3   torch.nn.functionalrs   rt   r-  torchvision.ops.boxesr   image_processing_backendsr
   image_processing_utilsr   r   image_utilsr   r   r   r   r   r   processing_utilsr   r   utilsr   r   r   PILr   r^   r$   r9   rW   rn   r   rz   tupler   r   r(  r   r   r   r"   r#   r   r   r   r   __all__r   r'   r(   <module>rb     s  (    ' '     - ; A  5 D D |5 N E cf .b,$8S	 8 8 8 %"$782E2E 2E 	2E
 4Z2E %)I$42E 4S	?DI%&2Ej"D# %,,  _c14 ]b#ll;@c?
\\8 d38n    4:> {+ { {|	  
 r'   