Ë
    T^(h|9  ã                   ó¤   — d Z ddlmZ ddlmZ  ej
                  e«      Z G d„ de«      Z G d„ de«      Z	 G d„ d	e«      Z
 G d
„ de«      Zg d¢Zy)zSAM model configurationé   )ÚPretrainedConfig)Úloggingc                   ó6   ‡ — e Zd ZdZdZ	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚSamPromptEncoderConfiga  
    This is the configuration class to store the configuration of a [`SamPromptEncoder`]. The [`SamPromptEncoder`]
    module is used to encode the input 2D points and bounding boxes. Instantiating a configuration defaults will yield
    a similar configuration to that of the SAM-vit-h
    [facebook/sam-vit-huge](https://huggingface.co/facebook/sam-vit-huge) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        hidden_size (`int`, *optional*, defaults to 256):
            Dimensionality of the hidden states.
        image_size (`int`, *optional*, defaults to 1024):
            The expected output resolution of the image.
        patch_size (`int`, *optional*, defaults to 16):
            The size (resolution) of each patch.
        mask_input_channels (`int`, *optional*, defaults to 16):
            The number of channels to be fed to the `MaskDecoder` module.
        num_point_embeddings (`int`, *optional*, defaults to 4):
            The number of point embeddings to be used.
        hidden_act (`str`, *optional*, defaults to `"gelu"`):
            The non-linear activation function in the encoder and pooler.
    Úprompt_encoder_configc                 óš   •— t        ‰	| �  di |¤Ž || _        || _        || _        ||z  | _        || _        || _        || _        || _	        y ©N© )
ÚsuperÚ__init__Úhidden_sizeÚ
image_sizeÚ
patch_sizeÚimage_embedding_sizeÚmask_input_channelsÚnum_point_embeddingsÚ
hidden_actÚlayer_norm_eps)
Úselfr   r   r   r   r   r   r   ÚkwargsÚ	__class__s
            €úg/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/sam/configuration_sam.pyr   zSamPromptEncoderConfig.__init__3   sW   ø€ ô 	‰ÑÑ"˜6Ò"Ø&ˆÔØ$ˆŒØ$ˆŒØ$.°*Ñ$<ˆÔ!Ø#6ˆÔ Ø$8ˆÔ!Ø$ˆŒØ,ˆÕó    )é   é   é   r   é   Úgeluç�íµ ÷Æ°>©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úbase_config_keyr   Ú__classcell__©r   s   @r   r   r      s0   ø„ ñð0 .€Oð ØØØØØØ÷-ñ -r   r   c                   ó<   ‡ — e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚSamMaskDecoderConfiga¿  
    This is the configuration class to store the configuration of a [`SamMaskDecoder`]. It is used to instantiate a SAM
    mask decoder to the specified arguments, defining the model architecture. Instantiating a configuration defaults
    will yield a similar configuration to that of the SAM-vit-h
    [facebook/sam-vit-huge](https://huggingface.co/facebook/sam-vit-huge) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        hidden_size (`int`, *optional*, defaults to 256):
            Dimensionality of the hidden states.
        hidden_act (`str`, *optional*, defaults to `"relu"`):
            The non-linear activation function used inside the `SamMaskDecoder` module.
        mlp_dim (`int`, *optional*, defaults to 2048):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 2):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 8):
            Number of attention heads for each attention layer in the Transformer encoder.
        attention_downsample_rate (`int`, *optional*, defaults to 2):
            The downsampling rate of the attention layer.
        num_multimask_outputs (`int`, *optional*, defaults to 3):
            The number of outputs from the `SamMaskDecoder` module. In the Segment Anything paper, this is set to 3.
        iou_head_depth (`int`, *optional*, defaults to 3):
            The number of layers in the IoU head module.
        iou_head_hidden_dim (`int`, *optional*, defaults to 256):
            The dimensionality of the hidden states in the IoU head module.
        layer_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the layer normalization layers.

    Úmask_decoder_configc                 ó°   •— t        ‰| �  di |¤Ž || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        y r	   )r   r   r   r   Úmlp_dimÚnum_hidden_layersÚnum_attention_headsÚattention_downsample_rateÚnum_multimask_outputsÚiou_head_depthÚiou_head_hidden_dimr   )r   r   r   r,   r-   r.   r/   r0   r1   r2   r   r   r   s               €r   r   zSamMaskDecoderConfig.__init__m   sc   ø€ ô 	‰ÑÑ"˜6Ò"Ø&ˆÔØ$ˆŒØˆŒØ!2ˆÔØ#6ˆÔ Ø)BˆÔ&Ø%:ˆÔ"Ø,ˆÔØ#6ˆÔ Ø,ˆÕr   )
r   Úrelui   é   é   r4   r   r   r   r   r    r'   s   @r   r)   r)   I   s:   ø„ ñðB ,€Oð ØØØØØ"#ØØØØ÷-ñ -r   r)   c                   óV   ‡ — e Zd ZdZdZdZddddddd	d
ddddddddg d¢ddfˆ fd„	Zˆ xZS )ÚSamVisionConfiga  
    This is the configuration class to store the configuration of a [`SamVisionModel`]. It is used to instantiate a SAM
    vision encoder according to the specified arguments, defining the model architecture. Instantiating a configuration
    defaults will yield a similar configuration to that of the SAM ViT-h
    [facebook/sam-vit-huge](https://huggingface.co/facebook/sam-vit-huge) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers and the pooler layer.
        output_channels (`int`, *optional*, defaults to 256):
            Dimensionality of the output channels in the Patch Encoder.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 12):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_channels (`int`, *optional*, defaults to 3):
            Number of channels in the input image.
        image_size (`int`, *optional*, defaults to 1024):
            Expected resolution. Target size of the resized input image.
        patch_size (`int`, *optional*, defaults to 16):
            Size of the patches to be extracted from the input image.
        hidden_act (`str`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string)
        layer_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the layer normalization layers.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        initializer_range (`float`, *optional*, defaults to 1e-10):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        qkv_bias (`bool`, *optional*, defaults to `True`):
            Whether to add a bias to query, key, value projections.
        mlp_ratio (`float`, *optional*, defaults to 4.0):
            Ratio of mlp hidden dim to embedding dim.
        use_abs_pos (`bool`, *optional*, defaults to `True`):
            Whether to use absolute position embedding.
        use_rel_pos (`bool`, *optional*, defaults to `True`):
            Whether to use relative position embedding.
        window_size (`int`, *optional*, defaults to 14):
            Window size for relative position.
        global_attn_indexes (`List[int]`, *optional*, defaults to `[2, 5, 8, 11]`):
            The indexes of the global attention layers.
        num_pos_feats (`int`, *optional*, defaults to 128):
            The dimensionality of the position embedding.
        mlp_dim (`int`, *optional*):
            The dimensionality of the MLP layer in the Transformer encoder. If `None`, defaults to `mlp_ratio *
            hidden_size`.

    Example:

    ```python
    >>> from transformers import (
    ...     SamVisionConfig,
    ...     SamVisionModel,
    ... )

    >>> # Initializing a SamVisionConfig with `"facebook/sam-vit-huge"` style configuration
    >>> configuration = SamVisionConfig()

    >>> # Initializing a SamVisionModel (with random weights) from the `"facebook/sam-vit-huge"` style configuration
    >>> model = SamVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úvision_configÚsam_vision_modeli   r   é   r   r   r   r   r   g        g»½×Ùß|Û=Tg      @é   )r4   é   r5   é   é€   Nc                 óZ  •— t        ‰| �  di |¤Ž || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        |€t)        ||z  «      | _        y || _        y r	   )r   r   r   Úoutput_channelsr-   r.   Únum_channelsr   r   r   r   Úattention_dropoutÚinitializer_rangeÚqkv_biasÚ	mlp_ratioÚuse_abs_posÚuse_rel_posÚwindow_sizeÚglobal_attn_indexesÚnum_pos_featsÚintr,   )r   r   r@   r-   r.   rA   r   r   r   r   rB   rC   rD   rE   rF   rG   rH   rI   rJ   r,   r   r   s                        €r   r   zSamVisionConfig.__init__Ð   s»   ø€ ô. 	‰ÑÑ"˜6Ò"à&ˆÔØ.ˆÔØ!2ˆÔØ#6ˆÔ Ø(ˆÔØ$ˆŒØ$ˆŒØ$ˆŒØ,ˆÔØ!2ˆÔØ!2ˆÔØ ˆŒØ"ˆŒØ&ˆÔØ&ˆÔØ&ˆÔØ#6ˆÔ Ø*ˆÔØ7>°”s˜;¨Ñ2Ó3ˆ�ÈGˆ�r   )r!   r"   r#   r$   r%   Ú
model_typer   r&   r'   s   @r   r7   r7   ˆ   s]   ø„ ñBðH &€OØ#€Jð ØØØØØØØØØØØØØØØÚ)ØØ÷)+Tñ +Tr   r7   c                   ó<   ‡ — e Zd ZdZdZeeedœZ	 	 	 	 dˆ fd„	Z	ˆ xZ
S )Ú	SamConfiga²  
    [`SamConfig`] is the configuration class to store the configuration of a [`SamModel`]. It is used to instantiate a
    SAM model according to the specified arguments, defining the vision model, prompt-encoder model and mask decoder
    configs. Instantiating a configuration with the defaults will yield a similar configuration to that of the
    SAM-ViT-H [facebook/sam-vit-huge](https://huggingface.co/facebook/sam-vit-huge) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        vision_config (Union[`dict`, `SamVisionConfig`], *optional*):
            Dictionary of configuration options used to initialize [`SamVisionConfig`].
        prompt_encoder_config (Union[`dict`, `SamPromptEncoderConfig`], *optional*):
            Dictionary of configuration options used to initialize [`SamPromptEncoderConfig`].
        mask_decoder_config (Union[`dict`, `SamMaskDecoderConfig`], *optional*):
            Dictionary of configuration options used to initialize [`SamMaskDecoderConfig`].

        kwargs (*optional*):
            Dictionary of keyword arguments.

    Example:

    ```python
    >>> from transformers import (
    ...     SamVisionConfig,
    ...     SamPromptEncoderConfig,
    ...     SamMaskDecoderConfig,
    ...     SamModel,
    ... )

    >>> # Initializing a SamConfig with `"facebook/sam-vit-huge"` style configuration
    >>> configuration = SamConfig()

    >>> # Initializing a SamModel (with random weights) from the `"facebook/sam-vit-huge"` style configuration
    >>> model = SamModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config

    >>> # We can also initialize a SamConfig from a SamVisionConfig, SamPromptEncoderConfig, and SamMaskDecoderConfig

    >>> # Initializing SAM vision, SAM Q-Former and language model configurations
    >>> vision_config = SamVisionConfig()
    >>> prompt_encoder_config = SamPromptEncoderConfig()
    >>> mask_decoder_config = SamMaskDecoderConfig()

    >>> config = SamConfig(vision_config, prompt_encoder_config, mask_decoder_config)
    ```Úsam)r   r*   r8   c                 óv  •— t        ‰| �  di |¤Ž |�|ni }|�|ni }|�|ni }t        |t        «      r|j	                  «       }t        |t
        «      r|j	                  «       }t        |t        «      r|j	                  «       }t        di |¤Ž| _        t        di |¤Ž| _        t        di |¤Ž| _	        || _
        y r	   )r   r   Ú
isinstancer7   Úto_dictr   r)   r8   r   r*   rC   )r   r8   r   r*   rC   r   r   s         €r   r   zSamConfig.__init__7  sÇ   ø€ ô 	‰ÑÑ"˜6Ò"Ø)6Ð)B™ÈˆØ9NÐ9ZÑ 5Ð`bÐØ5HÐ5TÑ1ÐZ\Ðä�m¤_Ô5Ø)×1Ñ1Ó3ˆMÜÐ+Ô-CÔDØ$9×$AÑ$AÓ$CÐ!ÜÐ)Ô+?Ô@Ø"5×"=Ñ"=Ó"?Ðä,Ñ=¨}Ñ=ˆÔÜ%;Ñ%TÐ>SÑ%TˆÔ"Ü#7Ñ#NÐ:MÑ#NˆÔ Ø!2ˆÕr   )NNNg{®Gáz”?)r!   r"   r#   r$   rL   r   r)   r7   Úsub_configsr   r&   r'   s   @r   rN   rN   þ   s8   ø„ ñ/ðb €Jà!7Ø3Ø(ñ€Kð Ø"Ø Ø÷3ñ 3r   rN   )rN   r)   r   r7   N)r$   Úconfiguration_utilsr   Úutilsr   Ú
get_loggerr!   Úloggerr   r)   r7   rN   Ú__all__r
   r   r   ú<module>rY      sj   ðñ å 3Ý ð 
ˆ×	Ñ	˜HÓ	%€ô.-Ð-ô .-ôb<-Ð+ô <-ô~sTÐ&ô sTôlP3Ð ô P3òf ]�r   