a
    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 ejejdddZ!ej"#d ejeje$e% ejdddZ&ej"#d G dd de	j'Z(G dd de	j'Z)dHeeeee$e% e%e$e% e*e*ee ee eej e+edddZ,ej"#d G dd de	j'Z-G d d! d!e-Z.G d"d# d#e	j'Z/G d$d% d%e/Z0G d&d' d'e	j'Z1e$e% e%e$e% e$e% e$e% e*ee e+ee1d(
d)d*Z2d+eiZ3G d,d- d-eZ4G d.d/ d/eZ5G d0d1 d1eZ6G d2d3 d3eZ7G d4d5 d5eZ8G d6d7 d7eZ9e ed8e4j:fd9ddd:ee4 e+ee1d;d<d=Z;e ed8e5j:fd9ddd:ee5 e+ee1d;d>d?Z<e ed8e6j:fd9ddd:ee6 e+ee1d;d@dAZ=e ed8e7j:fd9ddd:ee7 e+ee1d;dBdCZ>e ed8e8j:fd9ddd:ee8 e+ee1d;dDdEZ?e ed8e9j:fd9ddd:ee9 e+ee1d;dFdGZ@dS )I    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 r1   Q/var/www/auris/lib/python3.9/site-packages/torchvision/models/swin_transformer.py_patch_merging_pad#   s         r3   )relative_position_bias_tablerelative_position_indexwindow_sizer%   c                 C   sB   |d |d  }| | }| ||d}|ddd d}|S )Nr   r   r'   r   )viewpermute
contiguous	unsqueeze)r4   r5   r6   Nrelative_position_biasr1   r1   r2   _get_relative_position_bias1   s
    r=   c                       sF   e Zd ZdZejfeedejf d fddZ	e
d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_layerc                    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@   rA   	__class__r1   r2   rH   E   s
    
zPatchMerging.__init__r$   c                 C   s    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]
        )r3   rK   rJ   rM   r$   r1   r1   r2   forwardL   s    

zPatchMerging.forward__name__
__module____qualname____doc__r   	LayerNormintr   ModulerH   r   rS   __classcell__r1   r1   rN   r2   r>   >   s   $r>   c                       sF   e Zd ZdZejfeedejf d fddZ	e
dddZ  ZS )	PatchMergingV2zPatch Merging Layer for Swin Transformer V2.
    Args:
        dim (int): Number of input channels.
        norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm.
    .r?   c                    sD   t    t|  || _tjd| d| dd| _|d| | _d S rB   rF   rL   rN   r1   r2   rH   `   s
    
zPatchMergingV2.__init__rP   c                 C   s    t |}| |}| |}|S rQ   )r3   rJ   rK   rR   r1   r1   r2   rS   g   s    

zPatchMergingV2.forwardrT   r1   r1   rN   r2   r]   Y   s   $r]           T)input
qkv_weightproj_weightr<   r6   	num_heads
shift_sizeattention_dropoutdropoutqkv_bias	proj_biaslogit_scaletrainingr%   c           $   	   C   s  | j \}}}}|d ||d   |d  }|d ||d   |d  }t| ddd|d|f}|j \}}}}| }|d |krd|d< |d |krd|d< t|dkrtj||d  |d  fdd}||d  ||d   }||||d  |d ||d  |d |}|dddddd	|| |d |d  |}|d	urv|	d	urv|	
 }	|	 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 ]2}#|!||"d |"d |#d |#d f< |!d7 }!qҐq|||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rt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   rC      Nr'   )r@   g      Y@)maxg      g      Yr^   )pri   )r(   r)   r*   copysumr+   Zrollr7   r8   Zreshapeclonenumelzero_Zlinearsize	normalizeZ	transposeclampmathlogexpmatmulZ	new_zerosr:   Zmasked_fillfloatZsoftmaxre   r9   )$r_   r`   ra   r<   r6   rb   rc   rd   re   rf   rg   rh   ri   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wr1   r1   r2   shifted_window_attentiont   sp    # ,.0
$
..$($$((, $r   c                
       sn   e Zd ZdZdeee ee eeeeed fddZdd Z	d	d
 Z
ejdddZeedddZ  ZS )ShiftedWindowAttentionz/
    See :func:`shifted_window_attention`.
    Tr^   r@   r6   rc   rb   rf   rg   rd   re   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 2rk   rD   )rG   rH   len
ValueErrorr6   rc   rb   rd   re   r   rI   r   proj#define_relative_position_bias_tabledefine_relative_position_index)	rM   r@   r6   rc   rb   rf   rg   rd   re   rN   r1   r2   rH      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+   zerosr6   rb   r4   inittrunc_normal_rM   r1   r1   r2   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'   r5   )
r+   aranger6   stackmeshgridflattenr8   r9   rq   register_buffer)rM   Zcoords_hZcoords_wZcoordsZcoords_flattenZrelative_coordsr5   r1   r1   r2   r     s    ,((,z5ShiftedWindowAttention.define_relative_position_indexr%   c                 C   s   t | j| j| jS N)r=   r4   r5   r6   r   r1   r1   r2   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]
        )rc   rd   re   rf   rg   ri   )r   r   r   weightr   r6   rb   rc   rd   re   rE   ri   rM   r$   r<   r1   r1   r2   rS   #  s    zShiftedWindowAttention.forward)TTr^   r^   )rU   rV   rW   rX   rZ   listboolr|   rH   r   r   r+   r   r   rS   r\   r1   r1   rN   r2   r      s&   
    r   c                
       sd   e Zd ZdZdeee ee eeeeed fddZdd Z	e
jd	d
dZedddZ  ZS )ShiftedWindowAttentionV2z2
    See :func:`shifted_window_attention_v2`.
    Tr^   r   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| _|r| jj d
 }	| jj|	d|	  j  d S )N)rf   rg   rd   re   
   r   r   i   TrD   )inplaceFrk   )rG   rH   r   r   r+   ry   Zonesrh   
SequentialrI   ZReLUcpb_mlpr   rE   rs   datart   )
rM   r@   r6   rc   rb   rf   rg   rd   re   r   rN   r1   r2   rH   @  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   r6   float32r   r   r8   r9   r:   signlog2absr   )rM   Zrelative_coords_hZrelative_coords_wr   r1   r1   r2   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   r7   rb   r5   r6   r+   Zsigmoid)rM   r<   r1   r1   r2   r   o  s    z3ShiftedWindowAttentionV2.get_relative_position_biasrP   c                 C   sH   |   }t|| jj| jj|| j| j| j| j| j	| jj
| jj
| j| jdS )r   )rc   rd   re   rf   rg   rh   ri   )r   r   r   r   r   r6   rb   rc   rd   re   rE   rh   ri   r   r1   r1   r2   rS   x  s     z ShiftedWindowAttentionV2.forward)TTr^   r^   )rU   rV   rW   rX   rZ   r   r   r|   rH   r   r+   r   r   rS   r\   r1   r1   rN   r2   r   ;  s$   
    	r   c                       sr   e Zd ZdZddddejefeeee ee e	e	e	e	e
dejf e
dejf d
 fddZed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@   rb   r6   rc   	mlp_ratiore   rd   stochastic_depth_probrA   
attn_layerc                    s   t    t|  |	|| _|
||||||d| _t|d| _|	|| _t|t	|| |gt
jd |d| _| j D ]:}t|t
jrtt
j|j |jd urtt
jj|jdd qtd S )N)rd   re   row)Zactivation_layerr   re   gư>r   )rG   rH   r   norm1r   r   stochastic_depthnorm2r	   rZ   r   ZGELUmlpmodules
isinstancerI   r   Zxavier_uniform_r   rE   Znormal_)rM   r@   rb   r6   rc   r   re   rd   r   rA   r   mrN   r1   r2   rH     s&    


"
zSwinTransformerBlock.__init__rP   c                 C   s8   ||  | | | }||  | | | }|S r   )r   r   r   r   r   rR   r1   r1   r2   rS     s    zSwinTransformerBlock.forward)rU   rV   rW   rX   r   rY   r   rZ   r   r|   r   r[   rH   r   rS   r\   r1   r1   rN   r2   r     s(   #r   c                       sr   e Zd ZdZddddejefeeee ee e	e	e	e	e
dejf e
dejf d
 fddZedd	d
Z  ZS )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   c                    s$   t  j|||||||||	|
d
 d S )N)r   re   rd   r   rA   r   )rG   rH   )rM   r@   rb   r6   rc   r   re   rd   r   rA   r   rN   r1   r2   rH     s    zSwinTransformerBlockV2.__init__rP   c                 C   s8   ||  | | | }||  | | | }|S r   )r   r   r   r   r   rR   r1   r1   r2   rS     s    zSwinTransformerBlockV2.forward)rU   rV   rW   rX   r   rY   r   rZ   r   r|   r   r[   rH   r   rS   r\   r1   r1   rN   r2   r     s(   r   c                       s   e Zd ZdZdddddddefee eee ee ee eeeeeee	de
jf  ee	de
jf  e	de
jf d 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depthsrb   r6   r   re   rd   r   num_classesrA   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 ]}g }|d|  }t|| D ]R |	t| |d  }||||| | fd	d
|D |||||d	 |d7 }q|tj	|  |t|d k r|||| qt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㈵>)Zepsrk   r   r   )Zkernel_sizeZstride)r   r   rk   r   r   c                    s$   g | ]} d  dkrdn|d  qS )r   r   r1   ).0r   Zi_layerr1   r2   
<listcomp>C      z,SwinTransformer.__init__.<locals>.<listcomp>)r6   rc   r   re   rd   r   rA   )r   rk   r   r   r   r   ) rG   rH   r   r   r   r   r   rY   appendr   ZConv2dr
   rq   ranger   r|   featuresrK   r8   ZAdaptiveAvgPool2davgpoolZFlattenr   rI   headr   r   r   r   r   rE   Zzeros_)rM   r   r   r   rb   r6   r   re   rd   r   r   rA   r   r   ZlayersZtotal_stage_blocksZstage_block_idZi_stageZstager@   Zsd_probZnum_featuresr   rN   r   r2   rH     sj    
 



zSwinTransformer.__init__c                 C   s@   |  |}| |}| |}| |}| |}| |}|S r   )r   rK   r8   r   r   r   rR   r1   r1   r2   rS   _  s    





zSwinTransformer.forward)rU   rV   rW   rX   r>   r   rZ   r|   r   r   r   r[   rH   rS   r\   r1   r1   rN   r2   r     s2   Or   )
r   r   r   rb   r6   r   weightsprogresskwargsr%   c           
   	   K   sZ   |d urt |dt|jd  tf | |||||d|}	|d urV|	|j|dd |	S )Nr   
categories)r   r   r   rb   r6   r   T)r   Z
check_hash)r   r   metar   Zload_state_dictZget_state_dict)
r   r   r   rb   r6   r   r   r   r   modelr1   r1   r2   _swin_transformeri  s    
r   r   c                   @   sN   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rU   rV   rW   r   r   r   r   ZBICUBIC_COMMON_METAIMAGENET1K_V1DEFAULTr1   r1   r1   r2   r     s,   
r   c                   @   sN   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_s-5e29d889.pthr      r   irr   r   r   gCT@gףp=
X@r   gZd{!@gx&g@r   r   r   Nr   r1   r1   r1   r2   r     s,   
r   c                   @   sN   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_b-68c6b09e.pthr      r   i<;r   r   r   gh|?T@g)\(X@r   g&1.@gt@r   r   r   Nr   r1   r1   r1   r2   r     s,   
r   c                   @   sN   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   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   r1   r1   r1   r2   r     s,   
r   c                   @   sN   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   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   r1   r1   r1   r2   r     s,   
r   c                   @   sN   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   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   r1   r1   r1   r2   r   	  s,   
r   Z
pretrained)r   )r   r   )r   r   r   r%   c                 K   s:   t | } tf 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:
    rC   `   r   r      r   rk   r            皙?r   r   r   rb   r6   r   r   r   )r   verifyr   r   r   r   r1   r1   r2   r   "  s    
	r   c                 K   s:   t | } tf ddgdg dg dddgd| |d|S )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:
    rC   r   r   r      r   r   r   333333?r   )r   r   r   r   r1   r1   r2   r   H  s    
	r   c                 K   s:   t | } tf ddgdg dg dddgd| |d|S )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:
    rC      r   rC   r   r       r         ?r   )r   r   r   r   r1   r1   r2   r   n  s    
	r   c                 K   s>   t | } tf 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:
    rC   r   r   r   r   r   
r   r   r   rb   r6   r   r   r   r   r   )r   r   r   r   r]   r   r1   r1   r2   r      s    
r    c                 K   s>   t | } tf ddgdg dg dddgd| |ttd
|S )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:
    rC   r   r   r   r   r   r  )r   r   r   r   r]   r   r1   r1   r2   r!     s    
r!   c                 K   s>   t | } tf ddgdg dg dddgd| |ttd
|S )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:
    rC   r   r   r   r   r   r  )r   r   r   r   r]   r   r1   r1   r2   r"     s    
r"   )r^   r^   NNNT)Arx   	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   Z_metar   _utilsr   r   __all__r3   Zfxwrapr   rZ   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"   r1   r1   r1   r2   <module>   s   
#      sQV92n$$$$$$$&$&