o
    h                     @   s  d dl Z d dlmZ d dlmZmZmZ d dlZd dlm	  m
Z d dlm	Z	mZ ddlmZmZ ddlmZ ddlmZmZ dd	lmZ d
dlmZmZmZ d
dlmZ d
dlmZmZ g dZ dejdejfddZ!ej"#d dejdejde$e% dejfddZ&ej"#d G dd de	j'Z(G dd de	j'Z)						d[deded ed!ede$e% d"e%d#e$e% d$e*d%e*d&ee d'ee d(eej d)e+defd*d+Z,ej"#d+ G d,d- d-e	j'Z-G d.d/ d/e-Z.G d0d1 d1e	j'Z/G d2d3 d3e/Z0G d4d5 d5e	j'Z1d6e$e% d7e%d8e$e% d"e$e% de$e% d9e*d:ee d;e+d<ede1fd=d>Z2d?eiZ3G d@dA dAeZ4G dBdC dCeZ5G dDdE dEeZ6G dFdG dGeZ7G dHdI dIeZ8G dJdK dKeZ9e edLe4j:fdMdddNd:ee4 d;e+d<ede1fdOdPZ;e edLe5j:fdMdddNd:ee5 d;e+d<ede1fdQdRZ<e edLe6j:fdMdddNd:ee6 d;e+d<ede1fdSdTZ=e edLe7j:fdMdddNd:ee7 d;e+d<ede1fdUdVZ>e edLe8j:fdMdddNd:ee8 d;e+d<ede1fdWdXZ?e edLe9j:fdMdddNd:ee9 d;e+d<ede1fdYdZZ@dS )\    N)partial)AnyCallableOptional)nnTensor   )MLPPermute)StochasticDepth)ImageClassificationInterpolationMode)_log_api_usage_once   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)SwinTransformerSwin_T_WeightsSwin_S_WeightsSwin_B_WeightsSwin_V2_T_WeightsSwin_V2_S_WeightsSwin_V2_B_Weightsswin_tswin_sswin_b	swin_v2_t	swin_v2_s	swin_v2_bxreturnc              
   C   s   | j dd  \}}}t| ddd|d d|d f} | ddd ddd dd d f }| ddd ddd dd d f }| ddd ddd dd d f }| ddd ddd dd d f }t||||gd} | S )Nr   r   .r   )shapeFpadtorchcat)r#   HW_Zx0x1Zx2Zx3 r0   i/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/torchvision/models/swin_transformer.py_patch_merging_pad#   s        r2   relative_position_bias_tablerelative_position_indexwindow_sizec                 C   sB   |d |d  }| | }| ||d}|ddd d}|S )Nr   r   r&   r   )viewpermute
contiguous	unsqueeze)r3   r4   r5   Nrelative_position_biasr0   r0   r1   _get_relative_position_bias1   s
   r<   c                       H   e Zd ZdZejfdededejf f fddZ	de
fdd	Z  ZS )
PatchMergingzPatch Merging Layer.
    Args:
        dim (int): Number of input channels.
        norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm.
    dim
norm_layer.c                    sD   t    t|  || _tjd| d| dd| _|d| | _d S N   r   Fbiassuper__init__r   r?   r   Linear	reductionnormselfr?   r@   	__class__r0   r1   rG   E   
   
zPatchMerging.__init__r#   c                 C       t |}| |}| |}|S z
        Args:
            x (Tensor): input tensor with expected layout of [..., H, W, C]
        Returns:
            Tensor with layout of [..., H/2, W/2, 2*C]
        )r2   rJ   rI   rL   r#   r0   r0   r1   forwardL      

zPatchMerging.forward__name__
__module____qualname____doc__r   	LayerNormintr   ModulerG   r   rS   __classcell__r0   r0   rM   r1   r>   >       &r>   c                       r=   )
PatchMergingV2zPatch Merging Layer for Swin Transformer V2.
    Args:
        dim (int): Number of input channels.
        norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm.
    r?   r@   .c                    sD   t    t|  || _tjd| d| dd| _|d| | _d S rA   rE   rK   rM   r0   r1   rG   `   rO   zPatchMergingV2.__init__r#   c                 C   rP   rQ   )r2   rI   rJ   rR   r0   r0   r1   rS   g   rT   zPatchMergingV2.forwardrU   r0   r0   rM   r1   r_   Y   r^   r_           Tinput
qkv_weightproj_weightr;   	num_heads
shift_sizeattention_dropoutdropoutqkv_bias	proj_biaslogit_scaletrainingc           $   	   C   s  | j \}}}}|d ||d   |d  }|d ||d   |d  }t| ddd|d|f}|j \}}}}| }|d |krDd|d< |d |krNd|d< t|dkrdtj||d  |d  fdd}||d  ||d   }||||d  |d ||d  |d |}|dddddd	|| |d |d  |}|d	ur|	d	ur|	
 }	|	 d }|	|d|    t|||	}|	|d|dd||| ddddd}|d |d |d }}}|d	urtj|d
dtj|d
ddd
 }tj|tdd }|| }n||| d  }||dd
}|| }t|dkr|||f}d|d  f|d  |d  f|d  d	ff}d|d  f|d  |d  f|d  d	ff} d}!|D ]}"| D ]}#|!||"d |"d |#d |#d f< |!d7 }!qgqc|||d  |d ||d  |d }|dddd	||d |d  }|d|d }||dktd|dktd}||d| |||d|d}||dd }|d
||d|d}tj|d
d}tj|||d}||dd	|d|d|}t|||
}tj|||d}||||d  ||d  |d |d |}|dddddd	||||}t|dkr^tj||d |d fdd}|d	d	d	|d	|d	d	f  }|S )a  
    Window based multi-head self attention (W-MSA) module with relative position bias.
    It supports both of shifted and non-shifted window.
    Args:
        input (Tensor[N, H, W, C]): The input tensor or 4-dimensions.
        qkv_weight (Tensor[in_dim, out_dim]): The weight tensor of query, key, value.
        proj_weight (Tensor[out_dim, out_dim]): The weight tensor of projection.
        relative_position_bias (Tensor): The learned relative position bias added to attention.
        window_size (List[int]): Window size.
        num_heads (int): Number of attention heads.
        shift_size (List[int]): Shift size for shifted window attention.
        attention_dropout (float): Dropout ratio of attention weight. Default: 0.0.
        dropout (float): Dropout ratio of output. Default: 0.0.
        qkv_bias (Tensor[out_dim], optional): The bias tensor of query, key, value. Default: None.
        proj_bias (Tensor[out_dim], optional): The bias tensor of projection. Default: None.
        logit_scale (Tensor[out_dim], optional): Logit scale of cosine attention for Swin Transformer V2. Default: None.
        training (bool, optional): Training flag used by the dropout parameters. Default: True.
    Returns:
        Tensor[N, H, W, C]: The output tensor after shifted window attention.
    r   r   )r   r   )Zshiftsdims   r   rB      Nr&   )r?   g      Y@)maxg      g      Yr`   )prk   )r'   r(   r)   copysumr*   Zrollr6   r7   Zreshapeclonenumelzero_Zlinearsize	normalizeZ	transposeclampmathlogexpmatmulZ	new_zerosr9   Zmasked_fillfloatZsoftmaxrg   r8   )$ra   rb   rc   r;   r5   rd   re   rf   rg   rh   ri   rj   rk   Br,   r-   CZpad_rZpad_br#   r.   Zpad_HZpad_WZnum_windowslengthqkvqkvattnZ	attn_maskZh_slicesZw_slicescounthwr0   r0   r1   shifted_window_attentiont   sr   # ,.0
$
..$($$((, $r   c                       s   e Zd ZdZ				ddedee dee deded	ed
edef fddZdd Z	dd Z
dejfddZdedefddZ  ZS )ShiftedWindowAttentionz/
    See :func:`shifted_window_attention`.
    Tr`   r?   r5   re   rd   rh   ri   rf   rg   c	           	         s   t    t|dkst|dkrtd|| _|| _|| _|| _|| _t	j
||d |d| _t	j
|||d| _|   |   d S )Nr   z.window_size and shift_size must be of length 2rm   rC   )rF   rG   len
ValueErrorr5   re   rd   rf   rg   r   rH   r   proj#define_relative_position_bias_tabledefine_relative_position_index)	rL   r?   r5   re   rd   rh   ri   rf   rg   rM   r0   r1   rG      s   
zShiftedWindowAttention.__init__c                 C   sL   t td| jd  d d| jd  d  | j| _t jj| jdd d S )Nr   r   r   {Gz?Zstd)	r   	Parameterr*   Zzerosr5   rd   r3   inittrunc_normal_rL   r0   r0   r1   r   	  s   ,z:ShiftedWindowAttention.define_relative_position_bias_tablec                 C   s  t | jd }t | jd }t t j||dd}t |d}|d d d d d f |d d d d d f  }|ddd }|d d d d df  | jd d 7  < |d d d d df  | jd d 7  < |d d d d df  d| jd  d 9  < |d }| 	d| d S )Nr   r   ijZindexingr   r&   r4   )
r*   aranger5   stackmeshgridflattenr7   r8   rs   register_buffer)rL   Zcoords_hZcoords_wZcoordsZcoords_flattenZrelative_coordsr4   r0   r0   r1   r     s   ,((,z5ShiftedWindowAttention.define_relative_position_indexr$   c                 C   s   t | j| j| jS N)r<   r3   r4   r5   r   r0   r0   r1   get_relative_position_bias  s   z1ShiftedWindowAttention.get_relative_position_biasr#   c                 C   sD   |   }t|| jj| jj|| j| j| j| j| j	| jj
| jj
| jdS )
        Args:
            x (Tensor): Tensor with layout of [B, H, W, C]
        Returns:
            Tensor with same layout as input, i.e. [B, H, W, C]
        )re   rf   rg   rh   ri   rk   )r   r   r   weightr   r5   rd   re   rf   rg   rD   rk   rL   r#   r;   r0   r0   r1   rS   #  s   zShiftedWindowAttention.forwardTTr`   r`   )rV   rW   rX   rY   r[   listboolr~   rG   r   r   r*   r   r   rS   r]   r0   r0   rM   r1   r      s6    
	r   c                       sz   e Zd ZdZ				ddedee dee deded	ed
edef fddZdd Z	de
jfddZdefddZ  ZS )ShiftedWindowAttentionV2z2
    See :func:`shifted_window_attention_v2`.
    Tr`   r?   r5   re   rd   rh   ri   rf   rg   c	           
   
      s   t  j||||||||d ttdt|ddf | _ttj	ddddtj
ddtj	d|d	d| _|rP| jj d
 }	| jj|	d|	  j  d S d S )N)rh   ri   rf   rg   
   r   r   i   TrC   )inplaceFrm   )rF   rG   r   r   r*   r{   Zonesrj   
SequentialrH   ZReLUcpb_mlpr   rD   ru   datarv   )
rL   r?   r5   re   rd   rh   ri   rf   rg   r   rM   r0   r1   rG   @  s$   "&z!ShiftedWindowAttentionV2.__init__c                 C   s  t j| jd d  | jd t jd}t j| jd d  | jd t jd}t t j||gdd}|ddd d}|d d d d d d df  | jd d   < |d d d d d d df  | jd d   < |d9 }t 	|t 
t |d  d	 }| d
| d S )Nr   r   )Zdtyper   r   r      g      ?g      @relative_coords_table)r*   r   r5   Zfloat32r   r   r7   r8   r9   signlog2absr   )rL   Zrelative_coords_hZrelative_coords_wr   r0   r0   r1   r   _  s   $$.. z<ShiftedWindowAttentionV2.define_relative_position_bias_tabler$   c                 C   s4   t | | jd| j| j| j}dt| }|S )Nr&      )	r<   r   r   r6   rd   r4   r5   r*   Zsigmoid)rL   r;   r0   r0   r1   r   o  s   z3ShiftedWindowAttentionV2.get_relative_position_biasr#   c                 C   sH   |   }t|| jj| jj|| j| j| j| j| j	| jj
| jj
| j| jdS )r   )re   rf   rg   rh   ri   rj   rk   )r   r   r   r   r   r5   rd   re   rf   rg   rD   rj   rk   r   r0   r0   r1   rS   x  s    z ShiftedWindowAttentionV2.forwardr   )rV   rW   rX   rY   r[   r   r   r~   rG   r   r*   r   r   rS   r]   r0   r0   rM   r1   r   ;  s4    
		r   c                          e Zd ZdZddddejefdededee dee de	d	e	d
e	de	de
dejf de
dejf f fddZdefddZ  ZS )SwinTransformerBlocka  
    Swin Transformer Block.
    Args:
        dim (int): Number of input channels.
        num_heads (int): Number of attention heads.
        window_size (List[int]): Window size.
        shift_size (List[int]): Shift size for shifted window attention.
        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
        dropout (float): Dropout rate. Default: 0.0.
        attention_dropout (float): Attention dropout rate. Default: 0.0.
        stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
        norm_layer (nn.Module): Normalization layer.  Default: nn.LayerNorm.
        attn_layer (nn.Module): Attention layer. Default: ShiftedWindowAttention
          @r`   r?   rd   r5   re   	mlp_ratiorg   rf   stochastic_depth_probr@   .
attn_layerc                    s   t    t|  |	|| _|
||||||d| _t|d| _|	|| _t|t	|| |gt
jd |d| _| j D ]}t|t
jrWt
j|j |jd urWt
jj|jdd q:d S )N)rf   rg   row)Zactivation_layerr   rg   gư>r   )rF   rG   r   norm1r   r   stochastic_depthnorm2r	   r[   r   ZGELUmlpmodules
isinstancerH   r   Zxavier_uniform_r   rD   Znormal_)rL   r?   rd   r5   re   r   rg   rf   r   r@   r   mrM   r0   r1   rG     s*   


"
zSwinTransformerBlock.__init__r#   c                 C   8   ||  | | | }||  | | | }|S r   )r   r   r   r   r   rR   r0   r0   r1   rS     s   zSwinTransformerBlock.forward)rV   rW   rX   rY   r   rZ   r   r[   r   r~   r   r\   rG   r   rS   r]   r0   r0   rM   r1   r     s<    	
#r   c                       r   )SwinTransformerBlockV2a  
    Swin Transformer V2 Block.
    Args:
        dim (int): Number of input channels.
        num_heads (int): Number of attention heads.
        window_size (List[int]): Window size.
        shift_size (List[int]): Shift size for shifted window attention.
        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
        dropout (float): Dropout rate. Default: 0.0.
        attention_dropout (float): Attention dropout rate. Default: 0.0.
        stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
        norm_layer (nn.Module): Normalization layer.  Default: nn.LayerNorm.
        attn_layer (nn.Module): Attention layer. Default: ShiftedWindowAttentionV2.
    r   r`   r?   rd   r5   re   r   rg   rf   r   r@   .r   c                    s$   t  j|||||||||	|
d
 d S )N)r   rg   rf   r   r@   r   )rF   rG   )rL   r?   rd   r5   re   r   rg   rf   r   r@   r   rM   r0   r1   rG     s   
zSwinTransformerBlockV2.__init__r#   c                 C   r   r   )r   r   r   r   r   rR   r0   r0   r1   rS     s   zSwinTransformerBlockV2.forward)rV   rW   rX   rY   r   rZ   r   r[   r   r~   r   r\   rG   r   rS   r]   r0   r0   rM   r1   r     s<    	
r   c                       s   e Zd ZdZdddddddefdee ded	ee d
ee dee dedededededee	de
jf  dee	de
jf  de	de
jf f fddZdd Z  ZS )r   a;  
    Implements Swin Transformer from the `"Swin Transformer: Hierarchical Vision Transformer using
    Shifted Windows" <https://arxiv.org/abs/2103.14030>`_ paper.
    Args:
        patch_size (List[int]): Patch size.
        embed_dim (int): Patch embedding dimension.
        depths (List(int)): Depth of each Swin Transformer layer.
        num_heads (List(int)): Number of attention heads in different layers.
        window_size (List[int]): Window size.
        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
        dropout (float): Dropout rate. Default: 0.0.
        attention_dropout (float): Attention dropout rate. Default: 0.0.
        stochastic_depth_prob (float): Stochastic depth rate. Default: 0.1.
        num_classes (int): Number of classes for classification head. Default: 1000.
        block (nn.Module, optional): SwinTransformer Block. Default: None.
        norm_layer (nn.Module, optional): Normalization layer. Default: None.
        downsample_layer (nn.Module): Downsample layer (patch merging). Default: PatchMerging.
    r   r`   g?i  N
patch_size	embed_dimdepthsrd   r5   r   rg   rf   r   num_classesr@   .blockdownsample_layerc                    s  t    t|  |
| _|d u rt}|d u rttjdd}g }|t	tj
d||d |d f|d |d fdtg d|| t|}d}tt|D ]R}g }|d|  }t|| D ]) |	t| |d  }||||| | fd	d
|D |||||d	 |d7 }q^|tj	|  |t|d k r|||| qNtj	| | _|dt|d   }||| _tg d| _td| _td| _t||
| _|  D ]}t|tjrtjj|jdd |jd urtj|j qd S )Ngh㈵>)epsrm   r   r   )Zkernel_sizeZstride)r   r   rm   r   r   c                    s$   g | ]} d  dkrdn|d  qS )r   r   r0   ).0r   Zi_layerr0   r1   
<listcomp>C  s   $ z,SwinTransformer.__init__.<locals>.<listcomp>)r5   re   r   rg   rf   r   r@   )r   rm   r   r   r   r   ) rF   rG   r   r   r   r   r   rZ   appendr   ZConv2dr
   rs   ranger   r~   featuresrJ   r7   ZAdaptiveAvgPool2davgpoolZFlattenr   rH   headr   r   r   r   r   rD   Zzeros_)rL   r   r   r   rd   r5   r   rg   rf   r   r   r@   r   r   ZlayersZtotal_stage_blocksZstage_block_idZi_stageZstager?   Zsd_probZnum_featuresr   rM   r   r1   rG     sp   
 




zSwinTransformer.__init__c                 C   s@   |  |}| |}| |}| |}| |}| |}|S r   )r   rJ   r7   r   r   r   rR   r0   r0   r1   rS   _  s   





zSwinTransformer.forward)rV   rW   rX   rY   r>   r   r[   r~   r   r   r   r\   rG   rS   r]   r0   r0   rM   r1   r     sL    	
Or   r   r   r   r   weightsprogresskwargsc           
   	   K   sZ   |d urt |dt|jd  td| |||||d|}	|d ur+|	|j|dd |	S )Nr   
categories)r   r   r   rd   r5   r   T)r   Z
check_hashr0   )r   r   metar   Zload_state_dictZget_state_dict)
r   r   r   rd   r5   r   r   r   r   modelr0   r0   r1   _swin_transformeri  s   
r   r   c                   @   N   e Zd Zedeeddejdi eddddd	d
didddddZ	e	Z
dS )r   z7https://download.pytorch.org/models/swin_t-704ceda3.pth      Z	crop_sizeZresize_sizeinterpolationibr   r   Uhttps://github.com/pytorch/vision/tree/main/references/classification#swintransformerImageNet-1KguV^T@glW@zacc@1zacc@5gX9@g\([@YThese weights reproduce closely the results of the paper using a similar training recipe.Z
num_paramsZmin_sizeZrecipeZ_metricsZ_ops
_file_sizeZ_docsurlZ
transformsr   NrV   rW   rX   r   r   r   r   ZBICUBIC_COMMON_METAIMAGENET1K_V1DEFAULTr0   r0   r0   r1   r     .    
r   c                   @   r   )r   z7https://download.pytorch.org/models/swin_s-5e29d889.pthr      r   irr   r   r   gCT@gףp=
X@r   gZd{!@gx&g@r   r   r   Nr   r0   r0   r0   r1   r     r   r   c                   @   r   )r   z7https://download.pytorch.org/models/swin_b-68c6b09e.pthr      r   i<;r   r   r   gh|?T@g)\(X@r   g&1.@gt@r   r   r   Nr   r0   r0   r0   r1   r     r   r   c                   @   r   )r   z:https://download.pytorch.org/models/swin_v2_t-b137f0e2.pth     r   iRr   r   Xhttps://github.com/pytorch/vision/tree/main/references/classification#swintransformer-v2r   gS㥛T@g rX@r   g(\@gMb([@r   r   r   Nr   r0   r0   r0   r1   r     r   r   c                   @   r   )r   z:https://download.pytorch.org/models/swin_v2_s-637d8ceb.pthr   r   r   ir   r   r   g!rhT@gNbX94X@r   gd;O'@gg@r   r   r   Nr   r0   r0   r0   r1   r     r   r   c                   @   r   )r   z:https://download.pytorch.org/models/swin_v2_b-781e5279.pthr   i  r   i=r   r   r   gI+U@gK7X@r   g33333S4@gˡEu@r   r   r   Nr   r0   r0   r0   r1   r   	  r   r   Z
pretrained)r   )r   r   c                 K   :   t | } td	ddgdg dg dddgd| |d|S )
a  
    Constructs a swin_tiny architecture from
    `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_T_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_T_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_T_Weights
        :members:
    rB   `   r   r      r   rm   r            皙?r   r   r   rd   r5   r   r   r   Nr0   )r   verifyr   r   r   r   r0   r0   r1   r   "     
	r   c                 K   r   )
a  
    Constructs a swin_small architecture from
    `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_S_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_S_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_S_Weights
        :members:
    rB   r   r   r      r   r   r   333333?r   Nr0   )r   r   r   r   r0   r0   r1   r   H  r   r   c                 K   r   )
a  
    Constructs a swin_base architecture from
    `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_B_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_B_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_B_Weights
        :members:
    rB      r   rB   r   r       r         ?r   Nr0   )r   r   r   r   r0   r0   r1   r   n  r   r   c                 K   >   t | } td	ddgdg dg dddgd| |ttd
|S )
a  
    Constructs a swin_v2_tiny architecture from
    `Swin Transformer V2: Scaling Up Capacity and Resolution <https://arxiv.org/abs/2111.09883>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_V2_T_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_V2_T_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_V2_T_Weights
        :members:
    rB   r   r   r   r   r   
r   r   r   rd   r5   r   r   r   r   r   Nr0   )r   r   r   r   r_   r   r0   r0   r1   r         
r    c                 K   r  )
a  
    Constructs a swin_v2_small architecture from
    `Swin Transformer V2: Scaling Up Capacity and Resolution <https://arxiv.org/abs/2111.09883>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_V2_S_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_V2_S_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_V2_S_Weights
        :members:
    rB   r   r   r   r   r   r  Nr0   )r   r   r   r   r_   r   r0   r0   r1   r!     r  r!   c                 K   r  )
a  
    Constructs a swin_v2_base architecture from
    `Swin Transformer V2: Scaling Up Capacity and Resolution <https://arxiv.org/abs/2111.09883>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_V2_B_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_V2_B_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_V2_B_Weights
        :members:
    rB   r  r   r  r   r  r  Nr0   )r   r   r   r   r_   r   r0   r0   r1   r"     r  r"   )r`   r`   NNNT)Arz   	functoolsr   typingr   r   r   r*   Ztorch.nn.functionalr   Z
functionalr(   r   Zops.miscr	   r
   Zops.stochastic_depthr   Ztransforms._presetsr   r   utilsr   Z_apir   r   r   _metar   Z_utilsr   r   __all__r2   Zfxwrapr   r[   r<   r\   r>   r_   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r0   r0   r0   r1   <module>   s    

#	

sQV92m	

*$*$*$*&*&.