Ë
    T^(h'{  ã            	       ó‚  — d Z ddlmZ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 ddl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mZmZmZm Z   e«       rddl!Z! e«       r	  ejD                  e#«      Z$d	e%d
eee%e%f      fd„Z&	 ddejN                  deeee%e%f         dee   d
ejN                  fd„Z( G d„ de
«      Z)dgZ*y)z!Image processor class for SegGPT.é    )ÚDictÚListÚOptionalÚTupleÚUnionNé   )ÚBaseImageProcessorÚBatchFeatureÚget_size_dict)ÚresizeÚto_channel_dimension_format)
ÚIMAGENET_DEFAULT_MEANÚIMAGENET_DEFAULT_STDÚChannelDimensionÚ
ImageInputÚPILImageResamplingÚinfer_channel_dimension_formatÚis_scaled_imageÚmake_list_of_imagesÚto_numpy_arrayÚvalid_images)Ú
TensorTypeÚis_torch_availableÚis_vision_availableÚloggingÚrequires_backendsÚ
num_labelsÚreturnc                 óà   — t        | dz  «      dz   }d|z  }dg}t        | «      D ]F  }||dz  z  }||dz  z  |z  }||z  }d||z  z
  }d||z  z
  }	d||z  z
  }
|j                  ||	|
f«       ŒH |S )NgUUUUUUÕ?é   é   )r   r   r   é   éÿ   )ÚintÚrangeÚappend)r   ÚbaseÚmarginÚ
color_listÚlocationÚ	num_seq_rÚ	num_seq_gÚ	num_seq_bÚRÚGÚBs              úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/seggpt/image_processing_seggpt.pyÚbuild_paletter2   2   s¯   € Üˆz˜eÑ$Ó%¨Ñ)€DØ�D‰[€Fð �€JÜ˜*Ó%ò 	%ˆØ  a¡Ñ'ˆ	Ø  a¡Ñ'¨DÑ0ˆ	Ø˜t‘Oˆ	à�)˜fÑ$Ñ$ˆØ�)˜fÑ$Ñ$ˆØ�)˜fÑ$Ñ$ˆà×Ñ˜1˜a ˜)Õ$ð	%ð Ðó    ÚmaskÚpaletteÚdata_formatc                 ó¬  — |�|nt         j                  }|��| j                  \  }}t        j                  d||ft        j
                  ¬«      }t        j                  | «      }|D ]‘  }||   }| |k(  j                  t        j
                  «      }	t        j                  |	d¬«      }	|	t        j                  |«      z  }
t        j                  |
dd«      }
||
j                  t        j
                  «      z  }Œ“ t        j                  |dd«      j                  t        j
                  «      }nt        j                  | d   dd¬«      }t        ||«      S )Nr   )Údtypeéÿÿÿÿ)Úaxisr   r#   )N.)r   ÚFIRSTÚshapeÚnpÚzerosÚuint8ÚuniqueÚastypeÚexpand_dimsÚarrayÚmoveaxisÚclipÚrepeatr   )r4   r5   r6   ÚheightÚwidthÚrgb_maskÚclasses_in_maskÚ	class_idxÚ	rgb_valueÚ
class_maskÚclass_rgb_masks              r1   Úmask_to_rgbrO   F   s  € ð "-Ð!8‘+Ô>N×>TÑ>T€KàÑØŸ
™
‰ˆ�ä—8‘8˜Q ¨Ð.´b·h±hÔ?ˆäŸ)™) D›/ˆà(ò 	8ˆIØ 	Ñ*ˆIØ )Ñ+×3Ñ3´B·H±HÓ=ˆJÜŸ™¨
¸Ô<ˆJØ'¬"¯(©(°9Ó*=Ñ=ˆNÜŸ[™[¨¸¸QÓ?ˆNØ˜×-Ñ-¬b¯h©hÓ7Ñ7‰Hð	8ô —7‘7˜8 Q¨Ó,×3Ñ3´B·H±HÓ=‰ô —9‘9˜T )™_¨a°aÔ8ˆä& x°Ó=Ð=r3   c            $       óü  ‡ — e Zd ZdZdgZddej                  ddddddf	dedee	e
ef      ded	ed
eeef   dedeeeee   f      deeeee   f      deddfˆ fd„Zdedeeeef      fd„Z	 	 d!dej&                  deeeeef         deee
ef      dej&                  fd„Zej                  ddfdej&                  de	e
ef   dedeee
ef      deee
ef      dej&                  fd„Zddddddddej.                  dddfdedee   de	e
ef   ded	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
ef   deee
ef      dee   dee   fd„Zddddddddddddddej.                  dfdee   dee   dee   dee   de	e
ef   ded	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e
ef      dee
ef   deee
ef      f d„Z	 d!deeeeef         dee   fd „Zˆ xZS )"ÚSegGptImageProcessoraõ  
    Constructs a SegGpt image processor.

    Args:
        do_resize (`bool`, *optional*, defaults to `True`):
            Whether to resize the image's (height, width) dimensions to the specified `(size["height"],
            size["width"])`. Can be overridden by the `do_resize` parameter in the `preprocess` method.
        size (`dict`, *optional*, defaults to `{"height": 448, "width": 448}`):
            Size of the output image after resizing. Can be overridden by the `size` parameter in the `preprocess`
            method.
        resample (`PILImageResampling`, *optional*, defaults to `Resampling.BICUBIC`):
            Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in the
            `preprocess` method.
        do_rescale (`bool`, *optional*, defaults to `True`):
            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 `1/255`):
            Scale factor to use if rescaling the image. Can be overridden by the `rescale_factor` parameter in the
            `preprocess` method.
        do_normalize (`bool`, *optional*, defaults to `True`):
            Whether to normalize the image. Can be overridden by the `do_normalize` parameter in the `preprocess`
            method.
        image_mean (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_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.
        image_std (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_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.
        do_convert_rgb (`bool`, *optional*, defaults to `True`):
            Whether to convert the prompt mask to RGB format. Can be overridden by the `do_convert_rgb` parameter in the
            `preprocess` method.
    Úpixel_valuesTNgp?Ú	do_resizeÚsizeÚresampleÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚdo_convert_rgbr   c
                 óê   •— t        ‰| �  di |
¤Ž |�|ndddœ}t        |«      }|| _        || _        || _        || _        || _        || _        |�|nt        | _
        |�|nt        | _        |	| _        y )NiÀ  )rG   rH   © )ÚsuperÚ__init__r   rS   rV   rX   rT   rU   rW   r   rY   r   rZ   r[   )ÚselfrS   rT   rU   rV   rW   rX   rY   rZ   r[   ÚkwargsÚ	__class__s              €r1   r_   zSegGptImageProcessor.__init__†   s‚   ø€ ô 	‰ÑÑ"˜6Ò"ØÐ'‰t¸ÀcÑ-JˆÜ˜TÓ"ˆØ"ˆŒØ$ˆŒØ(ˆÔØˆŒ	Ø ˆŒØ,ˆÔØ(2Ð(>™*ÔDYˆŒØ&/Ð&;™ÔAUˆŒØ,ˆÕr3   r   c                 ó   — t        |«      S )a_  Build a palette to map the prompt mask from a single channel to a 3 channel RGB.

        Args:
            num_labels (`int`):
                Number of classes in the segmentation task (excluding the background).

        Returns:
            `List[Tuple[int, int]]`: Palette to map the prompt mask from a single channel to a 3 channel RGB.
        )r2   )r`   r   s     r1   Úget_palettez SegGptImageProcessor.get_palette    s   € ô ˜ZÓ(Ð(r3   Úimager5   r6   c                 ó   — t        |||¬«      S )a¿  Converts a segmentation map to RGB format.

        Args:
            image (`np.ndarray`):
                Segmentation map with dimensions (height, width) where pixel values represent the class index.
            palette (`List[Tuple[int, int]]`, *optional*, defaults to `None`):
                Palette to use to convert the mask to RGB format. If unset, the mask is duplicated across the channel
                dimension.
            data_format (`ChannelDimension` or `str`, *optional*):
                The channel dimension format for the output image. If unset, the channel dimension format of the input
                image is used. 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.

        Returns:
            `np.ndarray`: The mask in RGB format.
        )r5   r6   )rO   )r`   re   r5   r6   s       r1   rO   z SegGptImageProcessor.mask_to_rgb¬   s   € ô. ˜5¨'¸{ÔKÐKr3   Úinput_data_formatc                 ó–   — t        |«      }d|vsd|vrt        d|j                  «       › �«      ‚|d   |d   f}t        |f||||dœ|¤ŽS )a‹  
        Resize an image to `(size["height"], size["width"])`.

        Args:
            image (`np.ndarray`):
                Image to resize.
            size (`Dict[str, int]`):
                Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
            resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
                `PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.BICUBIC`.
            data_format (`ChannelDimension` or `str`, *optional*):
                The channel dimension format for the output image. If unset, the channel dimension format of the input
                image is used. 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.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                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.

        Returns:
            `np.ndarray`: The resized image.
        rG   rH   zFThe `size` dictionary must contain the keys `height` and `width`. Got )rT   rU   r6   rg   )r   Ú
ValueErrorÚkeysr   )r`   re   rT   rU   r6   rg   ra   Úoutput_sizes           r1   r   zSegGptImageProcessor.resizeÆ   sy   € ôF ˜TÓ"ˆØ˜4Ñ 7°$Ñ#6ÜÐeÐfj×foÑfoÓfqÐerÐsÓtÐtØ˜H‘~ t¨G¡}Ð5ˆÜØð
àØØ#Ø/ñ
ð ñ
ð 	
r3   Úimagesc           	      óz  — |�|n| j                   }|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j
                  }|�|n| j                  }|	�|	n| j                  }	|�|n| j                  }t        |«      }t        ||rdnd¬«      }t        |«      st        d«      ‚|r|€t        d«      ‚|r|€t        d«      ‚|r|�|	€t        d«      ‚|D �cg c]  }t        |«      ‘Œ }}|r#t        |d	   «      rt        j!                  d
«       |€|st#        |d	   «      }|rT|�| j%                  |«      nd}|D �cg c]$  }| j'                  ||t(        j*                  ¬«      ‘Œ& }}t(        j*                  }|r"|D �cg c]  }| j-                  ||||¬«      ‘Œ }}|r!|D �cg c]  }| j/                  |||¬«      ‘Œ }}|r"|D �cg c]  }| j1                  |||	|¬«      ‘Œ }}|D �cg c]  }t3        ||
|¬«      ‘Œ }}|S c c}w c c}w c c}w c c}w c c}w c c}w )aˆ  
        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`):
                Dictionary in the format `{"height": h, "width": w}` specifying the size of the output image after
                resizing.
            resample (`PILImageResampling` filter, *optional*, defaults to `self.resample`):
                `PILImageResampling` filter to use if resizing the image e.g. `PILImageResampling.BICUBIC`. Only has
                an effect if `do_resize` is set to `True`.
            do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
                Whether to rescale the image values between [0 - 1].
            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 if `do_normalize` is set to `True`.
            image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
                Image standard deviation to use if `do_normalize` is set to `True`.
            return_tensors (`str` or `TensorType`, *optional*):
                The type of tensors to return. Can be one of:
                - Unset: Return a list of `np.ndarray`.
                - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
                - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
                - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
                - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
            data_format (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
                The channel dimension format for the output 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.
                - Unset: Use the channel dimension format of the input image.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                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.
            do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
                Whether to convert the prompt mask to RGB format. If `num_labels` is specified, a palette will be built
                to map the prompt mask from a single channel to a 3 channel RGB. If unset, the prompt mask is duplicated
                across the channel dimension. Must be set to `False` if the prompt mask is already in RGB format.
            num_labels: (`int`, *optional*):
                Number of classes in the segmentation task (excluding the background). If specified, a palette will be
                built, assuming that class_idx 0 is the background, to map the prompt mask from a single class_idx
                channel to a 3 channel RGB. Not specifying this will result in the prompt mask either being passed
                through as is if it is already in RGB format or being duplicated across the channel dimension.
        Nr"   r   )Úexpected_ndimszkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.z,Size must be specified if do_resize is True.z7Rescale factor must be specified if do_rescale is True.z=Image mean and std must be specified if do_normalize is True.r   z­It looks like you are trying to rescale already rescaled images. If the input images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again.)re   r5   r6   )re   rT   rU   rg   )re   Úscalerg   )re   ÚmeanÚstdrg   )Úinput_channel_dim)rS   rV   rX   r[   rU   rW   rY   rZ   rT   r   r   r   ri   r   r   ÚloggerÚwarning_oncer   rd   rO   r   r;   r   ÚrescaleÚ	normalizer   )r`   rl   rS   rT   rU   rV   rW   rX   rY   rZ   r6   rg   r[   r   ra   Ú	size_dictre   r5   s                     r1   Ú_preprocess_stepz%SegGptImageProcessor._preprocess_stepö   s¶  € ðL "+Ð!6‘I¸D¿N¹Nˆ	Ø#-Ð#9‘Z¸t¿¹ˆ
Ø'3Ð'?‘|ÀT×EVÑEVˆØ+9Ð+E™È4×K^ÑK^ˆØ'Ð3‘8¸¿¹ˆØ+9Ð+E™È4×K^ÑK^ˆØ#-Ð#9‘Z¸t¿¹ˆ
Ø!*Ð!6‘I¸D¿N¹Nˆ	àÐ'‰t¨T¯Y©YˆÜ! $Ó'ˆ	ô % VÁ¹AÐUVÔWˆä˜FÔ#Üð:óð ñ
 ˜˜ÜÐKÓLÐLá˜.Ð0ÜÐVÓWÐWá˜ZÐ/°9Ð3DÜÐ\Ó]Ð]ð 6<Ö<¨E”. Õ'Ð<ˆÐ<áœ/¨&°©)Ô4Ü×Ñðsôð
 Ð$©^ä >¸vÀa¹yÓ IÐáØ6@Ð6L�d×&Ñ& zÔ2ÐRVˆGð qwöØgl�× Ñ  u°gÔK[×KaÑKaÐ ÕbðˆFð ô !1× 6Ñ 6Ðáð $öàð —‘ %¨iÀ(Ð^o�ÕpðˆFð ñ
 ð $öàð —‘ 5°ÐRc�ÕdðˆFð ñ
 ð $öàð —‘ U°ÀÐ^o�ÕpðˆFð ð ouö
ØejÔ'¨¨{ÐN_Ö`ð
ˆð 
ð ˆùòU =ùòùòùòùòùò

s$   Ã6HÅ)H$ÆH)ÇH.Ç$H3ÈH8Úprompt_imagesÚprompt_masksÚreturn_tensorsc                 óf  — t        d„ |||fD «       «      rt        d«      ‚i }|�% | j                  |fd||||||	|
|d||dœ|¤Ž}||d<   |�% | j                  |fd||||||	|
|d||dœ|¤Ž}||d<   |�3 | j                  |f||t        j                  |||	|
|||||dœ|¤Ž}||d<   t        ||¬	«      S )
a¤  
        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`.
            prompt_images (`ImageInput`):
                Prompt 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`.
            prompt_masks (`ImageInput`):
                Prompt mask from prompt image to _preprocess that specify prompt_masks value in the preprocessed output.
                Can either be in the format of segmentation maps (no channels) or RGB images. If in the format of
                RGB images, `do_convert_rgb` should be set to `False`. If in the format of segmentation maps, `num_labels`
                specifying `num_labels` is recommended to build a palette to map the prompt mask from a single channel to
                a 3 channel RGB. If `num_labels` is not specified, the prompt mask will be duplicated across the channel
                dimension.
            do_resize (`bool`, *optional*, defaults to `self.do_resize`):
                Whether to resize the image.
            size (`Dict[str, int]`, *optional*, defaults to `self.size`):
                Dictionary in the format `{"height": h, "width": w}` specifying the size of the output image after
                resizing.
            resample (`PILImageResampling` filter, *optional*, defaults to `self.resample`):
                `PILImageResampling` filter to use if resizing the image e.g. `PILImageResampling.BICUBIC`. Only has
                an effect if `do_resize` is set to `True`. Doesn't apply to prompt mask as it is resized using nearest.
            do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
                Whether to rescale the image values between [0 - 1].
            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 if `do_normalize` is set to `True`.
            image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
                Image standard deviation to use if `do_normalize` is set to `True`.
            do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
                Whether to convert the prompt mask to RGB format. If `num_labels` is specified, a palette will be built
                to map the prompt mask from a single channel to a 3 channel RGB. If unset, the prompt mask is duplicated
                across the channel dimension. Must be set to `False` if the prompt mask is already in RGB format.
            num_labels: (`int`, *optional*):
                Number of classes in the segmentation task (excluding the background). If specified, a palette will be
                built, assuming that class_idx 0 is the background, to map the prompt mask from a plain segmentation map
                with no channels to a 3 channel RGB. Not specifying this will result in the prompt mask either being passed
                through as is if it is already in RGB format (if `do_convert_rgb` is false) or being duplicated
                across the channel dimension.
            return_tensors (`str` or `TensorType`, *optional*):
                The type of tensors to return. Can be one of:
                - Unset: Return a list of `np.ndarray`.
                - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
                - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
                - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
                - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
            data_format (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
                The channel dimension format for the output 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.
                - Unset: Use the channel dimension format of the input image.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                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.
        c              3   ó$   K  — | ]  }|d u –— Œ
 y ­w)Nr]   )Ú.0Úvs     r1   ú	<genexpr>z2SegGptImageProcessor.preprocess.<locals>.<genexpr>Û  s   è ø€ ÒH˜Qˆq�DŒyÑHùs   ‚zFAt least one of images, prompt_images, prompt_masks must be specified.F)Úis_maskrS   rT   rU   rV   rW   rX   rY   rZ   r[   r6   rg   rR   Úprompt_pixel_values)rS   rT   rU   rV   rW   rX   rY   rZ   r[   r   r6   rg   rz   )ÚdataÚtensor_type)Úallri   rx   r   ÚNEARESTr
   )r`   rl   ry   rz   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r   r{   r6   rg   ra   rƒ   s                      r1   Ú
preprocesszSegGptImageProcessor.preprocess‡  sM  € ôh ÑH 6¨=¸,Ð"GÔHÔHÜÐeÓfÐfàˆàÐØ*�T×*Ñ*ØðàØ#ØØ!Ø%Ø-Ø)Ø%Ø#Ø$Ø'Ø"3ñð ñˆFð" $*ˆD�Ñ àÐ$Ø1˜D×1Ñ1ØðàØ#ØØ!Ø%Ø-Ø)Ø%Ø#Ø$Ø'Ø"3ñð ñˆMð" +8ˆDÐ&Ñ'àÐ#Ø0˜4×0Ñ0Øðà#ØÜ+×3Ñ3Ø%Ø-Ø)Ø%Ø#Ø-Ø%Ø'Ø"3ñð ñˆLð" $0ˆD�Ñ ä °>ÔBÐBr3   Útarget_sizesc                 óò  — t        | dg«       |j                  }|dd…dd…|j                  d   dz  d…dd…f   }t        j                  | j
                  «      j                  |j                  «      }t        j                  | j                  «      j                  |j                  «      }|j                  dddd«      |z  |z   }|j                  dddd«      }t        j                  |dz  dd«      }g }d}|�| j                  |«      nd}	|	�ft        j                  |	«      j                  |j                  t        j                  ¬«      }|j                  \  }
}}
}
|j                  dd|dz   |«      }t        |«      D ]õ  \  }}|�At        j                  j                   j#                  |j%                  d«      ||   d	¬
«      d   }|�z|j                  \  }}}|j                  ddd«      j                  ||d|«      }||z
  }t        j&                  |d«      }t        j(                  |d¬«      }|j+                  d¬«      }n |j-                  d¬«      j/                  «       }|j1                  |«       Œ÷ |S )aÖ  
        Converts the output of [`SegGptImageSegmentationOutput`] into segmentation maps. Only supports
        PyTorch.

        Args:
            outputs ([`SegGptImageSegmentationOutput`]):
                Raw outputs of the model.
            target_sizes (`List[Tuple[int, int]]`, *optional*):
                List of length (batch_size), where each list item (`Tuple[int, int]`) corresponds to the requested
                final size (height, width) of each prediction. If left to None, predictions will not be resized.
            num_labels (`int`, *optional*):
                Number of classes in the segmentation task (excluding the background). If specified, a palette will be
                built, assuming that class_idx 0 is the background, to map prediction masks from RGB values to class
                indices. This value should be the same used when preprocessing inputs.
        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.
        ÚtorchNr"   r   r   r    r#   )Údevicer8   Únearest)rT   Úmoder9   )Údim)r   Ú
pred_masksr<   rŠ   ÚtensorrZ   Útor‹   rY   ÚpermuterE   rd   ÚfloatÚviewÚ	enumerateÚnnÚ
functionalÚinterpolateÚ	unsqueezeÚpowÚsumÚargminrp   r$   r&   )r`   Úoutputsrˆ   r   Úmasksrq   rp   Úsemantic_segmentationÚpalette_tensorr5   Ú_Únum_channelsÚidxr4   ÚchannelsrG   rH   ÚdistÚpreds                      r1   Ú"post_process_semantic_segmentationz7SegGptImageProcessor.post_process_semantic_segmentation  sQ  € ô, 	˜$  	Ô*à×"Ñ"ˆð ’aš˜EŸK™K¨™N¨aÑ/Ñ1²1Ð4Ñ5ˆô �l‰l˜4Ÿ>™>Ó*×-Ñ-¨e¯l©lÓ;ˆÜ�|‰|˜DŸO™OÓ,×/Ñ/°·±Ó=ˆà—‘˜a  A qÓ)¨CÑ/°$Ñ6ˆð —‘˜a  A qÓ)ˆô —
‘
˜5 3™;¨¨3Ó/ˆà "ÐØˆØ2<Ð2H�$×"Ñ" :Ô.ÈdˆØÐÜ"Ÿ\™\¨'Ó2×5Ñ5¸U¿\¹\ÔQV×Q\ÑQ\Ð5Ó]ˆNØ$)§K¡KÑ!ˆAˆ|˜Q Ø+×0Ñ0°°A°zÀA±~À|ÓTˆNä" 5Ó)ò 	/‰IˆC�ØÐ'Ü—x‘x×*Ñ*×6Ñ6Ø—N‘N 1Ó%Ø% cÑ*Ø"ð 7ó ð ñ	�ð Ð%Ø*.¯*©*Ñ'�˜& %Ø—|‘| A q¨!Ó,×1Ñ1°&¸%ÀÀHÓM�Ø˜nÑ,�Ü—y‘y  qÓ)�Ü—y‘y ¨2Ô.�Ø—{‘{ r�{Ó*‘ð —y‘y Q�yÓ'×+Ñ+Ó-�à!×(Ñ(¨Õ.ð)	/ð, %Ð$r3   ©NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr   ÚBICUBICÚboolr   r   Ústrr$   r   r“   r   r_   r   rd   r=   Úndarrayr   rO   r   r;   r   rx   r   r‡   r§   Ú__classcell__)rb   s   @r1   rQ   rQ   b   s±  ø„ ñðB (Ð(Ðð Ø)-Ø'9×'AÑ'AØØ,3Ø!Ø:>Ø9=Ø#ñ-àð-ð �t˜C ˜H‘~Ñ&ð-ð %ð	-ð
 ð-ð ˜c 5˜jÑ)ð-ð ð-ð ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ð-ð ˜E %¨¨e©Ð"4Ñ5Ñ6ð-ð ð-ð 
õ-ð4
) cð 
)¨d°5¸¸c¸±?Ñ.Có 
)ð 48Ø>Bñ	Là�z‰zðLð ˜$˜u S¨# X™Ñ/Ñ0ðLð ˜e CÐ)9Ð$9Ñ:Ñ;ð	Lð
 
�‰óLð< (:×'AÑ'AØ>BØDHñ.
à�z‰zð.
ð �3˜�8‰nð.
ð %ð	.
ð
 ˜e CÐ)9Ð$9Ñ:Ñ;ð.
ð $ E¨#Ð/?Ð*?Ñ$@ÑAð.
ð 
�‰ó.
ðf %)Ø#Ø'+Ø%)Ø*.Ø'+Ø:>Ø9=Ø4D×4JÑ4JØDHØ)-Ø$(ñOàðOð ˜D‘>ðOð �3˜�8‰nð	Oð
 %ðOð ˜T‘NðOð ! ™ðOð ˜t‘nðOð ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ðOð ˜E %¨¨e©Ð"4Ñ5Ñ6ðOð ˜3Ð 0Ð0Ñ1ðOð $ E¨#Ð/?Ð*?Ñ$@ÑAðOð ! ™ðOð ˜S‘MóOðf (,Ø.2Ø-1Ø$(Ø#Ø'+Ø%)Ø*.Ø'+Ø:>Ø9=Ø)-Ø$(Ø;?Ø4D×4JÑ4JØDHñ#UCà˜Ñ$ðUCð   
Ñ+ðUCð ˜zÑ*ð	UCð
 ˜D‘>ðUCð �3˜�8‰nðUCð %ðUCð ˜T‘NðUCð ! ™ðUCð ˜t‘nðUCð ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ðUCð ˜E %¨¨e©Ð"4Ñ5Ñ6ðUCð ! ™ðUCð ˜S‘MðUCð !  s¨J Ñ!7Ñ8ðUCð  ˜3Ð 0Ð0Ñ1ð!UCð" $ E¨#Ð/?Ð*?Ñ$@ÑAó#UCðp jnñI%Ø%-¨d°5¸¸c¸±?Ñ.CÑ%DðI%ØYaÐbeÑYf÷I%r3   rQ   r¨   )+r¬   Útypingr   r   r   r   r   Únumpyr=   Úimage_processing_utilsr	   r
   r   Úimage_transformsr   r   Úimage_utilsr   r   r   r   r   r   r   r   r   r   Úutilsr   r   r   r   r   rŠ   Ú
get_loggerr©   rs   r$   r2   r±   rO   rQ   Ú__all__r]   r3   r1   ú<module>r»      sâ   ðñ (ç 5Õ 5ã ç UÑ Uß C÷÷ ÷ ÷ eÕ dñ ÔÛáÔØð 
ˆ×	Ñ	˜HÓ	%€ð
˜cð  d¨5°°c°©?Ñ&;ó ð* rvñ>Ø
�*‰*ð>Ø'¨¨U°3¸°8©_Ñ(=Ñ>ð>ØT\Ð]mÑTnð>à‡Z�Zó>ô8E%Ð-ô E%ðP "Ð
"�r3   