a
    d?                     @   sN   d Z ddlZddlmZ ddlmZ ddlmZ ee	Z
G dd	 d	eZdS )
z UperNet model configuration    N   )PretrainedConfig)logging   )CONFIG_MAPPINGc                       sH   e Zd ZdZdZdddg dddd	d
dddf fdd	Zdd Z  ZS )UperNetConfiga	  
    This is the configuration class to store the configuration of an [`UperNetForSemanticSegmentation`]. It is used to
    instantiate an UperNet model according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the UperNet
    [openmmlab/upernet-convnext-tiny](https://huggingface.co/openmmlab/upernet-convnext-tiny) architecture.

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

    Args:
        backbone_config (`PretrainedConfig` or `dict`, *optional*, defaults to `ResNetConfig()`):
            The configuration of the backbone model.
        hidden_size (`int`, *optional*, defaults to 512):
            The number of hidden units in the convolutional layers.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        pool_scales (`Tuple[int]`, *optional*, defaults to `[1, 2, 3, 6]`):
            Pooling scales used in Pooling Pyramid Module applied on the last feature map.
        use_auxiliary_head (`bool`, *optional*, defaults to `True`):
            Whether to use an auxiliary head during training.
        auxiliary_loss_weight (`float`, *optional*, defaults to 0.4):
            Weight of the cross-entropy loss of the auxiliary head.
        auxiliary_channels (`int`, *optional*, defaults to 256):
            Number of channels to use in the auxiliary head.
        auxiliary_num_convs (`int`, *optional*, defaults to 1):
            Number of convolutional layers to use in the auxiliary head.
        auxiliary_concat_input (`bool`, *optional*, defaults to `False`):
            Whether to concatenate the output of the auxiliary head with the input before the classification layer.
        loss_ignore_index (`int`, *optional*, defaults to 255):
            The index that is ignored by the loss function.

    Examples:

    ```python
    >>> from transformers import UperNetConfig, UperNetForSemanticSegmentation

    >>> # Initializing a configuration
    >>> configuration = UperNetConfig()

    >>> # Initializing a model (with random weights) from the configuration
    >>> model = UperNetForSemanticSegmentation(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```ZupernetNi   g{Gz?)   r   r      Tg?i     r   F   c                    s   t  jf i | |d u r8td td g dd}n&t|tr^|d}t| }||}|| _	|| _
|| _|| _|| _|| _|| _|| _|	| _|
| _|| _d S )NzX`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.Zresnet)Zstage1Zstage2Zstage3Zstage4)Zout_features
model_type)super__init__loggerinfor   
isinstancedictget	from_dictbackbone_confighidden_sizeinitializer_rangepool_scalesuse_auxiliary_headauxiliary_loss_weightauxiliary_in_channelsauxiliary_channelsauxiliary_num_convsauxiliary_concat_inputloss_ignore_index)selfr   r   r   r   r   r   r   r   r   r   r   kwargsZbackbone_model_typeZconfig_class	__class__ z/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/transformers/models/upernet/configuration_upernet.pyr   K   s&    



zUperNetConfig.__init__c                 C   s*   t | j}| j |d< | jj|d< |S )z
        Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`]. Returns:
            `Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
        r   r   )copydeepcopy__dict__r   to_dictr#   r   )r    outputr$   r$   r%   r)   p   s    zUperNetConfig.to_dict)__name__
__module____qualname____doc__r   r   r)   __classcell__r$   r$   r"   r%   r      s   -%r   )r.   r&   Zconfiguration_utilsr   utilsr   Zauto.configuration_autor   Z
get_loggerr+   r   r   r$   r$   r$   r%   <module>   s   
