
    S^(h                        d dl mZ d dlmZmZ d dlmZmZmZm	Z	 d dl
ZddlmZmZmZ ddlmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZm Z m!Z! dd	l"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+  e*       rddlm,Z,  e'       rd dl-Z- e(       rddlm.Z.  e)       rd dl/m0Z1 nd dl2m0Z1  e+jf                  e4      Z5 ed      dddddddddddddejl                  fdee7   dee8   dee7   dee	e8e9e8   f      dee	e8e9e8   f      dee7   dee:   dee7   dee   dee7   dee   ded   dee	e;e%f      dee   fd       Z<d7d d!d"ee:   d#d!fd$Z=d%ee   d#e9e   fd&Z>d'e9d!   d#e?e:   fd(Z@d)e	ej                  d!f   d*e:d#e9e	ej                  d!f      fd+ZB G d, d-ed./      ZCd0ZDd1ZE e&d2eD       G d3 d4e             ZF G d5 d6      ZGy)8    )Iterable)	lru_cachepartial)AnyOptional	TypedDictUnionN   )BaseImageProcessorBatchFeatureget_size_dict)convert_to_rgbget_resize_output_image_sizeget_size_with_aspect_ratiogroup_images_by_shapereorder_images)ChannelDimension
ImageInput	ImageTypeSizeDictget_image_size#get_image_size_for_max_height_widthget_image_typeinfer_channel_dimension_formatmake_flat_list_of_imagesvalidate_kwargsvalidate_preprocess_arguments)Unpack)
TensorTypeadd_start_docstringsis_torch_availableis_torchvision_availableis_torchvision_v2_availableis_vision_availablelogging)PILImageResampling)pil_torch_interpolation_mapping)
functional
   maxsize
do_rescalerescale_factordo_normalize
image_mean	image_stddo_padsize_divisibilitydo_center_crop	crop_size	do_resizesizeresampler&   return_tensorsdata_formatc                     t        | |||||||||	|
|       ||dk7  rt        d      |t        j                  k7  rt        d      y)z
    Checks validity of typically used arguments in an `ImageProcessorFast` `preprocess` method.
    Raises `ValueError` if arguments incompatibility is caught.
    )r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   Nptz6Only returning PyTorch tensors is currently supported.z6Only channel first data format is currently supported.)r   
ValueErrorr   FIRST)r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   s                 f/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/image_processing_utils_fast.py"validate_fast_preprocess_argumentsr?   K   sk    * "%!+% !n&<QRR&,,,QRR -    tensortorch.Tensoraxisreturnc                 n    || j                         S 	 | j                  |      S # t        $ r | cY S w xY w)zF
    Squeezes a tensor, but only if the axis specified has dim 1.
    )rC   )squeezer<   )rA   rC   s     r>   safe_squeezerG   v   s@     |~~~~4~(( s   & 44valuesc                 J    t        |  D cg c]  }t        |       c}S c c}w )zO
    Return the maximum value across all indices of an iterable of values.
    )zipmax)rH   values_is     r>   max_across_indicesrM      s      +.v,7hCM777s    imagesc                 b    t        | D cg c]  }|j                   c}      \  }}}||fS c c}w )zH
    Get the maximum height and width across all images in a batch.
    )rM   shape)rN   img_
max_height	max_widths        r>   get_max_height_widthrU      s5    
  22O3992OPAz9	"" 3Ps   ,image
patch_sizec                     g }t        | t        j                        \  }}t        d||      D ]9  }t        d||      D ]'  }| dd|||z   |||z   f   }|j	                  |       ) ; |S )a6  
    Divides an image into patches of a specified size.

    Args:
        image (`Union[np.array, "torch.Tensor"]`):
            The input image.
        patch_size (`int`):
            The size of each patch.
    Returns:
        list: A list of Union[np.array, "torch.Tensor"] representing the patches.
    )channel_dimr   N)r   r   r=   rangeappend)rV   rW   patchesheightwidthijpatchs           r>   divide_to_patchesrb      s     G"56F6L6LMMFE1fj) "q%, 	"A!QZ/Q^1CCDENN5!	""
 Nr@   c                   f   e Zd ZU ee   ed<   eeeef      ed<   ee   ed<   ee	d      ed<   ee   ed<   eeeef      ed<   ee   ed<   ee	ee
f      ed	<   ee   ed
<   ee	e
ee
   f      ed<   ee	e
ee
   f      ed<   ee   ed<   ee	eef      ed<   ee   ed<   ee	eef      ed<   ed   ed<   y)DefaultFastImageProcessorKwargsr5   r6   default_to_squarer&   F.InterpolationModer7   r3   r4   r,   r-   r.   r/   r0   do_convert_rgbr8   r9   input_data_formattorch.devicedeviceN)__name__
__module____qualname__r   bool__annotations__dictstrintr	   floatlistr   r    r@   r>   rd   rd      s    ~
4S>
""~%uHIJJTN"S#X''U3:.//4. ud5k1233eT%[0122TN"U3
?344*++c+;&; <==^$$r@   rd   F)totala  

    Args:
        do_resize (`bool`, *optional*, defaults to `self.do_resize`):
            Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by the
            `do_resize` parameter in the `preprocess` method.
        size (`dict`, *optional*, defaults to `self.size`):
            Size of the output image after resizing. Can be overridden by the `size` parameter in the `preprocess`
            method.
        default_to_square (`bool`, *optional*, defaults to `self.default_to_square`):
            Whether to default to a square image when resizing, if size is an int.
        resample (`PILImageResampling`, *optional*, defaults to `self.resample`):
            Resampling filter to use if resizing the image. Only has an effect if `do_resize` is set to `True`. Can be
            overridden by the `resample` parameter in the `preprocess` method.
        do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`):
            Whether to center crop the image to the specified `crop_size`. Can be overridden by `do_center_crop` in the
            `preprocess` method.
        crop_size (`Dict[str, int]` *optional*, defaults to `self.crop_size`):
            Size of the output image after applying `center_crop`. Can be overridden by `crop_size` in the `preprocess`
            method.
        do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
            Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the
            `do_rescale` parameter in the `preprocess` method.
        rescale_factor (`int` or `float`, *optional*, defaults to `self.rescale_factor`):
            Scale factor to use if rescaling the image. Only has an effect if `do_rescale` is set to `True`. Can be
            overridden by the `rescale_factor` parameter in the `preprocess` method.
        do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
            Whether to normalize the image. Can be overridden by the `do_normalize` parameter in the `preprocess`
            method. Can be overridden by the `do_normalize` parameter in the `preprocess` method.
        image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
            Mean to use if normalizing the image. This is a float or list of floats the length of the number of
            channels in the image. Can be overridden by the `image_mean` parameter in the `preprocess` method. Can be
            overridden by the `image_mean` parameter in the `preprocess` method.
        image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
            Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
            number of channels in the image. Can be overridden by the `image_std` parameter in the `preprocess` method.
            Can be overridden by the `image_std` parameter in the `preprocess` method.
        do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
            Whether to convert the image to RGB.
        return_tensors (`str` or `TensorType`, *optional*, defaults to `self.return_tensors`):
            Returns stacked tensors if set to `pt, otherwise returns a list of tensors.
        data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.data_format`):
            Only `ChannelDimension.FIRST` is supported. Added for compatibility with slow processors.
        input_data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.input_data_format`):
            The channel dimension format for the input image. If unset, the channel dimension format is inferred
            from the input image. Can be one of:
            - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
            - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
        device (`torch.device`, *optional*, defaults to `self.device`):
            The device to process the images on. If unset, the device is inferred from the input images.aQ  
    Preprocess an image or batch of images.

    Args:
        images (`ImageInput`):
            Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
            passing in images with pixel values between 0 and 1, set `do_rescale=False`.
        do_resize (`bool`, *optional*, defaults to `self.do_resize`):
            Whether to resize the image.
        size (`Dict[str, int]`, *optional*, defaults to `self.size`):
            Describes the maximum input dimensions to the model.
        resample (`PILImageResampling` or `InterpolationMode`, *optional*, defaults to `self.resample`):
            Resampling filter to use if resizing the image. This can be one of the enum `PILImageResampling`. Only
            has an effect if `do_resize` is set to `True`.
        do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`):
            Whether to center crop the image.
        crop_size (`Dict[str, int]`, *optional*, defaults to `self.crop_size`):
            Size of the output image after applying `center_crop`.
        do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
            Whether to rescale the image.
        rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
            Rescale factor to rescale the image by if `do_rescale` is set to `True`.
        do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
            Whether to normalize the image.
        image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
            Image mean to use for normalization. Only has an effect if `do_normalize` is set to `True`.
        image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
            Image standard deviation to use for normalization. Only has an effect if `do_normalize` is set to
            `True`.
        do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
            Whether to convert the image to RGB.
        return_tensors (`str` or `TensorType`, *optional*, defaults to `self.return_tensors`):
            Returns stacked tensors if set to `pt, otherwise returns a list of tensors.
        data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.data_format`):
            Only `ChannelDimension.FIRST` is supported. Added for compatibility with slow processors.
        input_data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.input_data_format`):
            The channel dimension format for the input image. If unset, the channel dimension format is inferred
            from the input image. Can be one of:
            - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
            - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
        device (`torch.device`, *optional*, defaults to `self.device`):
            The device to process the images on. If unset, the device is inferred from the input images.z'Constructs a fast base image processor.c                       e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZej"                  ZdZdZdgZeZdZdee   ddf fdZ	 	 d5dd	d
edddedd	f
dZdd	dedd	fdZdd	de ee!e   f   de ee!e   f   dd	fdZ" e#d      	 	 	 	 	 	 d6de$e   de$e ee%e   f      de$e ee%e   f      de$e   de$e   de$d   de&fd       Z'dd	dededede ee%e   f   de ee%e   f   dd	fdZ(dd	d
e)e*e+f   dd	fd Z,de-de-fd!Z.de)fd"Z/de-de-fd#Z0	 	 	 d7de-d$e$e   d%e$e e*ef      de$d   dd	f
d&Z1	 	 	 d7de-d$e$e   d%e$e e*ef      de$d   de%d	   f
d'Z2	 	 	 	 	 	 d6d
e$e   d(e$e   d)e$e   de$e ee%e   f      de$e ee%e   f      d*e$e   de)fd+Z3	 	 	 	 	 	 	 	 	 	 	 	 d8de$e   de$e   de$e   de$e ee&e   f      de$e ee&e   f      d,e$e   d
e$e   d-e$e   d(e$e   d.e$e d/      d0e$e e*e4f      d*e$e   fd1Z5 e6e7      de-dee   de8fd2       Z9de%d	   d,ed
ede$d   d-ed(edededede$e ee%e   f      de$e ee%e   f      d0e$e e*e4f      de8fd3Z: fd4Z; xZ<S )9BaseImageProcessorFastNTgp?pixel_valueskwargsrD   c           
         t        |   di | | j                  |      }|j                  d| j                        }|'t        ||j                  d| j                              nd | _        |j                  d| j                        }|t        |d      nd | _        | j                  j                  j                         D ]<  }|j                  |d       }|t        | ||       %t        | |t        | |d              > y )Nr6   re   r6   re   r4   
param_namerv   )super__init__filter_out_unused_kwargspopr6   r   re   r4   valid_kwargsrp   keyssetattrgetattr)selfr{   r6   r4   keykwarg	__class__s         r>   r   zBaseImageProcessorFast.__init__9  s     	"6"..v6zz&$)),  tvzzBUW[WmWm7no 		
 JJ{DNN;	MVMby[Ihl$$4499; 	=CJJsD)E c5)c74d#;<	=r@   rV   rB   r6   interpolationrg   	antialiasc                    ||nt         j                  j                  }|j                  r?|j                  r3t        |j                         dd |j                  |j                        }n|j                  r(t        ||j                  dt        j                        }n|j                  r?|j                  r3t        |j                         dd |j                  |j                        }n@|j                  r%|j                  r|j                  |j                  f}nt        d| d      t        j                   ||||      S )a;  
        Resize an image to `(size["height"], size["width"])`.

        Args:
            image (`torch.Tensor`):
                Image to resize.
            size (`SizeDict`):
                Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
            resample (`InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`):
                `InterpolationMode` filter to use when resizing the image e.g. `InterpolationMode.BICUBIC`.

        Returns:
            `torch.Tensor`: The resized image.
        NF)r6   re   ri   zjSize must contain 'height' and 'width' keys, or 'max_height' and 'max_width', or 'shortest_edge' key. Got .)r   r   )FInterpolationModeBILINEARshortest_edgelongest_edger   r6   r   r   r=   rS   rT   r   r]   r^   r<   resize)r   rV   r6   r   r   r{   new_sizes          r>   r   zBaseImageProcessorFast.resizeN  s   , *7)BH[H[HdHd$"3"3 2

RS!""!!H
 3''"'"2"8"8	H __:5::<;Ldoo_c_m_mnH[[TZZTZZ0H6  xxx}PYZZr@   scalec                     ||z  S )a?  
        Rescale an image by a scale factor. image = image * scale.

        Args:
            image (`torch.Tensor`):
                Image to rescale.
            scale (`float`):
                The scaling factor to rescale pixel values by.

        Returns:
            `torch.Tensor`: The rescaled image.
        rv   )r   rV   r   r{   s       r>   rescalezBaseImageProcessorFast.rescale  s    $ u}r@   meanstdc                 0    t        j                  |||      S )a  
        Normalize an image. image = (image - image_mean) / image_std.

        Args:
            image (`torch.Tensor`):
                Image to normalize.
            mean (`torch.Tensor`, `float` or `Iterable[float]`):
                Image mean to use for normalization.
            std (`torch.Tensor`, `float` or `Iterable[float]`):
                Image standard deviation to use for normalization.

        Returns:
            `torch.Tensor`: The normalized image.
        )r   	normalize)r   rV   r   r   r{   s        r>   r   z BaseImageProcessorFast.normalize  s    * {{5$,,r@   r)   r*   r.   r/   r0   r,   r-   rk   rj   c                     |r>|r<t        j                  ||      d|z  z  }t        j                  ||      d|z  z  }d}|||fS )N)rk   g      ?F)torchrA   )r   r.   r/   r0   r,   r-   rk   s          r>   !_fuse_mean_std_and_rescale_factorz8BaseImageProcessorFast._fuse_mean_std_and_rescale_factor  sO     ,j@C.DXYJYv>#BVWIJ9j00r@   rN   c                     | j                  ||||||j                        \  }}}|r3| j                  |j                  t        j
                        ||      }|S |r| j                  ||      }|S )z/
        Rescale and normalize images.
        )r.   r/   r0   r,   r-   rk   )dtype)r   rk   r   tor   float32r   )r   rN   r,   r-   r.   r/   r0   s          r>   rescale_and_normalizez,BaseImageProcessorFast.rescale_and_normalize  s     -1,R,R%!!)== -S -
)
Iz ^^FIIEMMI$BJPYZF  \\&.9Fr@   c                     |j                   |j                  t        d|j                                t	        j
                  ||d   |d   f      S )a  
        Center crop an image to `(size["height"], size["width"])`. If the input size is smaller than `crop_size` along
        any edge, the image is padded with 0's and then center cropped.

        Args:
            image (`"torch.Tensor"`):
                Image to center crop.
            size (`Dict[str, int]`):
                Size of the output image.

        Returns:
            `torch.Tensor`: The center cropped image.
        z=The size dictionary must have keys 'height' and 'width'. Got r]   r^   )r]   r^   r<   r   r   center_crop)r   rV   r6   r{   s       r>   r   z"BaseImageProcessorFast.center_crop  sS    & ;;$**"4\]a]f]f]h\ijkk}}UT(^T']$CDDr@   c                     t        |      S )a'  
        Converts an image to RGB format. Only converts if the image is of type PIL.Image.Image, otherwise returns the image
        as is.
        Args:
            image (ImageInput):
                The image to convert.

        Returns:
            ImageInput: The converted image.
        )r   )r   rV   s     r>   r   z%BaseImageProcessorFast.convert_to_rgb  s     e$$r@   c                     | j                   |S | j                   D ]1  }||v st        j                  d| d       |j                  |       3 |S )zJ
        Filter out the unused kwargs from the kwargs dictionary.
        z!This processor does not use the `z ` parameter. It will be ignored.)unused_kwargsloggerwarning_oncer   )r   r{   
kwarg_names      r>   r   z/BaseImageProcessorFast.filter_out_unused_kwargs  s^     %M,, 	'JV###&G
|Ss$tu

:&	' r@   c                     t        |      S )z
        Prepare the images structure for processing.

        Args:
            images (`ImageInput`):
                The input images to process.

        Returns:
            `ImageInput`: The images with a valid nesting.
        )r   )r   rN   s     r>   _prepare_images_structurez0BaseImageProcessorFast._prepare_images_structure  s     (//r@   rh   ri   c                 &   t        |      }|t        j                  t        j                  t        j                  fvrt        d|       |r| j                  |      }|t        j                  k(  rt        j                  |      }n6|t        j                  k(  r#t        j                  |      j                         }|t        |      }|t        j                  k(  r!|j                  ddd      j                         }||j!                  |      }|S )NzUnsupported input image type    r   r
   )r   r   PILTORCHNUMPYr<   r   r   pil_to_tensorr   
from_numpy
contiguousr   r   LASTpermuter   )r   rV   rh   ri   rk   
image_types         r>   _process_imagez%BaseImageProcessorFast._process_image  s     $E*
immY__iooNN<ZLIJJ''.E&OOE*E9??*$$U+668E $ >u E 0 5 55MM!Q*557E HHV$Er@   c                     | j                  |      }t        | j                  |||      }g }|D ]  }|j                   ||              |S )z:
        Prepare the input images for processing.
        )rh   ri   rk   )r   r   r   r[   )r   rN   rh   ri   rk   process_image_fnprocessed_imagesrV   s           r>   _prepare_input_imagesz,BaseImageProcessorFast._prepare_input_images=  sd     //7")/	
  	=E##$4U$;<	=  r@   r4   re   r9   c                 :   |i }|t        d	i t        ||      }|t        d	i t        |d      }t        |t              rt	        |      }t        |t              rt	        |      }|t
        j                  }||d<   ||d<   ||d<   ||d<   ||d<   ||d<   |S )
z
        Update kwargs that need further processing before being validated
        Can be overridden by subclasses to customize the processing of kwargs.
        r}   r4   r~   r6   re   r/   r0   r9   rv   )r   r   
isinstanceru   tupler   r=   )r   r6   r4   re   r/   r0   r9   r{   s           r>   _further_process_kwargsz.BaseImageProcessorFast._further_process_kwargsU  s     >F\mIZ[\D  T={#STIj$'z*Ji&i(I*00Kv'{&7"#)|'{ +}r@   r5   r3   r7   rf   r8   c                 2    t        |||||||||	|
||       y)z@
        validate the kwargs for the preprocess method.
        )r,   r-   r.   r/   r0   r5   r6   r3   r4   r7   r8   r9   N)r?   )r   r,   r-   r.   r/   r0   r5   r6   r3   r4   r7   r8   r9   r{   s                 r>   _validate_preprocess_kwargsz2BaseImageProcessorFast._validate_preprocess_kwargsy  s0    & 	+!)%!))#	
r@   c           	         t        |j                         | j                  j                  j                                | j                  j                  D ]  }|j	                  |t        | |d              ! |j                  d      }|j                  d      }|j                  d      }| j                  ||||      } | j                  di |} | j                  di | |j                  d      }t        |t        t        f      r	t        |   n||d<   |j                  d       |j                  d	        | j                  dd
|i|S )N)captured_kwargsvalid_processor_keysrh   ri   rk   )rN   rh   ri   rk   r7   r   re   r9   rN   rv   )r   r   r   rp   
setdefaultr   r   r   r   r   r   r&   rs   r'   _preprocess)r   rN   r{   r   rh   ri   rk   r7   s           r>   
preprocessz!BaseImageProcessorFast.preprocess  sF   DL]L]LmLmLrLrLtu ++;; 	KJj'$
D*IJ	K  $45"JJ':;H%++.L]fl , 

 .--77 	)((262 ::j)9CHOacfNg9h+H5nv 	
 	

&'

=!t8v888r@   c           	         t        |      \  }}i }|j                         D ]   \  }}|r| j                  |||      }|||<   " t        ||      }t        |      \  }}i }|j                         D ]4  \  }}|r| j	                  ||      }| j                  ||||	|
|      }|||<   6 t        ||      }|rt        j                  |d      n|}t        d|i|      S )N)rV   r6   r   r   dimrz   )datatensor_type)	r   itemsr   r   r   r   r   stackr   )r   rN   r5   r6   r   r3   r4   r,   r-   r.   r/   r0   r8   r{   grouped_imagesgrouped_images_indexresized_images_groupedrP   stacked_imagesresized_imagesprocessed_images_groupedr   s                         r>   r   z"BaseImageProcessorFast._preprocess  s   " 0EV/L,,!#%3%9%9%; 	;!E>!%>\i!j,:"5)	; ((>@TU 0E^/T,,#% %3%9%9%; 	=!E>!%!1!1.)!L!77
NL*V_N /=$U+	= **BDXYCQ5;;'7Q?Wg.2B!CQ_``r@   c                 H    t         |          }|j                  dd        |S )N_valid_processor_keys)r   to_dictr   )r   encoder_dictr   s     r>   r   zBaseImageProcessorFast.to_dict  s&    w(0$7r@   )NT)NNNNNN)NNN)NNNNNNNNNNNN)=rl   rm   rn   r7   r/   r0   r6   re   r4   r5   r3   r,   r-   r.   rh   r8   r   r=   r9   ri   rk   model_input_namesrd   r   r   r   r   r   ro   r   rt   r   r	   r   r   r   r   ru   r   r   r   rq   rr   rs   r   r   r   r   r   r   r   r   r   r   r    .BASE_IMAGE_PROCESSOR_FAST_DOCSTRING_PREPROCESSr   r   r   r   __classcell__)r   s   @r>   ry   ry      s   
 HJIDIINJNLNN"((KF'(2LM=89= 
=2 04/[/[ /[ -	/[
 /[ 
/[b 
 
(-- E8E?*+- 5(5/)*	- 
-. r (,:>9=%)*.+/1tn1 U5$u+#5671 E%e"456	1
 TN1 !1 (1 
1 1   	
  %e,- U+, 
8EE 38nE
 
E.%% 
% t 00 
0& *.DH+/   !  $E#/?*?$@A	 
 (  
 J *.DH+/   !  $E#/?*?$@A	 
 (  
n	 4 $((,,0:>9=26"x " H%" $D>	"
 U5$u+#567" E%e"456" ./" 
"L &**.'+;?:>$(#')-(,QU;?26 
TN 
 ! 
 tn	 

 U5%,#678 
 E%u"567 
 D> 
 x  
 ! 
 H% 
 5!LMN 
 !sJ!78 
 ./ 
D HI 9  9v>]7^  9co  9 J 9D)a^$)a )a 	)a
   56)a )a )a )a )a )a U5$u+#567)a E%e"456)a !sJ!78)a 
)aV r@   ry   c                        e Zd Zddee   fdZy)SemanticSegmentationMixinNtarget_sizesc                    |j                   }|t        |      t        |      k7  rt        d      g }t        t        |            D ]k  }t        j
                  j                  j                  ||   j                  d      ||   dd      }|d   j                  d      }|j                  |       m |S |j                  d      }t        |j                  d         D cg c]  }||   	 }}|S c c}w )aD  
        Converts the output of [`MobileNetV2ForSemanticSegmentation`] into semantic segmentation maps. Only supports PyTorch.

        Args:
            outputs ([`MobileNetV2ForSemanticSegmentation`]):
                Raw outputs of the model.
            target_sizes (`List[Tuple]` 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.

        Returns:
            semantic_segmentation: `List[torch.Tensor]` of length `batch_size`, where each item is a semantic
            segmentation map of shape (height, width) corresponding to the target_sizes entry (if `target_sizes` is
            specified). Each entry of each `torch.Tensor` correspond to a semantic class id.
        zTMake sure that you pass in as many target sizes as the batch dimension of the logitsr   r   bilinearF)r6   modealign_cornersr
   )logitslenr<   rZ   r   nnr(   interpolate	unsqueezeargmaxr[   rP   )	r   outputsr   r   semantic_segmentationidxresized_logitssemantic_mapr_   s	            r>   "post_process_semantic_segmentationz<SemanticSegmentationMixin.post_process_semantic_segmentation  s      #6{c,// j  %'!S[) ;!&!4!4!@!@3K))a)0|C7Hzin "A "  .a077A7>%,,\:; %$ %+MMaM$8!GLMbMhMhijMkGl$m!%:1%=$m!$m$$ %ns   #C3N)rl   rm   rn   ru   r   r   rv   r@   r>   r   r     s    (%U (%r@   r   r   )Hcollections.abcr   	functoolsr   r   typingr   r   r   r	   numpynpimage_processing_utilsr   r   r   image_transformsr   r   r   r   r   image_utilsr   r   r   r   r   r   r   r   r   r   r   processing_utilsr   utilsr   r    r!   r"   r#   r$   r%   r&   r   r'   torchvision.transforms.v2r(   r   torchvision.transforms
get_loggerrl   r   r=   ro   rt   ru   rs   rr   r?   rG   rM   r   rU   arrayrb   rd   #BASE_IMAGE_PROCESSOR_FAST_DOCSTRINGr   ry   r   rv   r@   r>   <module>r     s   % ( 2 2  
     %   /<"$=:			H	% 2!%&*#'6:59!'+%)$( $#/37;.>.D.D'S'SUO'S 4.'S ud5k123	'S
 eT%[012'S TN'S  }'S TN'S !'S ~'S 8
'S +,'S U3
?34'S *+'S 'ST
 
x} 
 
8x} 8c 8#n!5 #%* #>)*8;	%.(
)*0%iu %&2'l #h*2l .Z -'H/ H	HV)% )%r@   